From e22b5f03d24b9f066e4b27cb78a25c8d2c75414d Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 8 Jul 2023 21:24:37 -0400 Subject: [PATCH 01/78] [src] Fix logtime string race contidion --- src/logger.cc | 23 ++++++++++------------- src/logger.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/logger.cc b/src/logger.cc index 27bd67af..2e981d3d 100644 --- a/src/logger.cc +++ b/src/logger.cc @@ -73,21 +73,19 @@ void Logger::RecordLogs(LogLevel log_type, std::string&& log_info) { RecordLogs(Log_level_info_prefix[log_type] + log_info); } -void Logger::UpdateLoggerTime() { +std::string Logger::UpdateLoggerTime() { time_t tmp_time; ::time(&tmp_time); + std::lock_guard lock(time_mutex_); if (tmp_time > time_now_sec_) { - std::lock_guard lock(time_mutex_); - ::time(&tmp_time); - if (tmp_time > time_now_sec_) { - time_now_sec_ = tmp_time; - // In consideration of time zone - struct tm* tmp_tm = ::localtime(&tmp_time); - std::string tmp_time_now_str(::asctime(tmp_tm)); - tmp_time_now_str.resize(tmp_time_now_str.size() - 1); - time_now_str_ = "[ " + tmp_time_now_str + " ]"; - } + time_now_sec_ = tmp_time; + // In consideration of time zone + struct tm* tmp_tm = ::localtime(&tmp_time); + std::string tmp_time_now_str(::asctime(tmp_tm)); + tmp_time_now_str.resize(tmp_time_now_str.size() - 1); + time_now_str_ = "[ " + tmp_time_now_str + " ]"; } + return time_now_str_; } void Logger::WriteDownLogs() { @@ -151,9 +149,8 @@ void Logger::RecordLogs(std::string&& log_info) { } // Update the index which can be written next time and get the previous value const int64_t write_index = write_index_.fetch_add(1); - UpdateLoggerTime(); // Splice this log record - std::string time_now_str{time_now_str_}; + std::string time_now_str{UpdateLoggerTime()}; std::string log_data(time_now_str.size() + log_info.size() + 2, ' '); ::memcpy(reinterpret_cast(const_cast(log_data.c_str())), time_now_str.c_str(), time_now_str.size()); diff --git a/src/logger.h b/src/logger.h index 5c37fc1a..6e7ec085 100644 --- a/src/logger.h +++ b/src/logger.h @@ -144,7 +144,7 @@ class Logger : NonCopyableMovable { ~Logger(); private: - void UpdateLoggerTime(); + std::string UpdateLoggerTime(); // Called to write down logs void WriteDownLogs(); From 04c82ad7e5f649c90bf0060a70cebdd3836240d0 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 8 Jul 2023 23:58:42 -0400 Subject: [PATCH 02/78] [src] Fix race condition bug for UNIX Poller --- src/poller.cc | 25 +++++++++++++++++++------ src/poller.h | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/poller.cc b/src/poller.cc index aaa1a445..b31efe19 100644 --- a/src/poller.cc +++ b/src/poller.cc @@ -149,6 +149,7 @@ bool Poller::IsPollFdEffective() const { #include #include +#include #include #include "eventer.h" @@ -164,12 +165,24 @@ Poller::Poller() = default; Poller::~Poller() = default; TimePoint Poller::Poll(int timeout, EventerList* active_eventers) { - int event_amount = ::poll(&(*poll_events_.begin()), - static_cast(poll_events_.size()), timeout); + int event_amount = 0; + PollEventList poll_events; + { + LockGuard lock_guard(event_lock_); + nfds_t poll_events_size = static_cast(poll_events_.size()); + poll_events.resize(poll_events_.size()); + for (size_t i = 0; i < static_cast(poll_events_size); ++i) { + poll_events[i].fd = poll_events_[i].fd; + poll_events[i].events = poll_events_[i].events; + poll_events[i].revents = poll_events_[i].revents; + } + } + event_amount = ::poll(&(*poll_events.begin()), + static_cast(poll_events.size()), timeout); int saved_errno = errno; TimePoint return_time; if (event_amount > 0) { - GetActiveEventer(event_amount, active_eventers); + GetActiveEventer(event_amount, poll_events, active_eventers); } else if (0 == event_amount) { LOG_DEBUG("In thread(%lu), there is nothing happened.", ::pthread_self()); } else { @@ -231,11 +244,11 @@ void Poller::RemoveEventer(Eventer* eventer) { poll_events_.pop_back(); } -void Poller::GetActiveEventer(int event_amount, +void Poller::GetActiveEventer(int event_amount, const PollEventList active_events, EventerList* active_eventers) const { LockGuard lock_guard(event_lock_); - for (auto itr = poll_events_.cbegin(); - itr != poll_events_.cend() && event_amount > 0; ++itr) { + for (auto itr = active_events.cbegin(); + itr != active_events.cend() && event_amount > 0; ++itr) { if (itr->revents > 0) { --event_amount; auto evt = eventers_.find(itr->fd); diff --git a/src/poller.h b/src/poller.h index 17544414..09efbf76 100644 --- a/src/poller.h +++ b/src/poller.h @@ -102,7 +102,7 @@ class Poller : NonCopyableMovable { typedef std::map EventerMap; typedef std::vector PollEventList; - void GetActiveEventer(int event_amount, EventerList* active_eventers) const; + void GetActiveEventer(int event_amount, const PollEventList active_events, EventerList* active_eventers) const; // Map for all file descriptors mapping to their corresponding "Eventer"s EventerMap eventers_; From 9249914927e5af987009f5b1f7218a65bce1ca91 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sun, 9 Jul 2023 00:00:46 -0400 Subject: [PATCH 03/78] [src] Adjust format --- src/poller.cc | 5 +++-- src/poller.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/poller.cc b/src/poller.cc index b31efe19..f07e1d4b 100644 --- a/src/poller.cc +++ b/src/poller.cc @@ -125,7 +125,7 @@ void Poller::RemoveEventer(Eventer* eventer) { void Poller::GetActiveEventer(int event_amount, EventerList* active_eventers) const { - for (int i = 0; i < event_amount; ++i) { + for (size_t i = 0; i < event_amount; ++i) { auto eventer = static_cast(poll_events_[i].data.ptr); eventer->ReceiveEvents(poll_events_[i].events); active_eventers->emplace_back(eventer); @@ -244,7 +244,8 @@ void Poller::RemoveEventer(Eventer* eventer) { poll_events_.pop_back(); } -void Poller::GetActiveEventer(int event_amount, const PollEventList active_events, +void Poller::GetActiveEventer(int event_amount, + const PollEventList active_events, EventerList* active_eventers) const { LockGuard lock_guard(event_lock_); for (auto itr = active_events.cbegin(); diff --git a/src/poller.h b/src/poller.h index 09efbf76..6faf85c7 100644 --- a/src/poller.h +++ b/src/poller.h @@ -102,7 +102,8 @@ class Poller : NonCopyableMovable { typedef std::map EventerMap; typedef std::vector PollEventList; - void GetActiveEventer(int event_amount, const PollEventList active_events, EventerList* active_eventers) const; + void GetActiveEventer(int event_amount, const PollEventList active_events, + EventerList* active_eventers) const; // Map for all file descriptors mapping to their corresponding "Eventer"s EventerMap eventers_; From 6bb706398ecbf6d8abfa4af85b682e60898eb28f Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sun, 9 Jul 2023 00:02:27 -0400 Subject: [PATCH 04/78] [src] Modify argv passing method for UNIX Poller --- src/poller.cc | 2 +- src/poller.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/poller.cc b/src/poller.cc index f07e1d4b..429e9055 100644 --- a/src/poller.cc +++ b/src/poller.cc @@ -245,7 +245,7 @@ void Poller::RemoveEventer(Eventer* eventer) { } void Poller::GetActiveEventer(int event_amount, - const PollEventList active_events, + const PollEventList& active_events, EventerList* active_eventers) const { LockGuard lock_guard(event_lock_); for (auto itr = active_events.cbegin(); diff --git a/src/poller.h b/src/poller.h index 6faf85c7..e16c4269 100644 --- a/src/poller.h +++ b/src/poller.h @@ -102,7 +102,7 @@ class Poller : NonCopyableMovable { typedef std::map EventerMap; typedef std::vector PollEventList; - void GetActiveEventer(int event_amount, const PollEventList active_events, + void GetActiveEventer(int event_amount, const PollEventList& active_events, EventerList* active_eventers) const; // Map for all file descriptors mapping to their corresponding "Eventer"s From bae8c24f0cab8362f9aa06c707c5f0ff816dbca7 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 11 Jul 2023 04:44:59 -0400 Subject: [PATCH 05/78] [src] Modify all wrong spells --- src/acceptor.cc | 40 ++++++++++++++++++++-------------------- src/acceptor.h | 6 +++--- src/connector.cc | 10 +++++----- src/connector.h | 6 +++--- src/event_manager.h | 8 ++++---- src/io_buffer.cc | 2 +- src/memory_pool.h | 34 +++++++++++++++++----------------- src/reactor_manager.h | 4 ++-- src/server.h | 2 +- src/spin_lock.h | 2 +- src/thread_pool.cc | 4 ++-- src/thread_pool.h | 5 +++-- src/timer.cc | 2 +- 13 files changed, 63 insertions(+), 62 deletions(-) diff --git a/src/acceptor.cc b/src/acceptor.cc index 315becf8..a5350d14 100644 --- a/src/acceptor.cc +++ b/src/acceptor.cc @@ -1,7 +1,7 @@ /** * @file acceptor.cc * @author Sigma711 (sigma711 at foxmail dot com) - * @brief Implementation of class "Acceptor" which is the accetor of new TCP + * @brief Implementation of class "Acceptor" which is the acceptor of new TCP * connection requests from clients and create the connections. * @date 2021-12-03 * @@ -32,61 +32,61 @@ enum { Acceptor::Acceptor(Poller* poller, const NetAddress& listen_address, bool should_reuse_port) - : accept_soketer_(::socket(listen_address.GetFamily(), - SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, - IPPROTO_TCP)), - accept_eventer_(poller, accept_soketer_.Fd()), + : accept_socketer_(::socket(listen_address.GetFamily(), + SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, + IPPROTO_TCP)), + accept_eventer_(poller, accept_socketer_.Fd()), is_listening_(false), idle_fd_(::open("/dev/null", O_RDONLY | O_CLOEXEC)) { - if (accept_soketer_.Fd() < 0) { + if (accept_socketer_.Fd() < 0) { LOG_ERROR("Fail to initialize for acceptor!!!"); ::exit(-1); } #ifndef __linux__ - int flags = ::fcntl(accept_soketer_.Fd(), F_GETFL, 0); + int flags = ::fcntl(accept_socketer_.Fd(), F_GETFL, 0); flags |= O_NONBLOCK; - ::fcntl(accept_soketer_.Fd(), F_SETFL, flags); - flags = ::fcntl(accept_soketer_.Fd(), F_GETFD, 0); + ::fcntl(accept_socketer_.Fd(), F_SETFL, flags); + flags = ::fcntl(accept_socketer_.Fd(), F_GETFD, 0); flags |= FD_CLOEXEC; - ::fcntl(accept_soketer_.Fd(), F_SETFD, flags); + ::fcntl(accept_socketer_.Fd(), F_SETFD, flags); #endif - accept_soketer_.SetReuseAddress(true); - accept_soketer_.SetReusePort(should_reuse_port); - accept_soketer_.BindAddress(listen_address); + accept_socketer_.SetReuseAddress(true); + accept_socketer_.SetReusePort(should_reuse_port); + accept_socketer_.BindAddress(listen_address); accept_eventer_.RegisterReadCallback([this](const TimePoint& time_point) { this->DoReading(); }); // Register the accepting action as an reading event handler } Acceptor::~Acceptor() { - LOG_DEBUG("Acceptor with fd(%d) is closing.", accept_soketer_.Fd()); + LOG_DEBUG("Acceptor with fd(%d) is closing.", accept_socketer_.Fd()); is_listening_ = false; ::close(idle_fd_); } void Acceptor::Listen() { is_listening_ = true; - accept_soketer_.Listen(); + accept_socketer_.Listen(); accept_eventer_.EnableReadEvents(); - LOG_DEBUG("Acceptor with fd(%d) is listening.", accept_soketer_.Fd()); + LOG_DEBUG("Acceptor with fd(%d) is listening.", accept_socketer_.Fd()); } void Acceptor::DoReading() { NetAddress peer_address; - int conn_fd = accept_soketer_.Accept(&peer_address); + int conn_fd = accept_socketer_.Accept(&peer_address); if (conn_fd >= 0 && conn_fd <= kMaxEventAmount) { if (NewConnectionCallback_) { NewConnectionCallback_(conn_fd, peer_address); } else { - LOG_ERROR("Acceptor with fd(%d) is closing!!!", accept_soketer_.Fd()); + LOG_ERROR("Acceptor with fd(%d) is closing!!!", accept_socketer_.Fd()); ::close(conn_fd); } } else { LOG_ERROR("Acceptor with Fd(%d) failed to accept a new TCP connection!!!", - accept_soketer_.Fd()); + accept_socketer_.Fd()); if (errno == EMFILE) { // If it fails to connect, clear the waiting list of // listening ::close(idle_fd_); - idle_fd_ = ::accept(accept_soketer_.Fd(), NULL, NULL); + idle_fd_ = ::accept(accept_socketer_.Fd(), NULL, NULL); ::close(idle_fd_); idle_fd_ = ::open("/dev/null", O_RDONLY | O_CLOEXEC); } diff --git a/src/acceptor.h b/src/acceptor.h index 8f2149f6..d197eae2 100644 --- a/src/acceptor.h +++ b/src/acceptor.h @@ -1,7 +1,7 @@ /** * @file acceptor.h * @author Sigma711 (sigma711 at foxmail dot com) - * @brief Declaration of class "Acceptor" which is the accetor of new TCP + * @brief Declaration of class "Acceptor" which is the acceptor of new TCP * connection requests from clients and create the connections. * @date 2021-12-03 * @@ -39,7 +39,7 @@ class Acceptor : NonCopyableMovable { ~Acceptor(); // Get the file descriptor of this accepting socket - int Fd() const { return accept_soketer_.Fd(); } + int Fd() const { return accept_socketer_.Fd(); } // Listen to the port of the IP address void Listen(); @@ -56,7 +56,7 @@ class Acceptor : NonCopyableMovable { private: // Socketer which is about configurations of the socket - Socketer accept_soketer_; + Socketer accept_socketer_; // Eventer which is about event's setting Eventer accept_eventer_; diff --git a/src/connector.cc b/src/connector.cc index ac4771cb..b191a35b 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -65,7 +65,7 @@ Connector::Connector(EventManager* event_manager, server_address_(server_address), state_(kDisconnected), can_connect_(false), - retry_dalay_microseconds_(static_cast(kInitRetryDelayMicroseconds)) { + retry_delay_microseconds_(static_cast(kInitRetryDelayMicroseconds)) { } void Connector::Start() { @@ -75,7 +75,7 @@ void Connector::Start() { void Connector::Restart() { SetState(kDisconnected); - retry_dalay_microseconds_ = static_cast(kInitRetryDelayMicroseconds); + retry_delay_microseconds_ = static_cast(kInitRetryDelayMicroseconds); Start(); } void Connector::Stop() { @@ -147,10 +147,10 @@ void Connector::DoRetrying(int conn_fd) { SetState(kDisconnected); if (can_connect_) { LOG_DEBUG("Connector fd(%d) is retrying to connect.", conn_fd); - event_manager_->RunAfter(retry_dalay_microseconds_, + event_manager_->RunAfter(retry_delay_microseconds_, [this]() { this->Start(); }); - retry_dalay_microseconds_ = - std::min(retry_dalay_microseconds_ * 2, + retry_delay_microseconds_ = + std::min(retry_delay_microseconds_ * 2, static_cast(kMaxRetryDelayMicroseconds)); } else { LOG_DEBUG("Connector fd(%d) is not retrying to connect.", conn_fd); diff --git a/src/connector.h b/src/connector.h index 8ea12285..0cf08044 100644 --- a/src/connector.h +++ b/src/connector.h @@ -59,7 +59,7 @@ class Connector : NonCopyableMovable { const NetAddress& GetServerAddress() { return server_address_; } - // Execute when create a new TCP conncetion + // Execute when create a new TCP connection void DoWriting(); // Execute when error happens @@ -70,7 +70,7 @@ class Connector : NonCopyableMovable { enum State { kDisconnected, kConnecting, kConnected }; // After successful connecting, call it to reset because the TCP connection's - // file descriptot is disposable + // file descriptor is disposable int RemoveAndReset(); void SetState(State state) { state_ = state; } @@ -81,7 +81,7 @@ class Connector : NonCopyableMovable { NetAddress server_address_; State state_; bool can_connect_; - int retry_dalay_microseconds_; + int retry_delay_microseconds_; // Be called when a new TCP connection should be created NewConnectionCallback NewConnectionCallback_; diff --git a/src/event_manager.h b/src/event_manager.h index 805a8498..7f307d41 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -103,8 +103,8 @@ class EventManager : NonCopyableMovable { // I/O multiplexing manager Poller poller_; - // All connnections in this loop (also within this thread) (Mapping: file - // descriptor -> conncetion class pointer) + // All connections in this loop (also within this thread) (Mapping: file + // descriptor -> connection class pointer) ConnectionMap connection_map_; std::thread thread_; @@ -120,10 +120,10 @@ class EventManager : NonCopyableMovable { // List for active events returned from the I/O multiplexing waiting each loop Poller::EventerList active_events_; - // Set of file discriptors of connections which should be destroyed + // Set of file descriptors of connections which should be destroyed Fds closed_fds_; - // Spin lock protecting the set of file discriptors of connections which + // Spin lock protecting the set of file descriptors of connections which // should be destroyed mutable MutexLock closed_fds_lock_; diff --git a/src/io_buffer.cc b/src/io_buffer.cc index ca1e4576..0672f190 100644 --- a/src/io_buffer.cc +++ b/src/io_buffer.cc @@ -259,7 +259,7 @@ void IoBuffer::ReserveWritableSpace(size_t len) { } else { // Move forward to-read contents if too much space are reserved in the // front of the buffer, and then the writable space will be enough without - // dilatating + // dilatation ::memcpy(static_cast( const_cast(GetBufferBegin() + kReservedCapacity)), static_cast(GetBufferBegin() + reading_index_), diff --git a/src/memory_pool.h b/src/memory_pool.h index 4fd179c4..2d1d77c0 100644 --- a/src/memory_pool.h +++ b/src/memory_pool.h @@ -1,7 +1,7 @@ /** * @file memory_pool.h * @author Sigma711 (sigma711 at foxmail dot com) - * @brief Declaration and Implementation of struct "MemeryBlockNode" and class + * @brief Declaration and Implementation of struct "MemoryBlockNode" and class * "MemoryPool". * @date 2022-02-15 * @@ -20,13 +20,13 @@ namespace taotu { /** - * @brief "MemeryBlockNode" is the memory block node. + * @brief "MemoryBlockNode" is the memory block node. * */ -struct MemeryBlockNode { +struct MemoryBlockNode { union { char data_; - MemeryBlockNode* next_node_; + MemoryBlockNode* next_node_; }; }; @@ -39,15 +39,15 @@ class MemoryPool : NonCopyableMovable { public: MemoryPool() : free_list_head_(nullptr), list_head_(nullptr), malloc_time_(0) { - if (ObjectSize < sizeof(MemeryBlockNode)) { - object_size_ = sizeof(MemeryBlockNode); + if (ObjectSize < sizeof(MemoryBlockNode)) { + object_size_ = sizeof(MemoryBlockNode); } else { object_size_ = ObjectSize; } } ~MemoryPool() { while (list_head_ != nullptr) { - MemeryBlockNode* tmp_list_head = list_head_; + MemoryBlockNode* tmp_list_head = list_head_; list_head_ = list_head_->next_node_; ::free(reinterpret_cast(tmp_list_head)); } @@ -60,16 +60,16 @@ class MemoryPool : NonCopyableMovable { size_t malloc_size = MemoryPool::kInitialMallocSize + malloc_time_; void* new_malloc_ptr = - ::malloc(malloc_size * object_size_ + sizeof(MemeryBlockNode)); - MemeryBlockNode* new_malloc_node = - reinterpret_cast(new_malloc_ptr); + ::malloc(malloc_size * object_size_ + sizeof(MemoryBlockNode)); + MemoryBlockNode* new_malloc_node = + reinterpret_cast(new_malloc_ptr); new_malloc_node->next_node_ = list_head_; list_head_ = new_malloc_node; new_malloc_ptr = reinterpret_cast( - reinterpret_cast(new_malloc_ptr) + sizeof(MemeryBlockNode)); + reinterpret_cast(new_malloc_ptr) + sizeof(MemoryBlockNode)); for (size_t i = 0; i < malloc_size; ++i) { - MemeryBlockNode* new_node = - reinterpret_cast(new_malloc_ptr); + MemoryBlockNode* new_node = + reinterpret_cast(new_malloc_ptr); new_node->next_node_ = free_list_head_; free_list_head_ = new_node; new_malloc_ptr = reinterpret_cast( @@ -87,8 +87,8 @@ class MemoryPool : NonCopyableMovable { if (nullptr == memory_block_ptr) { return; } - MemeryBlockNode* tmp_node = - reinterpret_cast(memory_block_ptr); + MemoryBlockNode* tmp_node = + reinterpret_cast(memory_block_ptr); tmp_node->next_node_ = free_list_head_; free_list_head_ = tmp_node; } @@ -98,10 +98,10 @@ class MemoryPool : NonCopyableMovable { static const size_t kInitialMallocSize = 40; // Free linked list - MemeryBlockNode* free_list_head_; + MemoryBlockNode* free_list_head_; // Linked list of allocation - MemeryBlockNode* list_head_; + MemoryBlockNode* list_head_; // Time of calling malloc() size_t malloc_time_; diff --git a/src/reactor_manager.h b/src/reactor_manager.h index 5ee66ef2..2dada9b6 100644 --- a/src/reactor_manager.h +++ b/src/reactor_manager.h @@ -34,7 +34,7 @@ class Balancer; /** * @brief "ServerReactorManager" is the engine of the server which manages * almost everything including new TCP connections' creation and concurrent I/O. - * It allows users to difine what to do by some flags and different callback + * It allows users to define what to do by some flags and different callback * functions. * */ @@ -88,7 +88,7 @@ class ServerReactorManager : NonCopyableMovable { // I/O threads EventManagers event_managers_; - // Acceptor for accpecting new connections in the main thread + // Acceptor for accepting new connections in the main thread AcceptorPtr acceptor_; // Load balancer for dispatching new connections into I/O threads diff --git a/src/server.h b/src/server.h index 19ac2eb5..530f7c45 100644 --- a/src/server.h +++ b/src/server.h @@ -57,7 +57,7 @@ class Server : NonCopyableMovable { // Reactor manager (the "engine") ServerReactorManager reactor_manager_; - // Thread pool for caculation + // Thread pool for calculation ThreadPool thread_pool_; std::atomic_bool is_started_; diff --git a/src/spin_lock.h b/src/spin_lock.h index 92f7fb82..992f0467 100644 --- a/src/spin_lock.h +++ b/src/spin_lock.h @@ -20,7 +20,7 @@ namespace taotu { /** * @brief "MutexLock" is a mutex lock which improves the performance of the - * program when locking time is short by using lock-free programing. + * program when locking time is short by using lock-free programming. */ class MutexLock : NonCopyableMovable { public: diff --git a/src/thread_pool.cc b/src/thread_pool.cc index 42a594d4..f14d1f94 100644 --- a/src/thread_pool.cc +++ b/src/thread_pool.cc @@ -1,7 +1,7 @@ /** * @file thread_pool.cc * @author Sigma711 (sigma711 at foxmail dot com) - * @brief Implementation of class "ThreadPool" which is the caculation thread + * @brief Implementation of class "ThreadPool" which is the calculation thread * pool. * @date 2022-02-13 * @@ -40,7 +40,7 @@ ThreadPool::ThreadPool(size_t thread_amount) } size_t que_csm_idx = !(this->que_pdt_idx_); if (this->task_queues_[que_csm_idx] - .empty()) { // If there is no task for cunsuming, make the + .empty()) { // If there is no task for consuming, make the // index of the task queue for producers as the // index of the task queue for consumers std::lock_guard csm_lock(this->que_csm_mutex_); diff --git a/src/thread_pool.h b/src/thread_pool.h index e04bc96a..9d9079a9 100644 --- a/src/thread_pool.h +++ b/src/thread_pool.h @@ -1,7 +1,8 @@ /** * @file thread_pool.h * @author Sigma711 (sigma711 at foxmail dot com) - * @brief Declaration of class "ThreadPool" which is the caculation thread pool. + * @brief Declaration of class "ThreadPool" which is the calculation thread + * pool. * @date 2022-02-13 * * @copyright Copyright (c) 2022 Sigma711 @@ -40,7 +41,7 @@ class ThreadPool : NonCopyableMovable { explicit ThreadPool(size_t thread_amount = 4); ~ThreadPool(); - // Order the thread pool to execute a function and reture a "std::future" + // Order the thread pool to execute a function and return a "std::future" // object for retrieving the return value template auto AddTask(std::function&& task) diff --git a/src/timer.cc b/src/timer.cc index cdcfa579..d561e28c 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -28,7 +28,7 @@ int Timer::GetMinTimeDuration() const { int duration = static_cast(time_points_.begin()->first.GetMillisecond() - TimePoint().GetMillisecond()); return duration > 0 ? duration - : 0; // Could not give a negtive value of the duration + : 0; // Could not give a negative value of the duration } Timer::ExpiredTimeTasks Timer::GetExpiredTimeTasks() { From a76e7ad9761e56de15becada9e3eb208c4f6dca9 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 14 Jul 2023 02:15:50 -0400 Subject: [PATCH 06/78] [src] Modify all wrong spells and solve one FIXME --- .github/pull_request_template.md | 10 ++++++---- .github/workflows/cmake.yml | 2 +- src/acceptor.cc | 2 +- src/connecting.cc | 13 +++++++------ src/connecting.h | 9 +++++---- src/connector.cc | 2 +- src/event_manager.h | 2 +- src/reactor_manager.cc | 5 ++--- src/timer.h | 2 +- 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a8da4d37..3de90703 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,16 +1,18 @@ -### Purpose - +# + +## Purpose + - Purpose. -### Changes +## Changes - No changes. -### Review Instructions +## Review Instructions - No instructions. diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index dec23aff..949f304c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -14,7 +14,7 @@ env: jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # The CMake configure and build commands are platform-agnostic and should work equally well on Windows or Mac. # You can convert this to a matrix build if you need cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix runs-on: ubuntu-latest diff --git a/src/acceptor.cc b/src/acceptor.cc index a5350d14..aa403e3f 100644 --- a/src/acceptor.cc +++ b/src/acceptor.cc @@ -55,7 +55,7 @@ Acceptor::Acceptor(Poller* poller, const NetAddress& listen_address, accept_socketer_.BindAddress(listen_address); accept_eventer_.RegisterReadCallback([this](const TimePoint& time_point) { this->DoReading(); - }); // Register the accepting action as an reading event handler + }); // Register the accepting action as a reading event handler } Acceptor::~Acceptor() { LOG_DEBUG("Acceptor with fd(%d) is closing.", accept_socketer_.Fd()); diff --git a/src/connecting.cc b/src/connecting.cc index 61abc955..b5d582a1 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -204,14 +204,15 @@ void Connecting::ForceClose() { DoClosing(); } } + // FIXME: Make it be effective in the condition that the connection has been // destroyed. -// void Connecting::ForceCloseAfter(int64_t delay_microseconds) { -// if (kDisconnected != state_) { -// event_manager_->RunAfter(delay_microseconds, -// std::bind(&Connecting::ForceClose, this)); -// } -// } +void Connecting::ForceCloseAfter(int64_t delay_microseconds) { + if (kDisconnected != state_) { + event_manager_->RunAfter(delay_microseconds, + [this]() { this->ForceClose(); }); + } +} std::string Connecting::GetConnectionStateInfo(ConnectionState state) { switch (state) { diff --git a/src/connecting.h b/src/connecting.h index 944bf07e..49135a61 100644 --- a/src/connecting.h +++ b/src/connecting.h @@ -126,13 +126,13 @@ class Connecting : NonCopyableMovable { // Be called when this connection establishing void OnEstablishing(); - // Send the message (asynchronously at most of time) + // Send the message (asynchronously at most time) void Send(const void* message, size_t msg_len); - // Send the message (asynchronously at most of time) + // Send the message (asynchronously at most time) void Send(const std::string& message); - // Send the message (asynchronously at most of time) + // Send the message (asynchronously at most time) void Send(IoBuffer* io_buffer); // Shut down the writing end (close half == stop writing indeed) @@ -145,7 +145,8 @@ class Connecting : NonCopyableMovable { // Close this TCP connection directly (at the end of this loop) void ForceClose(); - // FIXME: void ForceCloseAfter(int64_t delay_microseconds); + + void ForceCloseAfter(int64_t delay_microseconds); private: enum ConnectionState { diff --git a/src/connector.cc b/src/connector.cc index b191a35b..be906427 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -128,7 +128,7 @@ void Connector::Connect() { ::close(sock_fd); break; default: - LOG_ERROR("Connector fd(%d) is closing because of an unkown error(%d)!!!", + LOG_ERROR("Connector fd(%d) is closing because of an unknow error(%d)!!!", sock_fd, saved_errno); ::close(sock_fd); break; diff --git a/src/event_manager.h b/src/event_manager.h index 7f307d41..d772676c 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -60,7 +60,7 @@ class EventManager : NonCopyableMovable { Poller* GetPoller() { return &poller_; } - // For the Balancer to pick a EventManager with lowest load + // For the Balancer to pick a EventManager with the lowest load uint32_t GetEventerAmount() const { LockGuard lock_guard(connection_map_mutex_lock_); return connection_map_.size(); diff --git a/src/reactor_manager.cc b/src/reactor_manager.cc index 288ed73e..aa66c269 100644 --- a/src/reactor_manager.cc +++ b/src/reactor_manager.cc @@ -104,9 +104,8 @@ void ServerReactorManager::AcceptNewConnectionCallback( int socket_fd, const NetAddress& peer_address) { auto new_connection = balancer_->PickOneEventManager()->InsertNewConnection( socket_fd, GetLocalAddress(socket_fd), - peer_address); // Pick a "Reactor" with lowest load and - // insert the new - // connection created just now into it + peer_address); // Pick a "Reactor" with the lowest load and insert the + // new connection created just now into it new_connection->RegisterOnConnectionCallback(ConnectionCallback_); new_connection->RegisterOnMessageCallback(MessageCallback_); new_connection->RegisterWriteCallback(WriteCompleteCallback_); diff --git a/src/timer.h b/src/timer.h index 6654a77a..beb60f31 100644 --- a/src/timer.h +++ b/src/timer.h @@ -38,7 +38,7 @@ class Timer : NonCopyableMovable { // Register a time task void AddTimeTask(const TimePoint& time_point, TimeCallback TimeTask); - // Get minium time duration for next epoll waiting + // Get minimum time duration for next epoll waiting int GetMinTimeDuration() const; // Get a set of expired time tasks From e606ceff7ae14b1a6ede03a05601df8e41cbaece Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 14 Jul 2023 02:18:07 -0400 Subject: [PATCH 07/78] [src] Solve one FIXME --- src/connecting.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connecting.cc b/src/connecting.cc index b5d582a1..d8c1edd8 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -208,7 +208,7 @@ void Connecting::ForceClose() { // FIXME: Make it be effective in the condition that the connection has been // destroyed. void Connecting::ForceCloseAfter(int64_t delay_microseconds) { - if (kDisconnected != state_) { + if (kDisconnected != state_.load()) { event_manager_->RunAfter(delay_microseconds, [this]() { this->ForceClose(); }); } From 4157f4c0f119da247dde7fbeb95f225ff2e6a5f2 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 14 Jul 2023 02:20:31 -0400 Subject: [PATCH 08/78] [src] Fix one warning about type conversion --- src/poller.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poller.cc b/src/poller.cc index 429e9055..819150e4 100644 --- a/src/poller.cc +++ b/src/poller.cc @@ -125,7 +125,7 @@ void Poller::RemoveEventer(Eventer* eventer) { void Poller::GetActiveEventer(int event_amount, EventerList* active_eventers) const { - for (size_t i = 0; i < event_amount; ++i) { + for (size_t i = 0; i < static_cast(event_amount); ++i) { auto eventer = static_cast(poll_events_[i].data.ptr); eventer->ReceiveEvents(poll_events_[i].events); active_eventers->emplace_back(eventer); From 6c30a678343f0ccf47e2f5d5c2017c19ad8a1763 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 14 Jul 2023 02:35:04 -0400 Subject: [PATCH 09/78] [src] Modify wrong spells --- src/connector.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/connector.cc b/src/connector.cc index be906427..110d0198 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -128,8 +128,9 @@ void Connector::Connect() { ::close(sock_fd); break; default: - LOG_ERROR("Connector fd(%d) is closing because of an unknow error(%d)!!!", - sock_fd, saved_errno); + LOG_ERROR( + "Connector fd(%d) is closing because of an unknown error(%d)!!!", + sock_fd, saved_errno); ::close(sock_fd); break; } From 5e1f3e222acf1f2c89b28a459ed98832e11d37bc Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 15 Jul 2023 05:23:54 -0400 Subject: [PATCH 10/78] [config] Modify gitignore file --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c2a3bd5c..dc6b6b6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .cache/* .vscode/* -build/* +build*/* .idea/* cmake-build-debug/* cmake-build-release/* From f32402689fae3cc02048569bf830340834c5a749 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 25 Jul 2023 16:40:41 -0400 Subject: [PATCH 11/78] [src] Develop byte array retrieving method for IoBuffer --- src/io_buffer.cc | 12 ++++++++++++ src/io_buffer.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/io_buffer.cc b/src/io_buffer.cc index 0672f190..cd148576 100644 --- a/src/io_buffer.cc +++ b/src/io_buffer.cc @@ -78,6 +78,18 @@ std::string IoBuffer::RetrieveAString(size_t len) { return ret; } +std::vector IoBuffer::RetrieveAByteArray(size_t len) { + if (len > GetReadableBytes()) { + LOG_ERROR("Read too many bytes from the buffer!!!"); + return std::vector{}; + } + std::vector ret(len); + std::copy(GetReadablePosition(), GetReadablePosition() + len, + &(*ret.begin())); + Refresh(len); + return ret; +} + int8_t IoBuffer::RetrieveInt8() { auto result = GetReadableInt8(); Refresh(sizeof(int8_t)); diff --git a/src/io_buffer.h b/src/io_buffer.h index 95badafe..eafe2b12 100644 --- a/src/io_buffer.h +++ b/src/io_buffer.h @@ -99,6 +99,14 @@ class IoBuffer { return RetrieveAString(GetReadableBytes()); } + // Read content as a byte array that has a specific length + std::vector RetrieveAByteArray(size_t len); + + // Read all content as a byte array + std::vector RetrieveAllAsByteArray() { + return RetrieveAByteArray(GetReadableBytes()); + } + // Read content as an 8-bit integer (refresh the indexes) int8_t RetrieveInt8(); From d6638f22651606464cb47440b23458fd79a035a2 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 29 Jul 2023 17:54:17 -0400 Subject: [PATCH 12/78] [src] Develop called once guarantee for staring of EventManager --- src/event_manager.cc | 42 ++++++++++++++++++++++++------------------ src/event_manager.h | 11 +++++++++-- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index 05612032..0d09c52c 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -107,26 +107,12 @@ EventManager::~EventManager() { } void EventManager::Loop() { - thread_ = std::thread([this] { this->Work(); }); + std::call_once(start_once_flag_, [this]() { + thread_ = std::thread([this] { this->Start(); }); + }); } void EventManager::Work() { - should_quit_ = false; - LOG_DEBUG("The event loop in thread(%lu) is starting.", ::pthread_self()); - while (!should_quit_) { - auto return_time = - poller_.Poll(timer_.GetMinTimeDuration(), - &active_events_); // Return time is the time point of the - // end of this polling - DoWithActiveTasks(return_time); - DoExpiredTimeTasks(return_time); - DestroyClosedConnections(); - } - LOG_DEBUG("The event loop in thread(%lu) is stopping.", ::pthread_self()); - LockGuard lock_guard(connection_map_mutex_lock_); - for (auto& [_, connection] : connection_map_) { - delete connection; - } - connection_map_.clear(); + std::call_once(start_once_flag_, [this]() { this->Start(); }); } Connecting* EventManager::InsertNewConnection(int socket_fd, @@ -229,6 +215,26 @@ void EventManager::WakeUp() { void EventManager::Quit() { should_quit_ = true; } +void EventManager::Start() { + should_quit_ = false; + LOG_DEBUG("The event loop in thread(%lu) is starting.", ::pthread_self()); + while (!should_quit_) { + auto return_time = + poller_.Poll(timer_.GetMinTimeDuration(), + &active_events_); // Return time is the time point of + // the end of this polling + DoWithActiveTasks(return_time); + DoExpiredTimeTasks(return_time); + DestroyClosedConnections(); + } + LOG_DEBUG("The event loop in thread(%lu) is stopping.", ::pthread_self()); + LockGuard lock_guard(connection_map_mutex_lock_); + for (auto& [_, connection] : connection_map_) { + delete connection; + } + connection_map_.clear(); +} + void EventManager::DoWithActiveTasks(const TimePoint& return_time) { for (auto active_event : active_events_) { active_event->Work(return_time); diff --git a/src/event_manager.h b/src/event_manager.h index d772676c..688093bb 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -48,9 +49,9 @@ class EventManager : NonCopyableMovable { std::function{}); ~EventManager(); - // Run the loop in a new thread + // Run the loop in a new thread (called once guarantee) void Loop(); - // Run the loop in this thread + // Run the loop in this thread (called once guarantee) void Work(); // Insert a new connection into current I/O thread @@ -93,6 +94,9 @@ class EventManager : NonCopyableMovable { typedef std::unordered_map ConnectionMap; typedef std::unordered_set Fds; + // Only called by Work() or Loop() + void Start(); + // Handle I/O events void DoWithActiveTasks(const TimePoint& return_time); // Do time tasks @@ -127,6 +131,9 @@ class EventManager : NonCopyableMovable { // should be destroyed mutable MutexLock closed_fds_lock_; + // Guaranteed to only start myself once + std::once_flag start_once_flag_; + #ifdef __linux__ // To wake up this I/O thread Eventer wake_up_eventer_; From 7148853bbbd388a7a2d33503af354da835f7125c Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Thu, 10 Aug 2023 15:57:19 -0400 Subject: [PATCH 13/78] [src && example] Refactor the use of EventManager (Make users manage I/O threads by themselves) --- CMakeLists.txt | 2 -- example/chat_room/chat_server.cc | 14 ++++++------- example/chat_room/chat_server.h | 4 +++- example/http_server/http_server.cc | 16 ++++++++------- example/http_server/http_server.h | 4 +++- example/pingpong/pingpong_server.cc | 14 ++++++------- example/pingpong/pingpong_server.h | 4 +++- example/simple_discard/discard.cc | 14 ++++++------- example/simple_discard/discard.h | 4 +++- example/simple_echo/echo.cc | 14 ++++++------- example/simple_echo/echo.h | 4 +++- example/simple_time/time.cc | 14 ++++++------- example/simple_time/time.h | 4 +++- src/event_manager.cc | 10 +-------- src/event_manager.h | 18 ++++++++++------ src/reactor_manager.cc | 32 +++++++++++++++-------------- src/reactor_manager.h | 4 ++-- src/server.cc | 4 ++-- src/server.h | 5 ++++- 19 files changed, 100 insertions(+), 85 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5606e9df..5ad2ea1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,6 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -fsanitize=addres ADD_DEFINITIONS(-Wno-format-security) -STRING(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}") - IF(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug")) MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG = " ${CMAKE_CXX_FLAGS_DEBUG}) ELSEIF(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release")) diff --git a/example/chat_room/chat_server.cc b/example/chat_room/chat_server.cc index 0c002ef8..07d7549f 100644 --- a/example/chat_room/chat_server.cc +++ b/example/chat_room/chat_server.cc @@ -15,9 +15,9 @@ ChatServer::ChatServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : event_manager_(new taotu::EventManager), + : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique( - event_manager_, listen_address, should_reuse_port, io_thread_amount, + &event_managers_, listen_address, should_reuse_port, io_thread_amount, calculation_thread_amount)), codec_([this](taotu::Connecting& connection, const std::string& message, taotu::TimePoint time_point) { @@ -33,14 +33,14 @@ ChatServer::ChatServer(const taotu::NetAddress& listen_address, }); } ChatServer::~ChatServer() { - delete event_manager_; + size_t event_managers_size = event_managers_.size(); + for (size_t i = 0; i < event_managers_size; ++i) { + delete event_managers_[i]; + } taotu::END_LOG(); } -void ChatServer::Start() { - server_->Start(); - event_manager_->Work(); -} +void ChatServer::Start() { server_->Start(); } void ChatServer::OnConnectionCallback(taotu::Connecting& connection) { taotu::LOG_DEBUG( diff --git a/example/chat_room/chat_server.h b/example/chat_room/chat_server.h index 52a2ed11..c1370c7e 100644 --- a/example/chat_room/chat_server.h +++ b/example/chat_room/chat_server.h @@ -20,6 +20,8 @@ class ChatServer : taotu::NonCopyableMovable { public: + typedef std::vector EventManagers; + ChatServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); ~ChatServer(); @@ -37,7 +39,7 @@ class ChatServer : taotu::NonCopyableMovable { void OnCodecMessage(taotu::Connecting& connection, const std::string& message, taotu::TimePoint); - taotu::EventManager* event_manager_; + EventManagers event_managers_; std::unique_ptr server_; Codec codec_; ConnectionSet connections_; diff --git a/example/http_server/http_server.cc b/example/http_server/http_server.cc index 3c3f0ce5..e37f61bc 100644 --- a/example/http_server/http_server.cc +++ b/example/http_server/http_server.cc @@ -10,15 +10,17 @@ #include "http_server.h" +#include + #include "http_parser.h" #include "http_response.h" HttpServer::HttpServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : event_manager_(new taotu::EventManager), + : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique( - event_manager_, listen_address, should_reuse_port, io_thread_amount, + &event_managers_, listen_address, should_reuse_port, io_thread_amount, calculation_thread_amount)) { server_->SetConnectionCallback([this](taotu::Connecting& connection) { this->OnConnectionCallback(connection); @@ -31,14 +33,14 @@ HttpServer::HttpServer(const taotu::NetAddress& listen_address, } HttpServer::~HttpServer() { - delete event_manager_; + size_t event_managers_size = event_managers_.size(); + for (size_t i = 0; i < event_managers_size; ++i) { + delete event_managers_[i]; + } taotu::END_LOG(); } -void HttpServer::Start() { - server_->Start(); - event_manager_->Work(); -} +void HttpServer::Start() { server_->Start(); } void HttpServer::OnConnectionCallback(taotu::Connecting& connection) { if (connection.IsConnected()) { diff --git a/example/http_server/http_server.h b/example/http_server/http_server.h index 18d5fd2d..09642aac 100644 --- a/example/http_server/http_server.h +++ b/example/http_server/http_server.h @@ -20,6 +20,8 @@ class HttpServer : taotu::NonCopyableMovable { public: + typedef std::vector EventManagers; + HttpServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount = 4, size_t calculation_thread_amount = 0); ~HttpServer(); @@ -44,7 +46,7 @@ class HttpServer : taotu::NonCopyableMovable { // Called when a request arriving void OnRequest(taotu::Connecting& connection, const HttpParser& http_parser); - taotu::EventManager* event_manager_; + EventManagers event_managers_; std::unique_ptr server_; std::function HttpCallback_; diff --git a/example/pingpong/pingpong_server.cc b/example/pingpong/pingpong_server.cc index 2909072f..9dc48cc5 100644 --- a/example/pingpong/pingpong_server.cc +++ b/example/pingpong/pingpong_server.cc @@ -13,9 +13,9 @@ PingpongServer::PingpongServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : event_manager_(new taotu::EventManager), + : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique( - event_manager_, listen_address, should_reuse_port, io_thread_amount, + &event_managers_, listen_address, should_reuse_port, io_thread_amount, calculation_thread_amount)) { server_->SetConnectionCallback([this](taotu::Connecting& connection) { this->OnConnectionCallback(connection); @@ -27,14 +27,14 @@ PingpongServer::PingpongServer(const taotu::NetAddress& listen_address, }); } PingpongServer::~PingpongServer() { - delete event_manager_; + size_t event_managers_size = event_managers_.size(); + for (size_t i = 0; i < event_managers_size; ++i) { + delete event_managers_[i]; + } taotu::END_LOG(); } -void PingpongServer::Start() { - server_->Start(); - event_manager_->Work(); -} +void PingpongServer::Start() { server_->Start(); } void PingpongServer::OnConnectionCallback(taotu::Connecting& connection) { if (connection.IsConnected()) { diff --git a/example/pingpong/pingpong_server.h b/example/pingpong/pingpong_server.h index 104e3dde..f2bc0982 100644 --- a/example/pingpong/pingpong_server.h +++ b/example/pingpong/pingpong_server.h @@ -17,6 +17,8 @@ class PingpongServer : taotu::NonCopyableMovable { public: + typedef std::vector EventManagers; + PingpongServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount = 5, size_t calculation_thread_amount = 0); @@ -34,7 +36,7 @@ class PingpongServer : taotu::NonCopyableMovable { taotu::IoBuffer* io_buffer, taotu::TimePoint time_point); - taotu::EventManager* event_manager_; + EventManagers event_managers_; std::unique_ptr server_; }; diff --git a/example/simple_discard/discard.cc b/example/simple_discard/discard.cc index 041ee794..a69f6cdf 100644 --- a/example/simple_discard/discard.cc +++ b/example/simple_discard/discard.cc @@ -18,9 +18,9 @@ DiscardServer::DiscardServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : event_manager_(new taotu::EventManager), + : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique( - event_manager_, listen_address, should_reuse_port, io_thread_amount, + &event_managers_, listen_address, should_reuse_port, io_thread_amount, calculation_thread_amount)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, @@ -29,14 +29,14 @@ DiscardServer::DiscardServer(const taotu::NetAddress& listen_address, }); } DiscardServer::~DiscardServer() { - delete event_manager_; + size_t event_managers_size = event_managers_.size(); + for (size_t i = 0; i < event_managers_size; ++i) { + delete event_managers_[i]; + } taotu::END_LOG(); } -void DiscardServer::Start() { - server_->Start(); - event_manager_->Work(); -} +void DiscardServer::Start() { server_->Start(); } void DiscardServer::OnMessageCallback(taotu::Connecting& connection, taotu::IoBuffer* io_buffer, diff --git a/example/simple_discard/discard.h b/example/simple_discard/discard.h index de8bdc0d..61e1bb72 100644 --- a/example/simple_discard/discard.h +++ b/example/simple_discard/discard.h @@ -15,6 +15,8 @@ class DiscardServer : taotu::NonCopyableMovable { public: + typedef std::vector EventManagers; + DiscardServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); @@ -29,7 +31,7 @@ class DiscardServer : taotu::NonCopyableMovable { taotu::IoBuffer* io_buffer, taotu::TimePoint time_point); - taotu::EventManager* event_manager_; + EventManagers event_managers_; std::unique_ptr server_; }; diff --git a/example/simple_echo/echo.cc b/example/simple_echo/echo.cc index 4e57630c..05842246 100644 --- a/example/simple_echo/echo.cc +++ b/example/simple_echo/echo.cc @@ -16,9 +16,9 @@ EchoServer::EchoServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : event_manager_(new taotu::EventManager), + : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique( - event_manager_, listen_address, should_reuse_port, io_thread_amount, + &event_managers_, listen_address, should_reuse_port, io_thread_amount, calculation_thread_amount)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, @@ -27,14 +27,14 @@ EchoServer::EchoServer(const taotu::NetAddress& listen_address, }); } EchoServer::~EchoServer() { - delete event_manager_; + size_t event_managers_size = event_managers_.size(); + for (size_t i = 0; i < event_managers_size; ++i) { + delete event_managers_[i]; + } taotu::END_LOG(); } -void EchoServer::Start() { - server_->Start(); - event_manager_->Work(); -} +void EchoServer::Start() { server_->Start(); } void EchoServer::OnMessageCallback(taotu::Connecting& connection, taotu::IoBuffer* io_buffer, diff --git a/example/simple_echo/echo.h b/example/simple_echo/echo.h index f11dd053..da06d42c 100644 --- a/example/simple_echo/echo.h +++ b/example/simple_echo/echo.h @@ -17,6 +17,8 @@ class EchoServer : taotu::NonCopyableMovable { public: + typedef std::vector EventManagers; + EchoServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); ~EchoServer(); @@ -30,7 +32,7 @@ class EchoServer : taotu::NonCopyableMovable { taotu::IoBuffer* io_buffer, taotu::TimePoint time_point); - taotu::EventManager* event_manager_; + EventManagers event_managers_; std::unique_ptr server_; }; diff --git a/example/simple_time/time.cc b/example/simple_time/time.cc index ebfb1cbf..abf57515 100644 --- a/example/simple_time/time.cc +++ b/example/simple_time/time.cc @@ -17,9 +17,9 @@ TimeServer::TimeServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : event_manager_(new taotu::EventManager), + : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique( - event_manager_, listen_address, should_reuse_port, io_thread_amount, + &event_managers_, listen_address, should_reuse_port, io_thread_amount, calculation_thread_amount)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, @@ -28,14 +28,14 @@ TimeServer::TimeServer(const taotu::NetAddress& listen_address, }); } TimeServer::~TimeServer() { - delete event_manager_; + size_t event_managers_size = event_managers_.size(); + for (size_t i = 0; i < event_managers_size; ++i) { + delete event_managers_[i]; + } taotu::END_LOG(); } -void TimeServer::Start() { - server_->Start(); - event_manager_->Work(); -} +void TimeServer::Start() { server_->Start(); } void TimeServer::OnMessageCallback(taotu::Connecting& connection, taotu::IoBuffer* io_buffer, diff --git a/example/simple_time/time.h b/example/simple_time/time.h index 5f6f6925..25fab34a 100644 --- a/example/simple_time/time.h +++ b/example/simple_time/time.h @@ -15,6 +15,8 @@ class TimeServer : taotu::NonCopyableMovable { public: + typedef std::vector EventManagers; + TimeServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); ~TimeServer(); @@ -28,7 +30,7 @@ class TimeServer : taotu::NonCopyableMovable { taotu::IoBuffer* io_buffer, taotu::TimePoint time_point); - taotu::EventManager* event_manager_; + EventManagers event_managers_; std::unique_ptr server_; }; diff --git a/src/event_manager.cc b/src/event_manager.cc index 0d09c52c..fc8ac34f 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -29,11 +29,7 @@ using namespace taotu; -EventManager::EventManager( - std::function - CreateConnectionCallback, - std::function DestroyConnectionCallback) +EventManager::EventManager() : poller_() #ifdef __linux__ , @@ -84,10 +80,6 @@ EventManager::EventManager( }); wake_up_eventer_->EnableReadEvents(); #endif - if (CreateConnectionCallback && DestroyConnectionCallback) { - CreateConnectionCallback_ = CreateConnectionCallback; - DestroyConnectionCallback_ = DestroyConnectionCallback; - } } EventManager::~EventManager() { #ifdef __linux__ diff --git a/src/event_manager.h b/src/event_manager.h index 688093bb..143a8638 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -40,14 +40,20 @@ namespace taotu { */ class EventManager : NonCopyableMovable { public: - EventManager( + EventManager(); + ~EventManager(); + + void SetCreateConnectionCallback( std::function - CreateConnectionCallback = std::function{}, - std::function DestroyConnectionCallback = - std::function{}); - ~EventManager(); + CreateConnectionCallback) { + CreateConnectionCallback_ = CreateConnectionCallback; + } + + void SetDestroyConnectionCallback( + std::function DestroyConnectionCallback) { + DestroyConnectionCallback_ = DestroyConnectionCallback; + } // Run the loop in a new thread (called once guarantee) void Loop(); diff --git a/src/reactor_manager.cc b/src/reactor_manager.cc index aa66c269..3a8d980c 100644 --- a/src/reactor_manager.cc +++ b/src/reactor_manager.cc @@ -48,12 +48,12 @@ static NetAddress GetPeerAddress(int socket_fd) { return NetAddress(local_addr); } -ServerReactorManager::ServerReactorManager(EventManager* event_manager, +ServerReactorManager::ServerReactorManager(EventManagers* event_managers, const NetAddress& listen_address, size_t io_thread_amount, bool should_reuse_port) - : event_managers_({event_manager}), - acceptor_(std::make_unique(event_managers_[0]->GetPoller(), + : event_managers_(event_managers), + acceptor_(std::make_unique((*event_managers_)[0]->GetPoller(), listen_address, should_reuse_port)) { if (acceptor_->Fd() >= 0 && !acceptor_->IsListening()) { acceptor_->Listen(); @@ -65,35 +65,37 @@ ServerReactorManager::ServerReactorManager(EventManager* event_manager, LOG_ERROR("Fail to init the acceptor!!!"); ::exit(-1); } - event_managers_[0] = event_manager; + // TODO: event_managers_[0] = event_managers; for (size_t i = 0; i < io_thread_amount; ++i) { - // Initialize "Reactor"s - event_managers_.emplace_back(new EventManager( + // "Initialize" "Reactor"s + (*event_managers_)[i]->SetCreateConnectionCallback( [this](EventManager* event_manager, int fd, const NetAddress& server_address, const NetAddress& peer_address) -> Connecting* { return this->NewOneConnectingFromObjectPool( event_manager, fd, server_address, peer_address); - }, + }); + (*event_managers_)[i]->SetDestroyConnectionCallback( [this](Connecting* connecting_ptr) { this->DeleteOneConnectingFromObjectPool(connecting_ptr); - })); + }); } - balancer_ = std::make_unique(&event_managers_, 0); + balancer_ = std::make_unique(event_managers_, 0); } ServerReactorManager::~ServerReactorManager() { - size_t thread_amount = event_managers_.size(); - for (size_t i = 1; i < thread_amount; ++i) { - delete event_managers_[i]; - } + // size_t thread_amount = event_managers_.size(); + // for (size_t i = 1; i < thread_amount; ++i) { + // delete event_managers_[i]; + // } } void ServerReactorManager::Loop() { - size_t io_thread_amount = event_managers_.size(); + size_t io_thread_amount = (*event_managers_).size(); for (size_t i = 1; i < io_thread_amount; ++i) { // Start each event loop in the corresponding I/O thread - event_managers_[i]->Loop(); + (*event_managers_)[i]->Loop(); } + (*event_managers_)[0]->Work(); // Do not start an event loop in main thread (mainly for accepting) // Like this: // `event_managers_[0]->Work();` diff --git a/src/reactor_manager.h b/src/reactor_manager.h index 2dada9b6..8d00cf25 100644 --- a/src/reactor_manager.h +++ b/src/reactor_manager.h @@ -45,7 +45,7 @@ class ServerReactorManager : NonCopyableMovable { typedef std::vector EventManagers; - ServerReactorManager(EventManager* event_manager, + ServerReactorManager(EventManagers* event_managers, const NetAddress& listen_address, size_t io_thread_amount = 6, bool should_reuse_port = false); @@ -86,7 +86,7 @@ class ServerReactorManager : NonCopyableMovable { // Event managers which are the "Reactor"s that manages events in their own // I/O threads - EventManagers event_managers_; + EventManagers* event_managers_; // Acceptor for accepting new connections in the main thread AcceptorPtr acceptor_; diff --git a/src/server.cc b/src/server.cc index 34b4e2a9..3f28c202 100644 --- a/src/server.cc +++ b/src/server.cc @@ -18,10 +18,10 @@ using namespace taotu; -Server::Server(EventManager* event_manager, const NetAddress& listen_address, +Server::Server(EventManagers* event_managers, const NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) - : reactor_manager_(event_manager, listen_address, io_thread_amount, + : reactor_manager_(event_managers, listen_address, io_thread_amount, should_reuse_port), thread_pool_(calculation_thread_amount), is_started_(false) { diff --git a/src/server.h b/src/server.h index 530f7c45..7233031f 100644 --- a/src/server.h +++ b/src/server.h @@ -32,7 +32,10 @@ namespace taotu { */ class Server : NonCopyableMovable { public: - explicit Server(EventManager* event_manager, const NetAddress& listen_address, + typedef std::vector EventManagers; + + explicit Server(EventManagers* event_managers, + const NetAddress& listen_address, bool should_reuse_port = false, size_t io_thread_amount = 6, size_t calculation_thread_amount = 4); From 4fc95879db265d0c441e62dd3c991b8e17420a01 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 11 Aug 2023 13:34:04 -0400 Subject: [PATCH 14/78] [src] Improve EventManager and ReactorManager --- src/event_manager.cc | 6 +++--- src/event_manager.h | 3 ++- src/reactor_manager.cc | 7 ------- src/reactor_manager.h | 1 - 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index fc8ac34f..babd83b8 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -205,12 +205,12 @@ void EventManager::WakeUp() { #endif } -void EventManager::Quit() { should_quit_ = true; } +void EventManager::Quit() { should_quit_.store(true); } void EventManager::Start() { - should_quit_ = false; + should_quit_.store(false); LOG_DEBUG("The event loop in thread(%lu) is starting.", ::pthread_self()); - while (!should_quit_) { + while (!should_quit_.load()) { auto return_time = poller_.Poll(timer_.GetMinTimeDuration(), &active_events_); // Return time is the time point of diff --git a/src/event_manager.h b/src/event_manager.h index 143a8638..f839796b 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -14,6 +14,7 @@ #include +#include #include #include #include @@ -125,7 +126,7 @@ class EventManager : NonCopyableMovable { mutable MutexLock connection_map_mutex_lock_; // The flag for deciding whether the event loop should quit - bool should_quit_; + std::atomic_bool should_quit_; // List for active events returned from the I/O multiplexing waiting each loop Poller::EventerList active_events_; diff --git a/src/reactor_manager.cc b/src/reactor_manager.cc index 3a8d980c..5698f736 100644 --- a/src/reactor_manager.cc +++ b/src/reactor_manager.cc @@ -65,7 +65,6 @@ ServerReactorManager::ServerReactorManager(EventManagers* event_managers, LOG_ERROR("Fail to init the acceptor!!!"); ::exit(-1); } - // TODO: event_managers_[0] = event_managers; for (size_t i = 0; i < io_thread_amount; ++i) { // "Initialize" "Reactor"s (*event_managers_)[i]->SetCreateConnectionCallback( @@ -82,12 +81,6 @@ ServerReactorManager::ServerReactorManager(EventManagers* event_managers, } balancer_ = std::make_unique(event_managers_, 0); } -ServerReactorManager::~ServerReactorManager() { - // size_t thread_amount = event_managers_.size(); - // for (size_t i = 1; i < thread_amount; ++i) { - // delete event_managers_[i]; - // } -} void ServerReactorManager::Loop() { size_t io_thread_amount = (*event_managers_).size(); diff --git a/src/reactor_manager.h b/src/reactor_manager.h index 8d00cf25..f14e5d07 100644 --- a/src/reactor_manager.h +++ b/src/reactor_manager.h @@ -49,7 +49,6 @@ class ServerReactorManager : NonCopyableMovable { const NetAddress& listen_address, size_t io_thread_amount = 6, bool should_reuse_port = false); - ~ServerReactorManager(); void SetConnectionCallback(const NormalCallback& cb) { ConnectionCallback_ = cb; From 6f8346085610cc2f2f1a2e006e2fdd4809880a7b Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 11 Aug 2023 13:50:38 -0400 Subject: [PATCH 15/78] [src] Add destructor for ReactorManager --- src/reactor_manager.cc | 1 + src/reactor_manager.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/reactor_manager.cc b/src/reactor_manager.cc index 5698f736..28c69a55 100644 --- a/src/reactor_manager.cc +++ b/src/reactor_manager.cc @@ -81,6 +81,7 @@ ServerReactorManager::ServerReactorManager(EventManagers* event_managers, } balancer_ = std::make_unique(event_managers_, 0); } +ServerReactorManager::~ServerReactorManager() {} void ServerReactorManager::Loop() { size_t io_thread_amount = (*event_managers_).size(); diff --git a/src/reactor_manager.h b/src/reactor_manager.h index f14e5d07..8d00cf25 100644 --- a/src/reactor_manager.h +++ b/src/reactor_manager.h @@ -49,6 +49,7 @@ class ServerReactorManager : NonCopyableMovable { const NetAddress& listen_address, size_t io_thread_amount = 6, bool should_reuse_port = false); + ~ServerReactorManager(); void SetConnectionCallback(const NormalCallback& cb) { ConnectionCallback_ = cb; From 2e064feff440181eb13c84414dcf69210064e0d9 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 11 Aug 2023 13:55:06 -0400 Subject: [PATCH 16/78] [example] Improve the code of HttpServer --- example/http_server/http_server.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/http_server/http_server.cc b/example/http_server/http_server.cc index e37f61bc..2c9d97f8 100644 --- a/example/http_server/http_server.cc +++ b/example/http_server/http_server.cc @@ -10,7 +10,7 @@ #include "http_server.h" -#include +#include #include "http_parser.h" #include "http_response.h" From 1f8e15d529c0106c15092bd5d1f4936e8c0854c8 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 11 Aug 2023 16:02:14 -0400 Subject: [PATCH 17/78] [src] Modify EventManager callback register --- src/event_manager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/event_manager.h b/src/event_manager.h index f839796b..2040b786 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -45,14 +45,14 @@ class EventManager : NonCopyableMovable { ~EventManager(); void SetCreateConnectionCallback( - std::function + const std::function& CreateConnectionCallback) { CreateConnectionCallback_ = CreateConnectionCallback; } void SetDestroyConnectionCallback( - std::function DestroyConnectionCallback) { + const std::function& DestroyConnectionCallback) { DestroyConnectionCallback_ = DestroyConnectionCallback; } From 4c2f85424b1798f75914fbb9bd33a8a021e8364a Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sun, 13 Aug 2023 16:18:48 -0400 Subject: [PATCH 18/78] [src && example] Refactor I/O threads number setting method --- example/chat_room/chat_server.cc | 6 +++--- example/http_server/http_server.cc | 6 +++--- example/pingpong/pingpong_server.cc | 6 +++--- example/simple_discard/discard.cc | 6 +++--- example/simple_echo/echo.cc | 6 +++--- example/simple_time/time.cc | 6 +++--- src/reactor_manager.cc | 3 +-- src/reactor_manager.h | 1 - src/server.cc | 6 ++---- src/server.h | 2 +- 10 files changed, 22 insertions(+), 26 deletions(-) diff --git a/example/chat_room/chat_server.cc b/example/chat_room/chat_server.cc index 07d7549f..4110018a 100644 --- a/example/chat_room/chat_server.cc +++ b/example/chat_room/chat_server.cc @@ -16,9 +16,9 @@ ChatServer::ChatServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), - server_(std::make_unique( - &event_managers_, listen_address, should_reuse_port, io_thread_amount, - calculation_thread_amount)), + server_(std::make_unique(&event_managers_, listen_address, + should_reuse_port, + calculation_thread_amount)), codec_([this](taotu::Connecting& connection, const std::string& message, taotu::TimePoint time_point) { this->OnCodecMessage(connection, message, time_point); diff --git a/example/http_server/http_server.cc b/example/http_server/http_server.cc index 2c9d97f8..4fe0f9d6 100644 --- a/example/http_server/http_server.cc +++ b/example/http_server/http_server.cc @@ -19,9 +19,9 @@ HttpServer::HttpServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), - server_(std::make_unique( - &event_managers_, listen_address, should_reuse_port, io_thread_amount, - calculation_thread_amount)) { + server_(std::make_unique(&event_managers_, listen_address, + should_reuse_port, + calculation_thread_amount)) { server_->SetConnectionCallback([this](taotu::Connecting& connection) { this->OnConnectionCallback(connection); }); diff --git a/example/pingpong/pingpong_server.cc b/example/pingpong/pingpong_server.cc index 9dc48cc5..7e3cbe36 100644 --- a/example/pingpong/pingpong_server.cc +++ b/example/pingpong/pingpong_server.cc @@ -14,9 +14,9 @@ PingpongServer::PingpongServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), - server_(std::make_unique( - &event_managers_, listen_address, should_reuse_port, io_thread_amount, - calculation_thread_amount)) { + server_(std::make_unique(&event_managers_, listen_address, + should_reuse_port, + calculation_thread_amount)) { server_->SetConnectionCallback([this](taotu::Connecting& connection) { this->OnConnectionCallback(connection); }); diff --git a/example/simple_discard/discard.cc b/example/simple_discard/discard.cc index a69f6cdf..7e13c623 100644 --- a/example/simple_discard/discard.cc +++ b/example/simple_discard/discard.cc @@ -19,9 +19,9 @@ DiscardServer::DiscardServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), - server_(std::make_unique( - &event_managers_, listen_address, should_reuse_port, io_thread_amount, - calculation_thread_amount)) { + server_(std::make_unique(&event_managers_, listen_address, + should_reuse_port, + calculation_thread_amount)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, taotu::TimePoint time_point) { diff --git a/example/simple_echo/echo.cc b/example/simple_echo/echo.cc index 05842246..0153f8f6 100644 --- a/example/simple_echo/echo.cc +++ b/example/simple_echo/echo.cc @@ -17,9 +17,9 @@ EchoServer::EchoServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), - server_(std::make_unique( - &event_managers_, listen_address, should_reuse_port, io_thread_amount, - calculation_thread_amount)) { + server_(std::make_unique(&event_managers_, listen_address, + should_reuse_port, + calculation_thread_amount)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, taotu::TimePoint time_point) { diff --git a/example/simple_time/time.cc b/example/simple_time/time.cc index abf57515..79b64291 100644 --- a/example/simple_time/time.cc +++ b/example/simple_time/time.cc @@ -18,9 +18,9 @@ TimeServer::TimeServer(const taotu::NetAddress& listen_address, bool should_reuse_port, size_t io_thread_amount, size_t calculation_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), - server_(std::make_unique( - &event_managers_, listen_address, should_reuse_port, io_thread_amount, - calculation_thread_amount)) { + server_(std::make_unique(&event_managers_, listen_address, + should_reuse_port, + calculation_thread_amount)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, taotu::TimePoint time_point) { diff --git a/src/reactor_manager.cc b/src/reactor_manager.cc index 28c69a55..1eff6e4c 100644 --- a/src/reactor_manager.cc +++ b/src/reactor_manager.cc @@ -50,7 +50,6 @@ static NetAddress GetPeerAddress(int socket_fd) { ServerReactorManager::ServerReactorManager(EventManagers* event_managers, const NetAddress& listen_address, - size_t io_thread_amount, bool should_reuse_port) : event_managers_(event_managers), acceptor_(std::make_unique((*event_managers_)[0]->GetPoller(), @@ -65,7 +64,7 @@ ServerReactorManager::ServerReactorManager(EventManagers* event_managers, LOG_ERROR("Fail to init the acceptor!!!"); ::exit(-1); } - for (size_t i = 0; i < io_thread_amount; ++i) { + for (size_t i = 0; i < event_managers->size(); ++i) { // "Initialize" "Reactor"s (*event_managers_)[i]->SetCreateConnectionCallback( [this](EventManager* event_manager, int fd, diff --git a/src/reactor_manager.h b/src/reactor_manager.h index 8d00cf25..94a14a35 100644 --- a/src/reactor_manager.h +++ b/src/reactor_manager.h @@ -47,7 +47,6 @@ class ServerReactorManager : NonCopyableMovable { ServerReactorManager(EventManagers* event_managers, const NetAddress& listen_address, - size_t io_thread_amount = 6, bool should_reuse_port = false); ~ServerReactorManager(); diff --git a/src/server.cc b/src/server.cc index 3f28c202..f732ee8d 100644 --- a/src/server.cc +++ b/src/server.cc @@ -19,10 +19,8 @@ using namespace taotu; Server::Server(EventManagers* event_managers, const NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) - : reactor_manager_(event_managers, listen_address, io_thread_amount, - should_reuse_port), + bool should_reuse_port, size_t calculation_thread_amount) + : reactor_manager_(event_managers, listen_address, should_reuse_port), thread_pool_(calculation_thread_amount), is_started_(false) { reactor_manager_.SetConnectionCallback([this](Connecting& connection) { diff --git a/src/server.h b/src/server.h index 7233031f..e14ec314 100644 --- a/src/server.h +++ b/src/server.h @@ -36,7 +36,7 @@ class Server : NonCopyableMovable { explicit Server(EventManagers* event_managers, const NetAddress& listen_address, - bool should_reuse_port = false, size_t io_thread_amount = 6, + bool should_reuse_port = false, size_t calculation_thread_amount = 4); void SetConnectionCallback(const std::function& cb); From a14f6c218d64650ee29bc0ea3fa9c33325ac9ad5 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 15 Aug 2023 20:46:25 -0400 Subject: [PATCH 19/78] [src] Develop RPC module --- src/CMakeLists.txt | 23 + src/rpc.pb.cc | 1886 +++++++++++++++++++++++++++++++++++++ src/rpc.pb.h | 2224 ++++++++++++++++++++++++++++++++++++++++++++ src/rpc.proto | 71 ++ src/rpc_channel.cc | 163 ++++ src/rpc_channel.h | 101 ++ src/rpc_codec.cc | 196 ++++ src/rpc_codec.h | 182 ++++ src/rpc_server.cc | 34 + src/rpc_server.h | 57 ++ 10 files changed, 4937 insertions(+) create mode 100644 src/rpc.pb.cc create mode 100644 src/rpc.pb.h create mode 100644 src/rpc.proto create mode 100644 src/rpc_channel.cc create mode 100644 src/rpc_channel.h create mode 100644 src/rpc_codec.cc create mode 100644 src/rpc_codec.h create mode 100644 src/rpc_server.cc create mode 100644 src/rpc_server.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd587454..b06317cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,22 @@ +FIND_PACKAGE(Protobuf CONFIG REQUIRED) + +SET(PROTO_PATH "${CMAKE_SOURCE_DIR}/src/") +SET(TIME_PROTO "${PROTO_PATH}/rpc.proto") +SET(GENERATED_PROTOBUF_PATH "${CMAKE_SOURCE_DIR}/src/") + +SET(RPC_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/rpc.pb.cc") +SET(RPC_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/rpc.pb.h") + +ADD_CUSTOM_COMMAND( + OUTPUT ${RPC_PB_H_FILE} + ${RPC_PB_CPP_FILE} + COMMAND protobuf::protoc + ARGS --proto_path ${PROTO_PATH} + --cpp_out ${GENERATED_PROTOBUF_PATH} + ${TIME_PROTO} + DEPENDS ${TIME_PROTO} +) + SET(TAOTU_SOURCE acceptor.cc timer.cc @@ -16,6 +35,10 @@ SET(TAOTU_SOURCE client.cc net_address.cc balancer.cc + ${RPC_PB_CPP_FILE} + rpc_codec.cc + rpc_channel.cc + rpc_server.cc ) FIND_PACKAGE(Threads REQUIRED) diff --git a/src/rpc.pb.cc b/src/rpc.pb.cc new file mode 100644 index 00000000..9c8866ac --- /dev/null +++ b/src/rpc.pb.cc @@ -0,0 +1,1886 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: rpc.proto + +#include "rpc.pb.h" + +#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" +PROTOBUF_PRAGMA_INIT_SEG +namespace _pb = ::PROTOBUF_NAMESPACE_ID; +namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace taotu { +template +PROTOBUF_CONSTEXPR RpcMessage::RpcMessage( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_._has_bits_)*/{} + , /*decltype(_impl_._cached_size_)*/{} + , /*decltype(_impl_.service_)*/ { + &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} + } + + , /*decltype(_impl_.method_)*/ { + &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} + } + + , /*decltype(_impl_.request_)*/ { + &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} + } + + , /*decltype(_impl_.response_)*/ { + &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} + } + + , /*decltype(_impl_.id_)*/ ::uint64_t{0u} + + , /*decltype(_impl_.type_)*/ 0 + + , /*decltype(_impl_.error_)*/ 0 +} {} +struct RpcMessageDefaultTypeInternal { + PROTOBUF_CONSTEXPR RpcMessageDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~RpcMessageDefaultTypeInternal() {} + union { + RpcMessage _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 RpcMessageDefaultTypeInternal _RpcMessage_default_instance_; +template +PROTOBUF_CONSTEXPR ListRpcRequest::ListRpcRequest( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_._has_bits_)*/{} + , /*decltype(_impl_._cached_size_)*/{} + , /*decltype(_impl_.service_name_)*/ { + &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} + } + + , /*decltype(_impl_.list_method_)*/ false +} {} +struct ListRpcRequestDefaultTypeInternal { + PROTOBUF_CONSTEXPR ListRpcRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~ListRpcRequestDefaultTypeInternal() {} + union { + ListRpcRequest _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ListRpcRequestDefaultTypeInternal _ListRpcRequest_default_instance_; +template +PROTOBUF_CONSTEXPR ListRpcResponse::ListRpcResponse( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.service_name_)*/{} + , /*decltype(_impl_.method_name_)*/{} + , /*decltype(_impl_.error_)*/ 0 + + , /*decltype(_impl_._cached_size_)*/{}} {} +struct ListRpcResponseDefaultTypeInternal { + PROTOBUF_CONSTEXPR ListRpcResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~ListRpcResponseDefaultTypeInternal() {} + union { + ListRpcResponse _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ListRpcResponseDefaultTypeInternal _ListRpcResponse_default_instance_; +template +PROTOBUF_CONSTEXPR GetServiceRequest::GetServiceRequest( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.service_name_)*/ { + &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} + } + + , /*decltype(_impl_._cached_size_)*/{}} {} +struct GetServiceRequestDefaultTypeInternal { + PROTOBUF_CONSTEXPR GetServiceRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~GetServiceRequestDefaultTypeInternal() {} + union { + GetServiceRequest _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GetServiceRequestDefaultTypeInternal _GetServiceRequest_default_instance_; +template +PROTOBUF_CONSTEXPR GetServiceResponse::GetServiceResponse( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.proto_file_)*/{} + , /*decltype(_impl_.proto_file_name_)*/{} + , /*decltype(_impl_.error_)*/ 0 + + , /*decltype(_impl_._cached_size_)*/{}} {} +struct GetServiceResponseDefaultTypeInternal { + PROTOBUF_CONSTEXPR GetServiceResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~GetServiceResponseDefaultTypeInternal() {} + union { + GetServiceResponse _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GetServiceResponseDefaultTypeInternal _GetServiceResponse_default_instance_; +} // namespace taotu +static ::_pb::Metadata file_level_metadata_rpc_2eproto[5]; +static const ::_pb::EnumDescriptor* file_level_enum_descriptors_rpc_2eproto[2]; +static const ::_pb::ServiceDescriptor* + file_level_service_descriptors_rpc_2eproto[1]; +const ::uint32_t TableStruct_rpc_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( + protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _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(::taotu::RpcMessage, _impl_.type_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.id_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.service_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.method_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.request_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.response_), + PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.error_), + ~0u, + ~0u, + 0, + 1, + 2, + 3, + 4, + PROTOBUF_FIELD_OFFSET(::taotu::ListRpcRequest, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::taotu::ListRpcRequest, _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(::taotu::ListRpcRequest, _impl_.service_name_), + PROTOBUF_FIELD_OFFSET(::taotu::ListRpcRequest, _impl_.list_method_), + 0, + 1, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::taotu::ListRpcResponse, _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(::taotu::ListRpcResponse, _impl_.error_), + PROTOBUF_FIELD_OFFSET(::taotu::ListRpcResponse, _impl_.service_name_), + PROTOBUF_FIELD_OFFSET(::taotu::ListRpcResponse, _impl_.method_name_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::taotu::GetServiceRequest, _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(::taotu::GetServiceRequest, _impl_.service_name_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::taotu::GetServiceResponse, _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(::taotu::GetServiceResponse, _impl_.error_), + PROTOBUF_FIELD_OFFSET(::taotu::GetServiceResponse, _impl_.proto_file_), + PROTOBUF_FIELD_OFFSET(::taotu::GetServiceResponse, _impl_.proto_file_name_), +}; + +static const ::_pbi::MigrationSchema + schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, 15, -1, sizeof(::taotu::RpcMessage)}, + { 22, 32, -1, sizeof(::taotu::ListRpcRequest)}, + { 34, -1, -1, sizeof(::taotu::ListRpcResponse)}, + { 45, -1, -1, sizeof(::taotu::GetServiceRequest)}, + { 54, -1, -1, sizeof(::taotu::GetServiceResponse)}, +}; + +static const ::_pb::Message* const file_default_instances[] = { + &::taotu::_RpcMessage_default_instance_._instance, + &::taotu::_ListRpcRequest_default_instance_._instance, + &::taotu::_ListRpcResponse_default_instance_._instance, + &::taotu::_GetServiceRequest_default_instance_._instance, + &::taotu::_GetServiceResponse_default_instance_._instance, +}; +const char descriptor_table_protodef_rpc_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + "\n\trpc.proto\022\005taotu\"\362\001\n\nRpcMessage\022 \n\004typ" + "e\030\001 \001(\0162\022.taotu.MessageType\022\n\n\002id\030\002 \001(\006\022" + "\024\n\007service\030\003 \001(\tH\000\210\001\001\022\023\n\006method\030\004 \001(\tH\001\210" + "\001\001\022\024\n\007request\030\005 \001(\014H\002\210\001\001\022\025\n\010response\030\006 \001" + "(\014H\003\210\001\001\022$\n\005error\030\007 \001(\0162\020.taotu.ErrorCode" + "H\004\210\001\001B\n\n\010_serviceB\t\n\007_methodB\n\n\010_request" + "B\013\n\t_responseB\010\n\006_error\"f\n\016ListRpcReques" + "t\022\031\n\014service_name\030\001 \001(\tH\000\210\001\001\022\030\n\013list_met" + "hod\030\002 \001(\010H\001\210\001\001B\017\n\r_service_nameB\016\n\014_list" + "_method\"]\n\017ListRpcResponse\022\037\n\005error\030\001 \001(" + "\0162\020.taotu.ErrorCode\022\024\n\014service_name\030\002 \003(" + "\t\022\023\n\013method_name\030\003 \003(\t\")\n\021GetServiceRequ" + "est\022\024\n\014service_name\030\001 \001(\t\"b\n\022GetServiceR" + "esponse\022\037\n\005error\030\001 \001(\0162\020.taotu.ErrorCode" + "\022\022\n\nproto_file\030\002 \003(\t\022\027\n\017proto_file_name\030" + "\003 \003(\t*>\n\013MessageType\022\t\n\005OTHER\020\000\022\013\n\007REQUE" + "ST\020\001\022\014\n\010RESPONSE\020\002\022\t\n\005ERROR\020\003*\201\001\n\tErrorC" + "ode\022\014\n\010NO_ERROR\020\000\022\017\n\013WRONG_PROTO\020\001\022\016\n\nNO" + "_SERVICE\020\002\022\r\n\tNO_METHOD\020\003\022\023\n\017INVALID_REQ" + "UEST\020\004\022\024\n\020INVALID_RESPONSE\020\005\022\013\n\007TIMEOUT\020" + "\0062\211\001\n\nRpcService\0228\n\007ListRpc\022\025.taotu.List" + "RpcRequest\032\026.taotu.ListRpcResponse\022A\n\nGe" + "tService\022\030.taotu.GetServiceRequest\032\031.tao" + "tu.GetServiceResponseB\t\200\001\001\210\001\001\220\001\001b\006proto3" +}; +static ::absl::once_flag descriptor_table_rpc_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_rpc_2eproto = { + false, + false, + 960, + descriptor_table_protodef_rpc_2eproto, + "rpc.proto", + &descriptor_table_rpc_2eproto_once, + nullptr, + 0, + 5, + schemas, + file_default_instances, + TableStruct_rpc_2eproto::offsets, + file_level_metadata_rpc_2eproto, + file_level_enum_descriptors_rpc_2eproto, + file_level_service_descriptors_rpc_2eproto, +}; + +// This function exists to be marked as weak. +// It can significantly speed up compilation by breaking up LLVM's SCC +// in the .pb.cc translation units. Large translation units see a +// reduction of more than 35% of walltime for optimized builds. Without +// the weak attribute all the messages in the file, including all the +// vtables and everything they use become part of the same SCC through +// a cycle like: +// GetMetadata -> descriptor table -> default instances -> +// vtables -> GetMetadata +// By adding a weak function here we break the connection from the +// individual vtables back into the descriptor table. +PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_rpc_2eproto_getter() { + return &descriptor_table_rpc_2eproto; +} +// Force running AddDescriptors() at dynamic initialization time. +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 +static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_rpc_2eproto(&descriptor_table_rpc_2eproto); +namespace taotu { +const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* MessageType_descriptor() { + ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rpc_2eproto); + return file_level_enum_descriptors_rpc_2eproto[0]; +} +bool MessageType_IsValid(int value) { + switch (value) { + case 0: + case 1: + case 2: + case 3: + return true; + default: + return false; + } +} +const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ErrorCode_descriptor() { + ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rpc_2eproto); + return file_level_enum_descriptors_rpc_2eproto[1]; +} +bool ErrorCode_IsValid(int value) { + switch (value) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + return true; + default: + return false; + } +} +// =================================================================== + +class RpcMessage::_Internal { + public: + using HasBits = decltype(std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(RpcMessage, _impl_._has_bits_); + static void set_has_service(HasBits* has_bits) { + (*has_bits)[0] |= 1u; + } + static void set_has_method(HasBits* has_bits) { + (*has_bits)[0] |= 2u; + } + static void set_has_request(HasBits* has_bits) { + (*has_bits)[0] |= 4u; + } + static void set_has_response(HasBits* has_bits) { + (*has_bits)[0] |= 8u; + } + static void set_has_error(HasBits* has_bits) { + (*has_bits)[0] |= 16u; + } +}; + +RpcMessage::RpcMessage(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:taotu.RpcMessage) +} +RpcMessage::RpcMessage(const RpcMessage& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + RpcMessage* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){from._impl_._has_bits_} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.service_) {} + + , decltype(_impl_.method_) {} + + , decltype(_impl_.request_) {} + + , decltype(_impl_.response_) {} + + , decltype(_impl_.id_) {} + + , decltype(_impl_.type_) {} + + , decltype(_impl_.error_) {} + }; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _impl_.service_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { + _this->_impl_.service_.Set(from._internal_service(), _this->GetArenaForAllocation()); + } + _impl_.method_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.method_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if ((from._impl_._has_bits_[0] & 0x00000002u) != 0) { + _this->_impl_.method_.Set(from._internal_method(), _this->GetArenaForAllocation()); + } + _impl_.request_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.request_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if ((from._impl_._has_bits_[0] & 0x00000004u) != 0) { + _this->_impl_.request_.Set(from._internal_request(), _this->GetArenaForAllocation()); + } + _impl_.response_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.response_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if ((from._impl_._has_bits_[0] & 0x00000008u) != 0) { + _this->_impl_.response_.Set(from._internal_response(), _this->GetArenaForAllocation()); + } + ::memcpy(&_impl_.id_, &from._impl_.id_, + static_cast<::size_t>(reinterpret_cast(&_impl_.error_) - + reinterpret_cast(&_impl_.id_)) + sizeof(_impl_.error_)); + // @@protoc_insertion_point(copy_constructor:taotu.RpcMessage) +} + +inline void RpcMessage::SharedCtor(::_pb::Arena* arena) { + (void)arena; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.service_) {} + + , decltype(_impl_.method_) {} + + , decltype(_impl_.request_) {} + + , decltype(_impl_.response_) {} + + , decltype(_impl_.id_) { ::uint64_t{0u} } + + , decltype(_impl_.type_) { 0 } + + , decltype(_impl_.error_) { 0 } + + }; + _impl_.service_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.method_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.method_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.request_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.request_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.response_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.response_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING +} + +RpcMessage::~RpcMessage() { + // @@protoc_insertion_point(destructor:taotu.RpcMessage) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void RpcMessage::SharedDtor() { + ABSL_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.service_.Destroy(); + _impl_.method_.Destroy(); + _impl_.request_.Destroy(); + _impl_.response_.Destroy(); +} + +void RpcMessage::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void RpcMessage::Clear() { +// @@protoc_insertion_point(message_clear_start:taotu.RpcMessage) + ::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 & 0x0000000fu) { + if (cached_has_bits & 0x00000001u) { + _impl_.service_.ClearNonDefaultToEmpty(); + } + if (cached_has_bits & 0x00000002u) { + _impl_.method_.ClearNonDefaultToEmpty(); + } + if (cached_has_bits & 0x00000004u) { + _impl_.request_.ClearNonDefaultToEmpty(); + } + if (cached_has_bits & 0x00000008u) { + _impl_.response_.ClearNonDefaultToEmpty(); + } + } + ::memset(&_impl_.id_, 0, static_cast<::size_t>( + reinterpret_cast(&_impl_.type_) - + reinterpret_cast(&_impl_.id_)) + sizeof(_impl_.type_)); + _impl_.error_ = 0; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* RpcMessage::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + _Internal::HasBits has_bits{}; + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // .taotu.MessageType type = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { + ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + CHK_(ptr); + _internal_set_type(static_cast<::taotu::MessageType>(val)); + } else { + goto handle_unusual; + } + continue; + // fixed64 id = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 17)) { + _impl_.id_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::uint64_t>(ptr); + ptr += sizeof(::uint64_t); + } else { + goto handle_unusual; + } + continue; + // optional string service = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { + auto str = _internal_mutable_service(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.RpcMessage.service")); + } else { + goto handle_unusual; + } + continue; + // optional string method = 4; + case 4: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { + auto str = _internal_mutable_method(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.RpcMessage.method")); + } else { + goto handle_unusual; + } + continue; + // optional bytes request = 5; + case 5: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 42)) { + auto str = _internal_mutable_request(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + // optional bytes response = 6; + case 6: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 50)) { + auto str = _internal_mutable_response(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + // optional .taotu.ErrorCode error = 7; + case 7: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 56)) { + ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + CHK_(ptr); + _internal_set_error(static_cast<::taotu::ErrorCode>(val)); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + _impl_._has_bits_.Or(has_bits); + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* RpcMessage::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:taotu.RpcMessage) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // .taotu.MessageType type = 1; + if (this->_internal_type() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteEnumToArray( + 1, this->_internal_type(), target); + } + + // fixed64 id = 2; + if (this->_internal_id() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFixed64ToArray( + 2, this->_internal_id(), target); + } + + cached_has_bits = _impl_._has_bits_[0]; + // optional string service = 3; + if (cached_has_bits & 0x00000001u) { + const std::string& _s = this->_internal_service(); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.RpcMessage.service"); + target = stream->WriteStringMaybeAliased(3, _s, target); + } + + // optional string method = 4; + if (cached_has_bits & 0x00000002u) { + const std::string& _s = this->_internal_method(); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.RpcMessage.method"); + target = stream->WriteStringMaybeAliased(4, _s, target); + } + + // optional bytes request = 5; + if (cached_has_bits & 0x00000004u) { + const std::string& _s = this->_internal_request(); + target = stream->WriteBytesMaybeAliased(5, _s, target); + } + + // optional bytes response = 6; + if (cached_has_bits & 0x00000008u) { + const std::string& _s = this->_internal_response(); + target = stream->WriteBytesMaybeAliased(6, _s, target); + } + + // optional .taotu.ErrorCode error = 7; + if (cached_has_bits & 0x00000010u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteEnumToArray( + 7, this->_internal_error(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:taotu.RpcMessage) + return target; +} + +::size_t RpcMessage::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:taotu.RpcMessage) + ::size_t total_size = 0; + + ::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 & 0x0000000fu) { + // optional string service = 3; + if (cached_has_bits & 0x00000001u) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_service()); + } + + // optional string method = 4; + if (cached_has_bits & 0x00000002u) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_method()); + } + + // optional bytes request = 5; + if (cached_has_bits & 0x00000004u) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( + this->_internal_request()); + } + + // optional bytes response = 6; + if (cached_has_bits & 0x00000008u) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( + this->_internal_response()); + } + + } + // fixed64 id = 2; + if (this->_internal_id() != 0) { + total_size += 9; + } + + // .taotu.MessageType type = 1; + if (this->_internal_type() != 0) { + total_size += 1 + + ::_pbi::WireFormatLite::EnumSize(this->_internal_type()); + } + + // optional .taotu.ErrorCode error = 7; + if (cached_has_bits & 0x00000010u) { + total_size += 1 + + ::_pbi::WireFormatLite::EnumSize(this->_internal_error()); + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData RpcMessage::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + RpcMessage::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*RpcMessage::GetClassData() const { return &_class_data_; } + + +void RpcMessage::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:taotu.RpcMessage) + 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 & 0x0000000fu) { + if (cached_has_bits & 0x00000001u) { + _this->_internal_set_service(from._internal_service()); + } + if (cached_has_bits & 0x00000002u) { + _this->_internal_set_method(from._internal_method()); + } + if (cached_has_bits & 0x00000004u) { + _this->_internal_set_request(from._internal_request()); + } + if (cached_has_bits & 0x00000008u) { + _this->_internal_set_response(from._internal_response()); + } + } + if (from._internal_id() != 0) { + _this->_internal_set_id(from._internal_id()); + } + if (from._internal_type() != 0) { + _this->_internal_set_type(from._internal_type()); + } + if (cached_has_bits & 0x00000010u) { + _this->_internal_set_error(from._internal_error()); + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void RpcMessage::CopyFrom(const RpcMessage& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:taotu.RpcMessage) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool RpcMessage::IsInitialized() const { + return true; +} + +void RpcMessage::InternalSwap(RpcMessage* other) { + using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.service_, lhs_arena, + &other->_impl_.service_, rhs_arena); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.method_, lhs_arena, + &other->_impl_.method_, rhs_arena); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.request_, lhs_arena, + &other->_impl_.request_, rhs_arena); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.response_, lhs_arena, + &other->_impl_.response_, rhs_arena); + ::PROTOBUF_NAMESPACE_ID::internal::memswap< + PROTOBUF_FIELD_OFFSET(RpcMessage, _impl_.error_) + + sizeof(RpcMessage::_impl_.error_) + - PROTOBUF_FIELD_OFFSET(RpcMessage, _impl_.id_)>( + reinterpret_cast(&_impl_.id_), + reinterpret_cast(&other->_impl_.id_)); +} + +::PROTOBUF_NAMESPACE_ID::Metadata RpcMessage::GetMetadata() const { + return ::_pbi::AssignDescriptors( + &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, + file_level_metadata_rpc_2eproto[0]); +} +// =================================================================== + +class ListRpcRequest::_Internal { + public: + using HasBits = decltype(std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(ListRpcRequest, _impl_._has_bits_); + static void set_has_service_name(HasBits* has_bits) { + (*has_bits)[0] |= 1u; + } + static void set_has_list_method(HasBits* has_bits) { + (*has_bits)[0] |= 2u; + } +}; + +ListRpcRequest::ListRpcRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:taotu.ListRpcRequest) +} +ListRpcRequest::ListRpcRequest(const ListRpcRequest& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + ListRpcRequest* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){from._impl_._has_bits_} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.service_name_) {} + + , decltype(_impl_.list_method_) {} + }; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _impl_.service_name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { + _this->_impl_.service_name_.Set(from._internal_service_name(), _this->GetArenaForAllocation()); + } + _this->_impl_.list_method_ = from._impl_.list_method_; + // @@protoc_insertion_point(copy_constructor:taotu.ListRpcRequest) +} + +inline void ListRpcRequest::SharedCtor(::_pb::Arena* arena) { + (void)arena; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.service_name_) {} + + , decltype(_impl_.list_method_) { false } + + }; + _impl_.service_name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING +} + +ListRpcRequest::~ListRpcRequest() { + // @@protoc_insertion_point(destructor:taotu.ListRpcRequest) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void ListRpcRequest::SharedDtor() { + ABSL_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.service_name_.Destroy(); +} + +void ListRpcRequest::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void ListRpcRequest::Clear() { +// @@protoc_insertion_point(message_clear_start:taotu.ListRpcRequest) + ::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 & 0x00000001u) { + _impl_.service_name_.ClearNonDefaultToEmpty(); + } + _impl_.list_method_ = false; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* ListRpcRequest::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + _Internal::HasBits has_bits{}; + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // optional string service_name = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { + auto str = _internal_mutable_service_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.ListRpcRequest.service_name")); + } else { + goto handle_unusual; + } + continue; + // optional bool list_method = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { + _Internal::set_has_list_method(&has_bits); + _impl_.list_method_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + _impl_._has_bits_.Or(has_bits); + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* ListRpcRequest::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:taotu.ListRpcRequest) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _impl_._has_bits_[0]; + // optional string service_name = 1; + if (cached_has_bits & 0x00000001u) { + const std::string& _s = this->_internal_service_name(); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.ListRpcRequest.service_name"); + target = stream->WriteStringMaybeAliased(1, _s, target); + } + + // optional bool list_method = 2; + if (cached_has_bits & 0x00000002u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray( + 2, this->_internal_list_method(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:taotu.ListRpcRequest) + return target; +} + +::size_t ListRpcRequest::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:taotu.ListRpcRequest) + ::size_t total_size = 0; + + ::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) { + // optional string service_name = 1; + if (cached_has_bits & 0x00000001u) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_service_name()); + } + + // optional bool list_method = 2; + if (cached_has_bits & 0x00000002u) { + total_size += 2; + } + + } + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListRpcRequest::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + ListRpcRequest::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListRpcRequest::GetClassData() const { return &_class_data_; } + + +void ListRpcRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:taotu.ListRpcRequest) + 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_service_name(from._internal_service_name()); + } + if (cached_has_bits & 0x00000002u) { + _this->_impl_.list_method_ = from._impl_.list_method_; + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void ListRpcRequest::CopyFrom(const ListRpcRequest& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:taotu.ListRpcRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool ListRpcRequest::IsInitialized() const { + return true; +} + +void ListRpcRequest::InternalSwap(ListRpcRequest* other) { + using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.service_name_, lhs_arena, + &other->_impl_.service_name_, rhs_arena); + + swap(_impl_.list_method_, other->_impl_.list_method_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata ListRpcRequest::GetMetadata() const { + return ::_pbi::AssignDescriptors( + &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, + file_level_metadata_rpc_2eproto[1]); +} +// =================================================================== + +class ListRpcResponse::_Internal { + public: +}; + +ListRpcResponse::ListRpcResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:taotu.ListRpcResponse) +} +ListRpcResponse::ListRpcResponse(const ListRpcResponse& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + ListRpcResponse* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.service_name_){from._impl_.service_name_} + , decltype(_impl_.method_name_){from._impl_.method_name_} + , decltype(_impl_.error_) {} + + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.error_ = from._impl_.error_; + // @@protoc_insertion_point(copy_constructor:taotu.ListRpcResponse) +} + +inline void ListRpcResponse::SharedCtor(::_pb::Arena* arena) { + (void)arena; + new (&_impl_) Impl_{ + decltype(_impl_.service_name_){arena} + , decltype(_impl_.method_name_){arena} + , decltype(_impl_.error_) { 0 } + + , /*decltype(_impl_._cached_size_)*/{} + }; +} + +ListRpcResponse::~ListRpcResponse() { + // @@protoc_insertion_point(destructor:taotu.ListRpcResponse) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void ListRpcResponse::SharedDtor() { + ABSL_DCHECK(GetArenaForAllocation() == nullptr); + _internal_mutable_service_name()->~RepeatedPtrField(); + _internal_mutable_method_name()->~RepeatedPtrField(); +} + +void ListRpcResponse::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void ListRpcResponse::Clear() { +// @@protoc_insertion_point(message_clear_start:taotu.ListRpcResponse) + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _internal_mutable_service_name()->Clear(); + _internal_mutable_method_name()->Clear(); + _impl_.error_ = 0; + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* ListRpcResponse::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // .taotu.ErrorCode error = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { + ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + CHK_(ptr); + _internal_set_error(static_cast<::taotu::ErrorCode>(val)); + } else { + goto handle_unusual; + } + continue; + // repeated string service_name = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { + ptr -= 1; + do { + ptr += 1; + auto str = _internal_add_service_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.ListRpcResponse.service_name")); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); + } else { + goto handle_unusual; + } + continue; + // repeated string method_name = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { + ptr -= 1; + do { + ptr += 1; + auto str = _internal_add_method_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.ListRpcResponse.method_name")); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* ListRpcResponse::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:taotu.ListRpcResponse) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // .taotu.ErrorCode error = 1; + if (this->_internal_error() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteEnumToArray( + 1, this->_internal_error(), target); + } + + // repeated string service_name = 2; + for (int i = 0, n = this->_internal_service_name_size(); i < n; ++i) { + const auto& s = this->_internal_service_name(i); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.ListRpcResponse.service_name"); + target = stream->WriteString(2, s, target); + } + + // repeated string method_name = 3; + for (int i = 0, n = this->_internal_method_name_size(); i < n; ++i) { + const auto& s = this->_internal_method_name(i); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.ListRpcResponse.method_name"); + target = stream->WriteString(3, s, target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:taotu.ListRpcResponse) + return target; +} + +::size_t ListRpcResponse::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:taotu.ListRpcResponse) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated string service_name = 2; + total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_service_name().size()); + for (int i = 0, n = _internal_service_name().size(); i < n; ++i) { + total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + _internal_service_name().Get(i)); + } + + // repeated string method_name = 3; + total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_method_name().size()); + for (int i = 0, n = _internal_method_name().size(); i < n; ++i) { + total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + _internal_method_name().Get(i)); + } + + // .taotu.ErrorCode error = 1; + if (this->_internal_error() != 0) { + total_size += 1 + + ::_pbi::WireFormatLite::EnumSize(this->_internal_error()); + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListRpcResponse::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + ListRpcResponse::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListRpcResponse::GetClassData() const { return &_class_data_; } + + +void ListRpcResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:taotu.ListRpcResponse) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_internal_mutable_service_name()->MergeFrom(from._internal_service_name()); + _this->_internal_mutable_method_name()->MergeFrom(from._internal_method_name()); + if (from._internal_error() != 0) { + _this->_internal_set_error(from._internal_error()); + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void ListRpcResponse::CopyFrom(const ListRpcResponse& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:taotu.ListRpcResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool ListRpcResponse::IsInitialized() const { + return true; +} + +void ListRpcResponse::InternalSwap(ListRpcResponse* other) { + using std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + _internal_mutable_service_name()->InternalSwap( + other->_internal_mutable_service_name()); + _internal_mutable_method_name()->InternalSwap( + other->_internal_mutable_method_name()); + swap(_impl_.error_, other->_impl_.error_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata ListRpcResponse::GetMetadata() const { + return ::_pbi::AssignDescriptors( + &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, + file_level_metadata_rpc_2eproto[2]); +} +// =================================================================== + +class GetServiceRequest::_Internal { + public: +}; + +GetServiceRequest::GetServiceRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:taotu.GetServiceRequest) +} +GetServiceRequest::GetServiceRequest(const GetServiceRequest& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + GetServiceRequest* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.service_name_) {} + + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _impl_.service_name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (!from._internal_service_name().empty()) { + _this->_impl_.service_name_.Set(from._internal_service_name(), _this->GetArenaForAllocation()); + } + // @@protoc_insertion_point(copy_constructor:taotu.GetServiceRequest) +} + +inline void GetServiceRequest::SharedCtor(::_pb::Arena* arena) { + (void)arena; + new (&_impl_) Impl_{ + decltype(_impl_.service_name_) {} + + , /*decltype(_impl_._cached_size_)*/{} + }; + _impl_.service_name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING +} + +GetServiceRequest::~GetServiceRequest() { + // @@protoc_insertion_point(destructor:taotu.GetServiceRequest) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void GetServiceRequest::SharedDtor() { + ABSL_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.service_name_.Destroy(); +} + +void GetServiceRequest::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void GetServiceRequest::Clear() { +// @@protoc_insertion_point(message_clear_start:taotu.GetServiceRequest) + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.service_name_.ClearToEmpty(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* GetServiceRequest::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // string service_name = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { + auto str = _internal_mutable_service_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.GetServiceRequest.service_name")); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* GetServiceRequest::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:taotu.GetServiceRequest) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // string service_name = 1; + if (!this->_internal_service_name().empty()) { + const std::string& _s = this->_internal_service_name(); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.GetServiceRequest.service_name"); + target = stream->WriteStringMaybeAliased(1, _s, target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:taotu.GetServiceRequest) + return target; +} + +::size_t GetServiceRequest::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:taotu.GetServiceRequest) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // string service_name = 1; + if (!this->_internal_service_name().empty()) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_service_name()); + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GetServiceRequest::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + GetServiceRequest::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetServiceRequest::GetClassData() const { return &_class_data_; } + + +void GetServiceRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:taotu.GetServiceRequest) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + if (!from._internal_service_name().empty()) { + _this->_internal_set_service_name(from._internal_service_name()); + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void GetServiceRequest::CopyFrom(const GetServiceRequest& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:taotu.GetServiceRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool GetServiceRequest::IsInitialized() const { + return true; +} + +void GetServiceRequest::InternalSwap(GetServiceRequest* other) { + using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.service_name_, lhs_arena, + &other->_impl_.service_name_, rhs_arena); +} + +::PROTOBUF_NAMESPACE_ID::Metadata GetServiceRequest::GetMetadata() const { + return ::_pbi::AssignDescriptors( + &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, + file_level_metadata_rpc_2eproto[3]); +} +// =================================================================== + +class GetServiceResponse::_Internal { + public: +}; + +GetServiceResponse::GetServiceResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:taotu.GetServiceResponse) +} +GetServiceResponse::GetServiceResponse(const GetServiceResponse& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + GetServiceResponse* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.proto_file_){from._impl_.proto_file_} + , decltype(_impl_.proto_file_name_){from._impl_.proto_file_name_} + , decltype(_impl_.error_) {} + + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.error_ = from._impl_.error_; + // @@protoc_insertion_point(copy_constructor:taotu.GetServiceResponse) +} + +inline void GetServiceResponse::SharedCtor(::_pb::Arena* arena) { + (void)arena; + new (&_impl_) Impl_{ + decltype(_impl_.proto_file_){arena} + , decltype(_impl_.proto_file_name_){arena} + , decltype(_impl_.error_) { 0 } + + , /*decltype(_impl_._cached_size_)*/{} + }; +} + +GetServiceResponse::~GetServiceResponse() { + // @@protoc_insertion_point(destructor:taotu.GetServiceResponse) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void GetServiceResponse::SharedDtor() { + ABSL_DCHECK(GetArenaForAllocation() == nullptr); + _internal_mutable_proto_file()->~RepeatedPtrField(); + _internal_mutable_proto_file_name()->~RepeatedPtrField(); +} + +void GetServiceResponse::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void GetServiceResponse::Clear() { +// @@protoc_insertion_point(message_clear_start:taotu.GetServiceResponse) + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _internal_mutable_proto_file()->Clear(); + _internal_mutable_proto_file_name()->Clear(); + _impl_.error_ = 0; + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* GetServiceResponse::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // .taotu.ErrorCode error = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { + ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + CHK_(ptr); + _internal_set_error(static_cast<::taotu::ErrorCode>(val)); + } else { + goto handle_unusual; + } + continue; + // repeated string proto_file = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { + ptr -= 1; + do { + ptr += 1; + auto str = _internal_add_proto_file(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.GetServiceResponse.proto_file")); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); + } else { + goto handle_unusual; + } + continue; + // repeated string proto_file_name = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { + ptr -= 1; + do { + ptr += 1; + auto str = _internal_add_proto_file_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, "taotu.GetServiceResponse.proto_file_name")); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* GetServiceResponse::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:taotu.GetServiceResponse) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // .taotu.ErrorCode error = 1; + if (this->_internal_error() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteEnumToArray( + 1, this->_internal_error(), target); + } + + // repeated string proto_file = 2; + for (int i = 0, n = this->_internal_proto_file_size(); i < n; ++i) { + const auto& s = this->_internal_proto_file(i); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.GetServiceResponse.proto_file"); + target = stream->WriteString(2, s, target); + } + + // repeated string proto_file_name = 3; + for (int i = 0, n = this->_internal_proto_file_name_size(); i < n; ++i) { + const auto& s = this->_internal_proto_file_name(i); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.GetServiceResponse.proto_file_name"); + target = stream->WriteString(3, s, target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:taotu.GetServiceResponse) + return target; +} + +::size_t GetServiceResponse::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:taotu.GetServiceResponse) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated string proto_file = 2; + total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_proto_file().size()); + for (int i = 0, n = _internal_proto_file().size(); i < n; ++i) { + total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + _internal_proto_file().Get(i)); + } + + // repeated string proto_file_name = 3; + total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_proto_file_name().size()); + for (int i = 0, n = _internal_proto_file_name().size(); i < n; ++i) { + total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + _internal_proto_file_name().Get(i)); + } + + // .taotu.ErrorCode error = 1; + if (this->_internal_error() != 0) { + total_size += 1 + + ::_pbi::WireFormatLite::EnumSize(this->_internal_error()); + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GetServiceResponse::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + GetServiceResponse::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetServiceResponse::GetClassData() const { return &_class_data_; } + + +void GetServiceResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:taotu.GetServiceResponse) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_internal_mutable_proto_file()->MergeFrom(from._internal_proto_file()); + _this->_internal_mutable_proto_file_name()->MergeFrom(from._internal_proto_file_name()); + if (from._internal_error() != 0) { + _this->_internal_set_error(from._internal_error()); + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void GetServiceResponse::CopyFrom(const GetServiceResponse& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:taotu.GetServiceResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool GetServiceResponse::IsInitialized() const { + return true; +} + +void GetServiceResponse::InternalSwap(GetServiceResponse* other) { + using std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + _internal_mutable_proto_file()->InternalSwap( + other->_internal_mutable_proto_file()); + _internal_mutable_proto_file_name()->InternalSwap( + other->_internal_mutable_proto_file_name()); + swap(_impl_.error_, other->_impl_.error_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata GetServiceResponse::GetMetadata() const { + return ::_pbi::AssignDescriptors( + &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, + file_level_metadata_rpc_2eproto[4]); +} +// =================================================================== + +const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* RpcService::descriptor() { + ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rpc_2eproto); + return file_level_service_descriptors_rpc_2eproto[0]; +} + +const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* RpcService::GetDescriptor() { + return descriptor(); +} + +void RpcService::ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::ListRpcRequest*, ::taotu::ListRpcResponse*, ::google::protobuf::Closure* done) { + controller->SetFailed("Method ListRpc() not implemented."); + done->Run(); +} +void RpcService::GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::GetServiceRequest*, ::taotu::GetServiceResponse*, ::google::protobuf::Closure* done) { + controller->SetFailed("Method GetService() not implemented."); + done->Run(); +} + +void RpcService::CallMethod( + const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method, + ::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::PROTOBUF_NAMESPACE_ID::Message* request, + ::PROTOBUF_NAMESPACE_ID::Message* response, ::google::protobuf::Closure* done) { + ABSL_DCHECK_EQ(method->service(), file_level_service_descriptors_rpc_2eproto[0]); + switch (method->index()) { + case 0: + ListRpc(controller, + ::PROTOBUF_NAMESPACE_ID::internal::DownCast(request), + ::PROTOBUF_NAMESPACE_ID::internal::DownCast<::taotu::ListRpcResponse*>(response), done); + break; + case 1: + GetService(controller, + ::PROTOBUF_NAMESPACE_ID::internal::DownCast(request), + ::PROTOBUF_NAMESPACE_ID::internal::DownCast<::taotu::GetServiceResponse*>(response), done); + break; + + default: + ABSL_LOG(FATAL) << "Bad method index; this should never happen."; + break; + } +} + +const ::PROTOBUF_NAMESPACE_ID::Message& RpcService::GetRequestPrototype( + const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const { + ABSL_DCHECK_EQ(method->service(), descriptor()); + switch (method->index()) { + case 0: + return ::taotu::ListRpcRequest::default_instance(); + case 1: + return ::taotu::GetServiceRequest::default_instance(); + + default: + ABSL_LOG(FATAL) << "Bad method index; this should never happen."; + return *::PROTOBUF_NAMESPACE_ID::MessageFactory::generated_factory() + ->GetPrototype(method->input_type()); + } +} + +const ::PROTOBUF_NAMESPACE_ID::Message& RpcService::GetResponsePrototype( + const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const { + ABSL_DCHECK_EQ(method->service(), descriptor()); + switch (method->index()) { + case 0: + return ::taotu::ListRpcResponse::default_instance(); + case 1: + return ::taotu::GetServiceResponse::default_instance(); + + default: + ABSL_LOG(FATAL) << "Bad method index; this should never happen."; + return *::PROTOBUF_NAMESPACE_ID::MessageFactory::generated_factory() + ->GetPrototype(method->output_type()); + } +} + +RpcService_Stub::RpcService_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel) + : channel_(channel), owns_channel_(false) {} + +RpcService_Stub::RpcService_Stub( + ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, + ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership) + : channel_(channel), + owns_channel_(ownership == + ::PROTOBUF_NAMESPACE_ID::Service::STUB_OWNS_CHANNEL) {} + +RpcService_Stub::~RpcService_Stub() { + if (owns_channel_) delete channel_; +} + +void RpcService_Stub::ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::ListRpcRequest* request, + ::taotu::ListRpcResponse* response, ::google::protobuf::Closure* done) { + channel_->CallMethod(descriptor()->method(0), controller, + request, response, done); +} +void RpcService_Stub::GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::GetServiceRequest* request, + ::taotu::GetServiceResponse* response, ::google::protobuf::Closure* done) { + channel_->CallMethod(descriptor()->method(1), controller, + request, response, done); +} +// @@protoc_insertion_point(namespace_scope) +} // namespace taotu +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_NOINLINE ::taotu::RpcMessage* +Arena::CreateMaybeMessage< ::taotu::RpcMessage >(Arena* arena) { + return Arena::CreateMessageInternal< ::taotu::RpcMessage >(arena); +} +template<> PROTOBUF_NOINLINE ::taotu::ListRpcRequest* +Arena::CreateMaybeMessage< ::taotu::ListRpcRequest >(Arena* arena) { + return Arena::CreateMessageInternal< ::taotu::ListRpcRequest >(arena); +} +template<> PROTOBUF_NOINLINE ::taotu::ListRpcResponse* +Arena::CreateMaybeMessage< ::taotu::ListRpcResponse >(Arena* arena) { + return Arena::CreateMessageInternal< ::taotu::ListRpcResponse >(arena); +} +template<> PROTOBUF_NOINLINE ::taotu::GetServiceRequest* +Arena::CreateMaybeMessage< ::taotu::GetServiceRequest >(Arena* arena) { + return Arena::CreateMessageInternal< ::taotu::GetServiceRequest >(arena); +} +template<> PROTOBUF_NOINLINE ::taotu::GetServiceResponse* +Arena::CreateMaybeMessage< ::taotu::GetServiceResponse >(Arena* arena) { + return Arena::CreateMessageInternal< ::taotu::GetServiceResponse >(arena); +} +PROTOBUF_NAMESPACE_CLOSE +// @@protoc_insertion_point(global_scope) +#include "google/protobuf/port_undef.inc" diff --git a/src/rpc.pb.h b/src/rpc.pb.h new file mode 100644 index 00000000..92300597 --- /dev/null +++ b/src/rpc.pb.h @@ -0,0 +1,2224 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: rpc.proto + +#ifndef GOOGLE_PROTOBUF_INCLUDED_rpc_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_rpc_2eproto_2epb_2eh + +#include +#include +#include + +#include "google/protobuf/port_def.inc" +#if PROTOBUF_VERSION < 4023000 +#error "This file was generated by a newer version of protoc which is" +#error "incompatible with your Protocol Buffer headers. Please update" +#error "your headers." +#endif // PROTOBUF_VERSION + +#if 4023001 < PROTOBUF_MIN_PROTOC_VERSION +#error "This file was generated by an older version of protoc which is" +#error "incompatible with your Protocol Buffer headers. Please" +#error "regenerate this file with a newer version of protoc." +#endif // PROTOBUF_MIN_PROTOC_VERSION +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/service.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_rpc_2eproto + +PROTOBUF_NAMESPACE_OPEN +namespace internal { +class AnyMetadata; +} // namespace internal +PROTOBUF_NAMESPACE_CLOSE + +// Internal implementation detail -- do not use these members. +struct TableStruct_rpc_2eproto { + static const ::uint32_t offsets[]; +}; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable + descriptor_table_rpc_2eproto; +namespace taotu { +class GetServiceRequest; +struct GetServiceRequestDefaultTypeInternal; +extern GetServiceRequestDefaultTypeInternal _GetServiceRequest_default_instance_; +class GetServiceResponse; +struct GetServiceResponseDefaultTypeInternal; +extern GetServiceResponseDefaultTypeInternal _GetServiceResponse_default_instance_; +class ListRpcRequest; +struct ListRpcRequestDefaultTypeInternal; +extern ListRpcRequestDefaultTypeInternal _ListRpcRequest_default_instance_; +class ListRpcResponse; +struct ListRpcResponseDefaultTypeInternal; +extern ListRpcResponseDefaultTypeInternal _ListRpcResponse_default_instance_; +class RpcMessage; +struct RpcMessageDefaultTypeInternal; +extern RpcMessageDefaultTypeInternal _RpcMessage_default_instance_; +} // namespace taotu +PROTOBUF_NAMESPACE_OPEN +template <> +::taotu::GetServiceRequest* Arena::CreateMaybeMessage<::taotu::GetServiceRequest>(Arena*); +template <> +::taotu::GetServiceResponse* Arena::CreateMaybeMessage<::taotu::GetServiceResponse>(Arena*); +template <> +::taotu::ListRpcRequest* Arena::CreateMaybeMessage<::taotu::ListRpcRequest>(Arena*); +template <> +::taotu::ListRpcResponse* Arena::CreateMaybeMessage<::taotu::ListRpcResponse>(Arena*); +template <> +::taotu::RpcMessage* Arena::CreateMaybeMessage<::taotu::RpcMessage>(Arena*); +PROTOBUF_NAMESPACE_CLOSE + +namespace taotu { +enum MessageType : int { + OTHER = 0, + REQUEST = 1, + RESPONSE = 2, + ERROR = 3, + MessageType_INT_MIN_SENTINEL_DO_NOT_USE_ = + std::numeric_limits<::int32_t>::min(), + MessageType_INT_MAX_SENTINEL_DO_NOT_USE_ = + std::numeric_limits<::int32_t>::max(), +}; + +bool MessageType_IsValid(int value); +constexpr MessageType MessageType_MIN = static_cast(0); +constexpr MessageType MessageType_MAX = static_cast(3); +constexpr int MessageType_ARRAYSIZE = 3 + 1; +const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* +MessageType_descriptor(); +template +const std::string& MessageType_Name(T value) { + static_assert(std::is_same::value || + std::is_integral::value, + "Incorrect type passed to MessageType_Name()."); + return MessageType_Name(static_cast(value)); +} +template <> +inline const std::string& MessageType_Name(MessageType value) { + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( + static_cast(value)); +} +inline bool MessageType_Parse(absl::string_view name, MessageType* value) { + return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( + MessageType_descriptor(), name, value); +} +enum ErrorCode : int { + NO_ERROR = 0, + WRONG_PROTO = 1, + NO_SERVICE = 2, + NO_METHOD = 3, + INVALID_REQUEST = 4, + INVALID_RESPONSE = 5, + TIMEOUT = 6, + ErrorCode_INT_MIN_SENTINEL_DO_NOT_USE_ = + std::numeric_limits<::int32_t>::min(), + ErrorCode_INT_MAX_SENTINEL_DO_NOT_USE_ = + std::numeric_limits<::int32_t>::max(), +}; + +bool ErrorCode_IsValid(int value); +constexpr ErrorCode ErrorCode_MIN = static_cast(0); +constexpr ErrorCode ErrorCode_MAX = static_cast(6); +constexpr int ErrorCode_ARRAYSIZE = 6 + 1; +const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* +ErrorCode_descriptor(); +template +const std::string& ErrorCode_Name(T value) { + static_assert(std::is_same::value || + std::is_integral::value, + "Incorrect type passed to ErrorCode_Name()."); + return ErrorCode_Name(static_cast(value)); +} +template <> +inline const std::string& ErrorCode_Name(ErrorCode value) { + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( + static_cast(value)); +} +inline bool ErrorCode_Parse(absl::string_view name, ErrorCode* value) { + return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( + ErrorCode_descriptor(), name, value); +} + +// =================================================================== + + +// ------------------------------------------------------------------- + +class RpcMessage final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.RpcMessage) */ { + public: + inline RpcMessage() : RpcMessage(nullptr) {} + ~RpcMessage() override; + template + explicit PROTOBUF_CONSTEXPR RpcMessage(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + RpcMessage(const RpcMessage& from); + RpcMessage(RpcMessage&& from) noexcept + : RpcMessage() { + *this = ::std::move(from); + } + + inline RpcMessage& operator=(const RpcMessage& from) { + CopyFrom(from); + return *this; + } + inline RpcMessage& operator=(RpcMessage&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const RpcMessage& default_instance() { + return *internal_default_instance(); + } + static inline const RpcMessage* internal_default_instance() { + return reinterpret_cast( + &_RpcMessage_default_instance_); + } + static constexpr int kIndexInFileMessages = + 0; + + friend void swap(RpcMessage& a, RpcMessage& b) { + a.Swap(&b); + } + inline void Swap(RpcMessage* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(RpcMessage* other) { + if (other == this) return; + ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + RpcMessage* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const RpcMessage& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const RpcMessage& from) { + RpcMessage::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(RpcMessage* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "taotu.RpcMessage"; + } + protected: + explicit RpcMessage(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kServiceFieldNumber = 3, + kMethodFieldNumber = 4, + kRequestFieldNumber = 5, + kResponseFieldNumber = 6, + kIdFieldNumber = 2, + kTypeFieldNumber = 1, + kErrorFieldNumber = 7, + }; + // optional string service = 3; + bool has_service() const; + void clear_service() ; + const std::string& service() const; + + + + + template + void set_service(Arg_&& arg, Args_... args); + std::string* mutable_service(); + PROTOBUF_NODISCARD std::string* release_service(); + void set_allocated_service(std::string* ptr); + + private: + const std::string& _internal_service() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_service( + const std::string& value); + std::string* _internal_mutable_service(); + + public: + // optional string method = 4; + bool has_method() const; + void clear_method() ; + const std::string& method() const; + + + + + template + void set_method(Arg_&& arg, Args_... args); + std::string* mutable_method(); + PROTOBUF_NODISCARD std::string* release_method(); + void set_allocated_method(std::string* ptr); + + private: + const std::string& _internal_method() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_method( + const std::string& value); + std::string* _internal_mutable_method(); + + public: + // optional bytes request = 5; + bool has_request() const; + void clear_request() ; + const std::string& request() const; + + + + + template + void set_request(Arg_&& arg, Args_... args); + std::string* mutable_request(); + PROTOBUF_NODISCARD std::string* release_request(); + void set_allocated_request(std::string* ptr); + + private: + const std::string& _internal_request() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_request( + const std::string& value); + std::string* _internal_mutable_request(); + + public: + // optional bytes response = 6; + bool has_response() const; + void clear_response() ; + const std::string& response() const; + + + + + template + void set_response(Arg_&& arg, Args_... args); + std::string* mutable_response(); + PROTOBUF_NODISCARD std::string* release_response(); + void set_allocated_response(std::string* ptr); + + private: + const std::string& _internal_response() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_response( + const std::string& value); + std::string* _internal_mutable_response(); + + public: + // fixed64 id = 2; + void clear_id() ; + ::uint64_t id() const; + void set_id(::uint64_t value); + + private: + ::uint64_t _internal_id() const; + void _internal_set_id(::uint64_t value); + + public: + // .taotu.MessageType type = 1; + void clear_type() ; + ::taotu::MessageType type() const; + void set_type(::taotu::MessageType value); + + private: + ::taotu::MessageType _internal_type() const; + void _internal_set_type(::taotu::MessageType value); + + public: + // optional .taotu.ErrorCode error = 7; + bool has_error() const; + void clear_error() ; + ::taotu::ErrorCode error() const; + void set_error(::taotu::ErrorCode value); + + private: + ::taotu::ErrorCode _internal_error() const; + void _internal_set_error(::taotu::ErrorCode value); + + public: + // @@protoc_insertion_point(class_scope:taotu.RpcMessage) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr method_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr response_; + ::uint64_t id_; + int type_; + int error_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_rpc_2eproto; +};// ------------------------------------------------------------------- + +class ListRpcRequest final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.ListRpcRequest) */ { + public: + inline ListRpcRequest() : ListRpcRequest(nullptr) {} + ~ListRpcRequest() override; + template + explicit PROTOBUF_CONSTEXPR ListRpcRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + ListRpcRequest(const ListRpcRequest& from); + ListRpcRequest(ListRpcRequest&& from) noexcept + : ListRpcRequest() { + *this = ::std::move(from); + } + + inline ListRpcRequest& operator=(const ListRpcRequest& from) { + CopyFrom(from); + return *this; + } + inline ListRpcRequest& operator=(ListRpcRequest&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const ListRpcRequest& default_instance() { + return *internal_default_instance(); + } + static inline const ListRpcRequest* internal_default_instance() { + return reinterpret_cast( + &_ListRpcRequest_default_instance_); + } + static constexpr int kIndexInFileMessages = + 1; + + friend void swap(ListRpcRequest& a, ListRpcRequest& b) { + a.Swap(&b); + } + inline void Swap(ListRpcRequest* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ListRpcRequest* other) { + if (other == this) return; + ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + ListRpcRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const ListRpcRequest& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const ListRpcRequest& from) { + ListRpcRequest::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(ListRpcRequest* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "taotu.ListRpcRequest"; + } + protected: + explicit ListRpcRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kServiceNameFieldNumber = 1, + kListMethodFieldNumber = 2, + }; + // optional string service_name = 1; + bool has_service_name() const; + void clear_service_name() ; + const std::string& service_name() const; + + + + + template + void set_service_name(Arg_&& arg, Args_... args); + std::string* mutable_service_name(); + PROTOBUF_NODISCARD std::string* release_service_name(); + void set_allocated_service_name(std::string* ptr); + + private: + const std::string& _internal_service_name() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_service_name( + const std::string& value); + std::string* _internal_mutable_service_name(); + + public: + // optional bool list_method = 2; + bool has_list_method() const; + void clear_list_method() ; + bool list_method() const; + void set_list_method(bool value); + + private: + bool _internal_list_method() const; + void _internal_set_list_method(bool value); + + public: + // @@protoc_insertion_point(class_scope:taotu.ListRpcRequest) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_name_; + bool list_method_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_rpc_2eproto; +};// ------------------------------------------------------------------- + +class ListRpcResponse final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.ListRpcResponse) */ { + public: + inline ListRpcResponse() : ListRpcResponse(nullptr) {} + ~ListRpcResponse() override; + template + explicit PROTOBUF_CONSTEXPR ListRpcResponse(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + ListRpcResponse(const ListRpcResponse& from); + ListRpcResponse(ListRpcResponse&& from) noexcept + : ListRpcResponse() { + *this = ::std::move(from); + } + + inline ListRpcResponse& operator=(const ListRpcResponse& from) { + CopyFrom(from); + return *this; + } + inline ListRpcResponse& operator=(ListRpcResponse&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const ListRpcResponse& default_instance() { + return *internal_default_instance(); + } + static inline const ListRpcResponse* internal_default_instance() { + return reinterpret_cast( + &_ListRpcResponse_default_instance_); + } + static constexpr int kIndexInFileMessages = + 2; + + friend void swap(ListRpcResponse& a, ListRpcResponse& b) { + a.Swap(&b); + } + inline void Swap(ListRpcResponse* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ListRpcResponse* other) { + if (other == this) return; + ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + ListRpcResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const ListRpcResponse& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const ListRpcResponse& from) { + ListRpcResponse::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(ListRpcResponse* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "taotu.ListRpcResponse"; + } + protected: + explicit ListRpcResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kServiceNameFieldNumber = 2, + kMethodNameFieldNumber = 3, + kErrorFieldNumber = 1, + }; + // repeated string service_name = 2; + int service_name_size() const; + private: + int _internal_service_name_size() const; + + public: + void clear_service_name() ; + const std::string& service_name(int index) const; + std::string* mutable_service_name(int index); + void set_service_name(int index, const std::string& value); + void set_service_name(int index, std::string&& value); + void set_service_name(int index, const char* value); + void set_service_name(int index, const char* value, std::size_t size); + void set_service_name(int index, absl::string_view value); + std::string* add_service_name(); + void add_service_name(const std::string& value); + void add_service_name(std::string&& value); + void add_service_name(const char* value); + void add_service_name(const char* value, std::size_t size); + void add_service_name(absl::string_view value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& service_name() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_service_name(); + + private: + const std::string& _internal_service_name(int index) const; + std::string* _internal_add_service_name(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_service_name() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_service_name(); + + public: + // repeated string method_name = 3; + int method_name_size() const; + private: + int _internal_method_name_size() const; + + public: + void clear_method_name() ; + const std::string& method_name(int index) const; + std::string* mutable_method_name(int index); + void set_method_name(int index, const std::string& value); + void set_method_name(int index, std::string&& value); + void set_method_name(int index, const char* value); + void set_method_name(int index, const char* value, std::size_t size); + void set_method_name(int index, absl::string_view value); + std::string* add_method_name(); + void add_method_name(const std::string& value); + void add_method_name(std::string&& value); + void add_method_name(const char* value); + void add_method_name(const char* value, std::size_t size); + void add_method_name(absl::string_view value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& method_name() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_method_name(); + + private: + const std::string& _internal_method_name(int index) const; + std::string* _internal_add_method_name(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_method_name() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_method_name(); + + public: + // .taotu.ErrorCode error = 1; + void clear_error() ; + ::taotu::ErrorCode error() const; + void set_error(::taotu::ErrorCode value); + + private: + ::taotu::ErrorCode _internal_error() const; + void _internal_set_error(::taotu::ErrorCode value); + + public: + // @@protoc_insertion_point(class_scope:taotu.ListRpcResponse) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField service_name_; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField method_name_; + int error_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_rpc_2eproto; +};// ------------------------------------------------------------------- + +class GetServiceRequest final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.GetServiceRequest) */ { + public: + inline GetServiceRequest() : GetServiceRequest(nullptr) {} + ~GetServiceRequest() override; + template + explicit PROTOBUF_CONSTEXPR GetServiceRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + GetServiceRequest(const GetServiceRequest& from); + GetServiceRequest(GetServiceRequest&& from) noexcept + : GetServiceRequest() { + *this = ::std::move(from); + } + + inline GetServiceRequest& operator=(const GetServiceRequest& from) { + CopyFrom(from); + return *this; + } + inline GetServiceRequest& operator=(GetServiceRequest&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const GetServiceRequest& default_instance() { + return *internal_default_instance(); + } + static inline const GetServiceRequest* internal_default_instance() { + return reinterpret_cast( + &_GetServiceRequest_default_instance_); + } + static constexpr int kIndexInFileMessages = + 3; + + friend void swap(GetServiceRequest& a, GetServiceRequest& b) { + a.Swap(&b); + } + inline void Swap(GetServiceRequest* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(GetServiceRequest* other) { + if (other == this) return; + ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + GetServiceRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const GetServiceRequest& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const GetServiceRequest& from) { + GetServiceRequest::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(GetServiceRequest* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "taotu.GetServiceRequest"; + } + protected: + explicit GetServiceRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kServiceNameFieldNumber = 1, + }; + // string service_name = 1; + void clear_service_name() ; + const std::string& service_name() const; + + + + + template + void set_service_name(Arg_&& arg, Args_... args); + std::string* mutable_service_name(); + PROTOBUF_NODISCARD std::string* release_service_name(); + void set_allocated_service_name(std::string* ptr); + + private: + const std::string& _internal_service_name() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_service_name( + const std::string& value); + std::string* _internal_mutable_service_name(); + + public: + // @@protoc_insertion_point(class_scope:taotu.GetServiceRequest) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_name_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_rpc_2eproto; +};// ------------------------------------------------------------------- + +class GetServiceResponse final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.GetServiceResponse) */ { + public: + inline GetServiceResponse() : GetServiceResponse(nullptr) {} + ~GetServiceResponse() override; + template + explicit PROTOBUF_CONSTEXPR GetServiceResponse(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + GetServiceResponse(const GetServiceResponse& from); + GetServiceResponse(GetServiceResponse&& from) noexcept + : GetServiceResponse() { + *this = ::std::move(from); + } + + inline GetServiceResponse& operator=(const GetServiceResponse& from) { + CopyFrom(from); + return *this; + } + inline GetServiceResponse& operator=(GetServiceResponse&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const GetServiceResponse& default_instance() { + return *internal_default_instance(); + } + static inline const GetServiceResponse* internal_default_instance() { + return reinterpret_cast( + &_GetServiceResponse_default_instance_); + } + static constexpr int kIndexInFileMessages = + 4; + + friend void swap(GetServiceResponse& a, GetServiceResponse& b) { + a.Swap(&b); + } + inline void Swap(GetServiceResponse* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(GetServiceResponse* other) { + if (other == this) return; + ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + GetServiceResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const GetServiceResponse& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const GetServiceResponse& from) { + GetServiceResponse::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(GetServiceResponse* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "taotu.GetServiceResponse"; + } + protected: + explicit GetServiceResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kProtoFileFieldNumber = 2, + kProtoFileNameFieldNumber = 3, + kErrorFieldNumber = 1, + }; + // repeated string proto_file = 2; + int proto_file_size() const; + private: + int _internal_proto_file_size() const; + + public: + void clear_proto_file() ; + const std::string& proto_file(int index) const; + std::string* mutable_proto_file(int index); + void set_proto_file(int index, const std::string& value); + void set_proto_file(int index, std::string&& value); + void set_proto_file(int index, const char* value); + void set_proto_file(int index, const char* value, std::size_t size); + void set_proto_file(int index, absl::string_view value); + std::string* add_proto_file(); + void add_proto_file(const std::string& value); + void add_proto_file(std::string&& value); + void add_proto_file(const char* value); + void add_proto_file(const char* value, std::size_t size); + void add_proto_file(absl::string_view value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& proto_file() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_proto_file(); + + private: + const std::string& _internal_proto_file(int index) const; + std::string* _internal_add_proto_file(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_proto_file() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_proto_file(); + + public: + // repeated string proto_file_name = 3; + int proto_file_name_size() const; + private: + int _internal_proto_file_name_size() const; + + public: + void clear_proto_file_name() ; + const std::string& proto_file_name(int index) const; + std::string* mutable_proto_file_name(int index); + void set_proto_file_name(int index, const std::string& value); + void set_proto_file_name(int index, std::string&& value); + void set_proto_file_name(int index, const char* value); + void set_proto_file_name(int index, const char* value, std::size_t size); + void set_proto_file_name(int index, absl::string_view value); + std::string* add_proto_file_name(); + void add_proto_file_name(const std::string& value); + void add_proto_file_name(std::string&& value); + void add_proto_file_name(const char* value); + void add_proto_file_name(const char* value, std::size_t size); + void add_proto_file_name(absl::string_view value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& proto_file_name() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_proto_file_name(); + + private: + const std::string& _internal_proto_file_name(int index) const; + std::string* _internal_add_proto_file_name(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_proto_file_name() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_proto_file_name(); + + public: + // .taotu.ErrorCode error = 1; + void clear_error() ; + ::taotu::ErrorCode error() const; + void set_error(::taotu::ErrorCode value); + + private: + ::taotu::ErrorCode _internal_error() const; + void _internal_set_error(::taotu::ErrorCode value); + + public: + // @@protoc_insertion_point(class_scope:taotu.GetServiceResponse) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField proto_file_; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField proto_file_name_; + int error_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_rpc_2eproto; +}; + +// =================================================================== + + +// ------------------------------------------------------------------- + +class RpcService_Stub; +class RpcService : public ::PROTOBUF_NAMESPACE_ID::Service { + protected: + RpcService() = default; + + public: + using Stub = RpcService_Stub; + + RpcService(const RpcService&) = delete; + RpcService& operator=(const RpcService&) = delete; + virtual ~RpcService() = default; + + static const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* descriptor(); + + virtual void ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::ListRpcRequest* request, + ::taotu::ListRpcResponse* response, + ::google::protobuf::Closure* done); + virtual void GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::GetServiceRequest* request, + ::taotu::GetServiceResponse* response, + ::google::protobuf::Closure* done); + + // implements Service ---------------------------------------------- + const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* GetDescriptor() override; + + void CallMethod(const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method, + ::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::PROTOBUF_NAMESPACE_ID::Message* request, + ::PROTOBUF_NAMESPACE_ID::Message* response, + ::google::protobuf::Closure* done) override; + + const ::PROTOBUF_NAMESPACE_ID::Message& GetRequestPrototype( + const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const override; + + const ::PROTOBUF_NAMESPACE_ID::Message& GetResponsePrototype( + const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const override; +}; + +class RpcService_Stub final : public RpcService { + public: + RpcService_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel); + RpcService_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, + ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership); + + RpcService_Stub(const RpcService_Stub&) = delete; + RpcService_Stub& operator=(const RpcService_Stub&) = delete; + + ~RpcService_Stub() override; + + inline ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel() { return channel_; } + + // implements RpcService ------------------------------------------ + void ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::ListRpcRequest* request, + ::taotu::ListRpcResponse* response, + ::google::protobuf::Closure* done) override; + void GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, + const ::taotu::GetServiceRequest* request, + ::taotu::GetServiceResponse* response, + ::google::protobuf::Closure* done) override; + + private: + ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel_; + bool owns_channel_; +}; +// =================================================================== + + + +// =================================================================== + + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// RpcMessage + +// .taotu.MessageType type = 1; +inline void RpcMessage::clear_type() { + _impl_.type_ = 0; +} +inline ::taotu::MessageType RpcMessage::type() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.type) + return _internal_type(); +} +inline void RpcMessage::set_type(::taotu::MessageType value) { + _internal_set_type(value); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.type) +} +inline ::taotu::MessageType RpcMessage::_internal_type() const { + return static_cast<::taotu::MessageType>(_impl_.type_); +} +inline void RpcMessage::_internal_set_type(::taotu::MessageType value) { + ; + _impl_.type_ = value; +} + +// fixed64 id = 2; +inline void RpcMessage::clear_id() { + _impl_.id_ = ::uint64_t{0u}; +} +inline ::uint64_t RpcMessage::id() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.id) + return _internal_id(); +} +inline void RpcMessage::set_id(::uint64_t value) { + _internal_set_id(value); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.id) +} +inline ::uint64_t RpcMessage::_internal_id() const { + return _impl_.id_; +} +inline void RpcMessage::_internal_set_id(::uint64_t value) { + ; + _impl_.id_ = value; +} + +// optional string service = 3; +inline bool RpcMessage::has_service() const { + bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline void RpcMessage::clear_service() { + _impl_.service_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000001u; +} +inline const std::string& RpcMessage::service() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.service) + return _internal_service(); +} +template +inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_service(Arg_&& arg, + Args_... args) { + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.service_.Set(static_cast(arg), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.service) +} +inline std::string* RpcMessage::mutable_service() { + std::string* _s = _internal_mutable_service(); + // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.service) + return _s; +} +inline const std::string& RpcMessage::_internal_service() const { + return _impl_.service_.Get(); +} +inline void RpcMessage::_internal_set_service(const std::string& value) { + _impl_._has_bits_[0] |= 0x00000001u; + + + _impl_.service_.Set(value, GetArenaForAllocation()); +} +inline std::string* RpcMessage::_internal_mutable_service() { + _impl_._has_bits_[0] |= 0x00000001u; + return _impl_.service_.Mutable( GetArenaForAllocation()); +} +inline std::string* RpcMessage::release_service() { + // @@protoc_insertion_point(field_release:taotu.RpcMessage.service) + if ((_impl_._has_bits_[0] & 0x00000001u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000001u; + auto* released = _impl_.service_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void RpcMessage::set_allocated_service(std::string* value) { + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000001u; + } else { + _impl_._has_bits_[0] &= ~0x00000001u; + } + _impl_.service_.SetAllocated(value, GetArenaForAllocation()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.service_.IsDefault()) { + _impl_.service_.Set("", GetArenaForAllocation()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.service) +} + +// optional string method = 4; +inline bool RpcMessage::has_method() const { + bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; + return value; +} +inline void RpcMessage::clear_method() { + _impl_.method_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000002u; +} +inline const std::string& RpcMessage::method() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.method) + return _internal_method(); +} +template +inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_method(Arg_&& arg, + Args_... args) { + _impl_._has_bits_[0] |= 0x00000002u; + _impl_.method_.Set(static_cast(arg), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.method) +} +inline std::string* RpcMessage::mutable_method() { + std::string* _s = _internal_mutable_method(); + // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.method) + return _s; +} +inline const std::string& RpcMessage::_internal_method() const { + return _impl_.method_.Get(); +} +inline void RpcMessage::_internal_set_method(const std::string& value) { + _impl_._has_bits_[0] |= 0x00000002u; + + + _impl_.method_.Set(value, GetArenaForAllocation()); +} +inline std::string* RpcMessage::_internal_mutable_method() { + _impl_._has_bits_[0] |= 0x00000002u; + return _impl_.method_.Mutable( GetArenaForAllocation()); +} +inline std::string* RpcMessage::release_method() { + // @@protoc_insertion_point(field_release:taotu.RpcMessage.method) + if ((_impl_._has_bits_[0] & 0x00000002u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000002u; + auto* released = _impl_.method_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.method_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void RpcMessage::set_allocated_method(std::string* value) { + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000002u; + } else { + _impl_._has_bits_[0] &= ~0x00000002u; + } + _impl_.method_.SetAllocated(value, GetArenaForAllocation()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.method_.IsDefault()) { + _impl_.method_.Set("", GetArenaForAllocation()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.method) +} + +// optional bytes request = 5; +inline bool RpcMessage::has_request() const { + bool value = (_impl_._has_bits_[0] & 0x00000004u) != 0; + return value; +} +inline void RpcMessage::clear_request() { + _impl_.request_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000004u; +} +inline const std::string& RpcMessage::request() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.request) + return _internal_request(); +} +template +inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_request(Arg_&& arg, + Args_... args) { + _impl_._has_bits_[0] |= 0x00000004u; + _impl_.request_.SetBytes(static_cast(arg), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.request) +} +inline std::string* RpcMessage::mutable_request() { + std::string* _s = _internal_mutable_request(); + // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.request) + return _s; +} +inline const std::string& RpcMessage::_internal_request() const { + return _impl_.request_.Get(); +} +inline void RpcMessage::_internal_set_request(const std::string& value) { + _impl_._has_bits_[0] |= 0x00000004u; + + + _impl_.request_.Set(value, GetArenaForAllocation()); +} +inline std::string* RpcMessage::_internal_mutable_request() { + _impl_._has_bits_[0] |= 0x00000004u; + return _impl_.request_.Mutable( GetArenaForAllocation()); +} +inline std::string* RpcMessage::release_request() { + // @@protoc_insertion_point(field_release:taotu.RpcMessage.request) + if ((_impl_._has_bits_[0] & 0x00000004u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000004u; + auto* released = _impl_.request_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.request_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void RpcMessage::set_allocated_request(std::string* value) { + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000004u; + } else { + _impl_._has_bits_[0] &= ~0x00000004u; + } + _impl_.request_.SetAllocated(value, GetArenaForAllocation()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.request_.IsDefault()) { + _impl_.request_.Set("", GetArenaForAllocation()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.request) +} + +// optional bytes response = 6; +inline bool RpcMessage::has_response() const { + bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; + return value; +} +inline void RpcMessage::clear_response() { + _impl_.response_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000008u; +} +inline const std::string& RpcMessage::response() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.response) + return _internal_response(); +} +template +inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_response(Arg_&& arg, + Args_... args) { + _impl_._has_bits_[0] |= 0x00000008u; + _impl_.response_.SetBytes(static_cast(arg), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.response) +} +inline std::string* RpcMessage::mutable_response() { + std::string* _s = _internal_mutable_response(); + // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.response) + return _s; +} +inline const std::string& RpcMessage::_internal_response() const { + return _impl_.response_.Get(); +} +inline void RpcMessage::_internal_set_response(const std::string& value) { + _impl_._has_bits_[0] |= 0x00000008u; + + + _impl_.response_.Set(value, GetArenaForAllocation()); +} +inline std::string* RpcMessage::_internal_mutable_response() { + _impl_._has_bits_[0] |= 0x00000008u; + return _impl_.response_.Mutable( GetArenaForAllocation()); +} +inline std::string* RpcMessage::release_response() { + // @@protoc_insertion_point(field_release:taotu.RpcMessage.response) + if ((_impl_._has_bits_[0] & 0x00000008u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000008u; + auto* released = _impl_.response_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.response_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void RpcMessage::set_allocated_response(std::string* value) { + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000008u; + } else { + _impl_._has_bits_[0] &= ~0x00000008u; + } + _impl_.response_.SetAllocated(value, GetArenaForAllocation()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.response_.IsDefault()) { + _impl_.response_.Set("", GetArenaForAllocation()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.response) +} + +// optional .taotu.ErrorCode error = 7; +inline bool RpcMessage::has_error() const { + bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; + return value; +} +inline void RpcMessage::clear_error() { + _impl_.error_ = 0; + _impl_._has_bits_[0] &= ~0x00000010u; +} +inline ::taotu::ErrorCode RpcMessage::error() const { + // @@protoc_insertion_point(field_get:taotu.RpcMessage.error) + return _internal_error(); +} +inline void RpcMessage::set_error(::taotu::ErrorCode value) { + _internal_set_error(value); + // @@protoc_insertion_point(field_set:taotu.RpcMessage.error) +} +inline ::taotu::ErrorCode RpcMessage::_internal_error() const { + return static_cast<::taotu::ErrorCode>(_impl_.error_); +} +inline void RpcMessage::_internal_set_error(::taotu::ErrorCode value) { + _impl_._has_bits_[0] |= 0x00000010u; + _impl_.error_ = value; +} + +// ------------------------------------------------------------------- + +// ListRpcRequest + +// optional string service_name = 1; +inline bool ListRpcRequest::has_service_name() const { + bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline void ListRpcRequest::clear_service_name() { + _impl_.service_name_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000001u; +} +inline const std::string& ListRpcRequest::service_name() const { + // @@protoc_insertion_point(field_get:taotu.ListRpcRequest.service_name) + return _internal_service_name(); +} +template +inline PROTOBUF_ALWAYS_INLINE void ListRpcRequest::set_service_name(Arg_&& arg, + Args_... args) { + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.service_name_.Set(static_cast(arg), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:taotu.ListRpcRequest.service_name) +} +inline std::string* ListRpcRequest::mutable_service_name() { + std::string* _s = _internal_mutable_service_name(); + // @@protoc_insertion_point(field_mutable:taotu.ListRpcRequest.service_name) + return _s; +} +inline const std::string& ListRpcRequest::_internal_service_name() const { + return _impl_.service_name_.Get(); +} +inline void ListRpcRequest::_internal_set_service_name(const std::string& value) { + _impl_._has_bits_[0] |= 0x00000001u; + + + _impl_.service_name_.Set(value, GetArenaForAllocation()); +} +inline std::string* ListRpcRequest::_internal_mutable_service_name() { + _impl_._has_bits_[0] |= 0x00000001u; + return _impl_.service_name_.Mutable( GetArenaForAllocation()); +} +inline std::string* ListRpcRequest::release_service_name() { + // @@protoc_insertion_point(field_release:taotu.ListRpcRequest.service_name) + if ((_impl_._has_bits_[0] & 0x00000001u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000001u; + auto* released = _impl_.service_name_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.service_name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void ListRpcRequest::set_allocated_service_name(std::string* value) { + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000001u; + } else { + _impl_._has_bits_[0] &= ~0x00000001u; + } + _impl_.service_name_.SetAllocated(value, GetArenaForAllocation()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.service_name_.IsDefault()) { + _impl_.service_name_.Set("", GetArenaForAllocation()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:taotu.ListRpcRequest.service_name) +} + +// optional bool list_method = 2; +inline bool ListRpcRequest::has_list_method() const { + bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; + return value; +} +inline void ListRpcRequest::clear_list_method() { + _impl_.list_method_ = false; + _impl_._has_bits_[0] &= ~0x00000002u; +} +inline bool ListRpcRequest::list_method() const { + // @@protoc_insertion_point(field_get:taotu.ListRpcRequest.list_method) + return _internal_list_method(); +} +inline void ListRpcRequest::set_list_method(bool value) { + _internal_set_list_method(value); + // @@protoc_insertion_point(field_set:taotu.ListRpcRequest.list_method) +} +inline bool ListRpcRequest::_internal_list_method() const { + return _impl_.list_method_; +} +inline void ListRpcRequest::_internal_set_list_method(bool value) { + _impl_._has_bits_[0] |= 0x00000002u; + _impl_.list_method_ = value; +} + +// ------------------------------------------------------------------- + +// ListRpcResponse + +// .taotu.ErrorCode error = 1; +inline void ListRpcResponse::clear_error() { + _impl_.error_ = 0; +} +inline ::taotu::ErrorCode ListRpcResponse::error() const { + // @@protoc_insertion_point(field_get:taotu.ListRpcResponse.error) + return _internal_error(); +} +inline void ListRpcResponse::set_error(::taotu::ErrorCode value) { + _internal_set_error(value); + // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.error) +} +inline ::taotu::ErrorCode ListRpcResponse::_internal_error() const { + return static_cast<::taotu::ErrorCode>(_impl_.error_); +} +inline void ListRpcResponse::_internal_set_error(::taotu::ErrorCode value) { + ; + _impl_.error_ = value; +} + +// repeated string service_name = 2; +inline int ListRpcResponse::_internal_service_name_size() const { + return _impl_.service_name_.size(); +} +inline int ListRpcResponse::service_name_size() const { + return _internal_service_name_size(); +} +inline void ListRpcResponse::clear_service_name() { + _internal_mutable_service_name()->Clear(); +} +inline std::string* ListRpcResponse::add_service_name() { + std::string* _s = _internal_add_service_name(); + // @@protoc_insertion_point(field_add_mutable:taotu.ListRpcResponse.service_name) + return _s; +} +inline const std::string& ListRpcResponse::service_name(int index) const { + // @@protoc_insertion_point(field_get:taotu.ListRpcResponse.service_name) + return _internal_service_name(index); +} +inline std::string* ListRpcResponse::mutable_service_name(int index) { + // @@protoc_insertion_point(field_mutable:taotu.ListRpcResponse.service_name) + return _internal_mutable_service_name()->Mutable(index); +} +inline void ListRpcResponse::set_service_name(int index, const std::string& value) { + _internal_mutable_service_name()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::set_service_name(int index, std::string&& value) { + _internal_mutable_service_name()->Mutable(index)->assign(std::move(value)); + // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::set_service_name(int index, const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_service_name()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::set_service_name(int index, const char* value, + std::size_t size) { + _internal_mutable_service_name()->Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::set_service_name(int index, absl::string_view value) { + _internal_mutable_service_name()->Mutable(index)->assign(value.data(), + value.size()); + // @@protoc_insertion_point(field_set_string_piece:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::add_service_name(const std::string& value) { + _internal_mutable_service_name()->Add()->assign(value); + // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::add_service_name(std::string&& value) { + _internal_mutable_service_name()->Add(std::move(value)); + // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::add_service_name(const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_service_name()->Add()->assign(value); + // @@protoc_insertion_point(field_add_char:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::add_service_name(const char* value, std::size_t size) { + _internal_mutable_service_name()->Add()->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:taotu.ListRpcResponse.service_name) +} +inline void ListRpcResponse::add_service_name(absl::string_view value) { + _internal_mutable_service_name()->Add()->assign(value.data(), value.size()); + // @@protoc_insertion_point(field_add_string_piece:taotu.ListRpcResponse.service_name) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +ListRpcResponse::service_name() const { + // @@protoc_insertion_point(field_list:taotu.ListRpcResponse.service_name) + return _internal_service_name(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* ListRpcResponse::mutable_service_name() { + // @@protoc_insertion_point(field_mutable_list:taotu.ListRpcResponse.service_name) + return _internal_mutable_service_name(); +} +inline const std::string& ListRpcResponse::_internal_service_name(int index) const { + return _internal_service_name().Get(index); +} +inline std::string* ListRpcResponse::_internal_add_service_name() { + return _internal_mutable_service_name()->Add(); +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +ListRpcResponse::_internal_service_name() const { + return _impl_.service_name_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* +ListRpcResponse::_internal_mutable_service_name() { + return &_impl_.service_name_; +} + +// repeated string method_name = 3; +inline int ListRpcResponse::_internal_method_name_size() const { + return _impl_.method_name_.size(); +} +inline int ListRpcResponse::method_name_size() const { + return _internal_method_name_size(); +} +inline void ListRpcResponse::clear_method_name() { + _internal_mutable_method_name()->Clear(); +} +inline std::string* ListRpcResponse::add_method_name() { + std::string* _s = _internal_add_method_name(); + // @@protoc_insertion_point(field_add_mutable:taotu.ListRpcResponse.method_name) + return _s; +} +inline const std::string& ListRpcResponse::method_name(int index) const { + // @@protoc_insertion_point(field_get:taotu.ListRpcResponse.method_name) + return _internal_method_name(index); +} +inline std::string* ListRpcResponse::mutable_method_name(int index) { + // @@protoc_insertion_point(field_mutable:taotu.ListRpcResponse.method_name) + return _internal_mutable_method_name()->Mutable(index); +} +inline void ListRpcResponse::set_method_name(int index, const std::string& value) { + _internal_mutable_method_name()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::set_method_name(int index, std::string&& value) { + _internal_mutable_method_name()->Mutable(index)->assign(std::move(value)); + // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::set_method_name(int index, const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_method_name()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::set_method_name(int index, const char* value, + std::size_t size) { + _internal_mutable_method_name()->Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::set_method_name(int index, absl::string_view value) { + _internal_mutable_method_name()->Mutable(index)->assign(value.data(), + value.size()); + // @@protoc_insertion_point(field_set_string_piece:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::add_method_name(const std::string& value) { + _internal_mutable_method_name()->Add()->assign(value); + // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::add_method_name(std::string&& value) { + _internal_mutable_method_name()->Add(std::move(value)); + // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::add_method_name(const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_method_name()->Add()->assign(value); + // @@protoc_insertion_point(field_add_char:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::add_method_name(const char* value, std::size_t size) { + _internal_mutable_method_name()->Add()->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:taotu.ListRpcResponse.method_name) +} +inline void ListRpcResponse::add_method_name(absl::string_view value) { + _internal_mutable_method_name()->Add()->assign(value.data(), value.size()); + // @@protoc_insertion_point(field_add_string_piece:taotu.ListRpcResponse.method_name) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +ListRpcResponse::method_name() const { + // @@protoc_insertion_point(field_list:taotu.ListRpcResponse.method_name) + return _internal_method_name(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* ListRpcResponse::mutable_method_name() { + // @@protoc_insertion_point(field_mutable_list:taotu.ListRpcResponse.method_name) + return _internal_mutable_method_name(); +} +inline const std::string& ListRpcResponse::_internal_method_name(int index) const { + return _internal_method_name().Get(index); +} +inline std::string* ListRpcResponse::_internal_add_method_name() { + return _internal_mutable_method_name()->Add(); +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +ListRpcResponse::_internal_method_name() const { + return _impl_.method_name_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* +ListRpcResponse::_internal_mutable_method_name() { + return &_impl_.method_name_; +} + +// ------------------------------------------------------------------- + +// GetServiceRequest + +// string service_name = 1; +inline void GetServiceRequest::clear_service_name() { + _impl_.service_name_.ClearToEmpty(); +} +inline const std::string& GetServiceRequest::service_name() const { + // @@protoc_insertion_point(field_get:taotu.GetServiceRequest.service_name) + return _internal_service_name(); +} +template +inline PROTOBUF_ALWAYS_INLINE void GetServiceRequest::set_service_name(Arg_&& arg, + Args_... args) { + ; + _impl_.service_name_.Set(static_cast(arg), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:taotu.GetServiceRequest.service_name) +} +inline std::string* GetServiceRequest::mutable_service_name() { + std::string* _s = _internal_mutable_service_name(); + // @@protoc_insertion_point(field_mutable:taotu.GetServiceRequest.service_name) + return _s; +} +inline const std::string& GetServiceRequest::_internal_service_name() const { + return _impl_.service_name_.Get(); +} +inline void GetServiceRequest::_internal_set_service_name(const std::string& value) { + ; + + + _impl_.service_name_.Set(value, GetArenaForAllocation()); +} +inline std::string* GetServiceRequest::_internal_mutable_service_name() { + ; + return _impl_.service_name_.Mutable( GetArenaForAllocation()); +} +inline std::string* GetServiceRequest::release_service_name() { + // @@protoc_insertion_point(field_release:taotu.GetServiceRequest.service_name) + return _impl_.service_name_.Release(); +} +inline void GetServiceRequest::set_allocated_service_name(std::string* value) { + _impl_.service_name_.SetAllocated(value, GetArenaForAllocation()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.service_name_.IsDefault()) { + _impl_.service_name_.Set("", GetArenaForAllocation()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:taotu.GetServiceRequest.service_name) +} + +// ------------------------------------------------------------------- + +// GetServiceResponse + +// .taotu.ErrorCode error = 1; +inline void GetServiceResponse::clear_error() { + _impl_.error_ = 0; +} +inline ::taotu::ErrorCode GetServiceResponse::error() const { + // @@protoc_insertion_point(field_get:taotu.GetServiceResponse.error) + return _internal_error(); +} +inline void GetServiceResponse::set_error(::taotu::ErrorCode value) { + _internal_set_error(value); + // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.error) +} +inline ::taotu::ErrorCode GetServiceResponse::_internal_error() const { + return static_cast<::taotu::ErrorCode>(_impl_.error_); +} +inline void GetServiceResponse::_internal_set_error(::taotu::ErrorCode value) { + ; + _impl_.error_ = value; +} + +// repeated string proto_file = 2; +inline int GetServiceResponse::_internal_proto_file_size() const { + return _impl_.proto_file_.size(); +} +inline int GetServiceResponse::proto_file_size() const { + return _internal_proto_file_size(); +} +inline void GetServiceResponse::clear_proto_file() { + _internal_mutable_proto_file()->Clear(); +} +inline std::string* GetServiceResponse::add_proto_file() { + std::string* _s = _internal_add_proto_file(); + // @@protoc_insertion_point(field_add_mutable:taotu.GetServiceResponse.proto_file) + return _s; +} +inline const std::string& GetServiceResponse::proto_file(int index) const { + // @@protoc_insertion_point(field_get:taotu.GetServiceResponse.proto_file) + return _internal_proto_file(index); +} +inline std::string* GetServiceResponse::mutable_proto_file(int index) { + // @@protoc_insertion_point(field_mutable:taotu.GetServiceResponse.proto_file) + return _internal_mutable_proto_file()->Mutable(index); +} +inline void GetServiceResponse::set_proto_file(int index, const std::string& value) { + _internal_mutable_proto_file()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::set_proto_file(int index, std::string&& value) { + _internal_mutable_proto_file()->Mutable(index)->assign(std::move(value)); + // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::set_proto_file(int index, const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_proto_file()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::set_proto_file(int index, const char* value, + std::size_t size) { + _internal_mutable_proto_file()->Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::set_proto_file(int index, absl::string_view value) { + _internal_mutable_proto_file()->Mutable(index)->assign(value.data(), + value.size()); + // @@protoc_insertion_point(field_set_string_piece:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::add_proto_file(const std::string& value) { + _internal_mutable_proto_file()->Add()->assign(value); + // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::add_proto_file(std::string&& value) { + _internal_mutable_proto_file()->Add(std::move(value)); + // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::add_proto_file(const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_proto_file()->Add()->assign(value); + // @@protoc_insertion_point(field_add_char:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::add_proto_file(const char* value, std::size_t size) { + _internal_mutable_proto_file()->Add()->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:taotu.GetServiceResponse.proto_file) +} +inline void GetServiceResponse::add_proto_file(absl::string_view value) { + _internal_mutable_proto_file()->Add()->assign(value.data(), value.size()); + // @@protoc_insertion_point(field_add_string_piece:taotu.GetServiceResponse.proto_file) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +GetServiceResponse::proto_file() const { + // @@protoc_insertion_point(field_list:taotu.GetServiceResponse.proto_file) + return _internal_proto_file(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* GetServiceResponse::mutable_proto_file() { + // @@protoc_insertion_point(field_mutable_list:taotu.GetServiceResponse.proto_file) + return _internal_mutable_proto_file(); +} +inline const std::string& GetServiceResponse::_internal_proto_file(int index) const { + return _internal_proto_file().Get(index); +} +inline std::string* GetServiceResponse::_internal_add_proto_file() { + return _internal_mutable_proto_file()->Add(); +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +GetServiceResponse::_internal_proto_file() const { + return _impl_.proto_file_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* +GetServiceResponse::_internal_mutable_proto_file() { + return &_impl_.proto_file_; +} + +// repeated string proto_file_name = 3; +inline int GetServiceResponse::_internal_proto_file_name_size() const { + return _impl_.proto_file_name_.size(); +} +inline int GetServiceResponse::proto_file_name_size() const { + return _internal_proto_file_name_size(); +} +inline void GetServiceResponse::clear_proto_file_name() { + _internal_mutable_proto_file_name()->Clear(); +} +inline std::string* GetServiceResponse::add_proto_file_name() { + std::string* _s = _internal_add_proto_file_name(); + // @@protoc_insertion_point(field_add_mutable:taotu.GetServiceResponse.proto_file_name) + return _s; +} +inline const std::string& GetServiceResponse::proto_file_name(int index) const { + // @@protoc_insertion_point(field_get:taotu.GetServiceResponse.proto_file_name) + return _internal_proto_file_name(index); +} +inline std::string* GetServiceResponse::mutable_proto_file_name(int index) { + // @@protoc_insertion_point(field_mutable:taotu.GetServiceResponse.proto_file_name) + return _internal_mutable_proto_file_name()->Mutable(index); +} +inline void GetServiceResponse::set_proto_file_name(int index, const std::string& value) { + _internal_mutable_proto_file_name()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::set_proto_file_name(int index, std::string&& value) { + _internal_mutable_proto_file_name()->Mutable(index)->assign(std::move(value)); + // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::set_proto_file_name(int index, const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_proto_file_name()->Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::set_proto_file_name(int index, const char* value, + std::size_t size) { + _internal_mutable_proto_file_name()->Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::set_proto_file_name(int index, absl::string_view value) { + _internal_mutable_proto_file_name()->Mutable(index)->assign(value.data(), + value.size()); + // @@protoc_insertion_point(field_set_string_piece:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::add_proto_file_name(const std::string& value) { + _internal_mutable_proto_file_name()->Add()->assign(value); + // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::add_proto_file_name(std::string&& value) { + _internal_mutable_proto_file_name()->Add(std::move(value)); + // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::add_proto_file_name(const char* value) { + ABSL_DCHECK(value != nullptr); + _internal_mutable_proto_file_name()->Add()->assign(value); + // @@protoc_insertion_point(field_add_char:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::add_proto_file_name(const char* value, std::size_t size) { + _internal_mutable_proto_file_name()->Add()->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:taotu.GetServiceResponse.proto_file_name) +} +inline void GetServiceResponse::add_proto_file_name(absl::string_view value) { + _internal_mutable_proto_file_name()->Add()->assign(value.data(), value.size()); + // @@protoc_insertion_point(field_add_string_piece:taotu.GetServiceResponse.proto_file_name) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +GetServiceResponse::proto_file_name() const { + // @@protoc_insertion_point(field_list:taotu.GetServiceResponse.proto_file_name) + return _internal_proto_file_name(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* GetServiceResponse::mutable_proto_file_name() { + // @@protoc_insertion_point(field_mutable_list:taotu.GetServiceResponse.proto_file_name) + return _internal_mutable_proto_file_name(); +} +inline const std::string& GetServiceResponse::_internal_proto_file_name(int index) const { + return _internal_proto_file_name().Get(index); +} +inline std::string* GetServiceResponse::_internal_add_proto_file_name() { + return _internal_mutable_proto_file_name()->Add(); +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +GetServiceResponse::_internal_proto_file_name() const { + return _impl_.proto_file_name_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* +GetServiceResponse::_internal_mutable_proto_file_name() { + return &_impl_.proto_file_name_; +} + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ + +// @@protoc_insertion_point(namespace_scope) +} // namespace taotu + + +PROTOBUF_NAMESPACE_OPEN + +template <> +struct is_proto_enum<::taotu::MessageType> : std::true_type {}; +template <> +inline const EnumDescriptor* GetEnumDescriptor<::taotu::MessageType>() { + return ::taotu::MessageType_descriptor(); +} +template <> +struct is_proto_enum<::taotu::ErrorCode> : std::true_type {}; +template <> +inline const EnumDescriptor* GetEnumDescriptor<::taotu::ErrorCode>() { + return ::taotu::ErrorCode_descriptor(); +} + +PROTOBUF_NAMESPACE_CLOSE + +// @@protoc_insertion_point(global_scope) + +#include "google/protobuf/port_undef.inc" + +#endif // GOOGLE_PROTOBUF_INCLUDED_rpc_2eproto_2epb_2eh diff --git a/src/rpc.proto b/src/rpc.proto new file mode 100644 index 00000000..942b761a --- /dev/null +++ b/src/rpc.proto @@ -0,0 +1,71 @@ +syntax = "proto3"; + +package taotu; + +option cc_generic_services = true; +option java_generic_services = true; +option py_generic_services = true; + +enum MessageType +{ + OTHER = 0; + REQUEST = 1; + RESPONSE = 2; + ERROR = 3; +} + +enum ErrorCode +{ + NO_ERROR = 0; + WRONG_PROTO = 1; + NO_SERVICE = 2; + NO_METHOD = 3; + INVALID_REQUEST = 4; + INVALID_RESPONSE = 5; + TIMEOUT = 6; +} + +message RpcMessage +{ + MessageType type = 1; + fixed64 id = 2; + + optional string service = 3; + optional string method = 4; + optional bytes request = 5; + + optional bytes response = 6; + + optional ErrorCode error = 7; +} + +message ListRpcRequest +{ + optional string service_name = 1; + optional bool list_method = 2; +} + +message ListRpcResponse +{ + ErrorCode error = 1; + repeated string service_name = 2; + repeated string method_name = 3; +} + +message GetServiceRequest +{ + string service_name = 1; +} + +message GetServiceResponse +{ + ErrorCode error = 1; + repeated string proto_file = 2; + repeated string proto_file_name = 3; +} + +service RpcService +{ + rpc ListRpc (ListRpcRequest) returns (ListRpcResponse); + rpc GetService (GetServiceRequest) returns (GetServiceResponse); +} diff --git a/src/rpc_channel.cc b/src/rpc_channel.cc new file mode 100644 index 00000000..426165b5 --- /dev/null +++ b/src/rpc_channel.cc @@ -0,0 +1,163 @@ +/** + * @file rpc_channel.h + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief Implementation of class "RpcChannel" which represents the single RPC + * message communication pipe. + * @date 2023-07-21 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#include "rpc_channel.h" + +#include + +#include "logger.h" +#include "rpc.pb.h" +#include "spin_lock.h" + +using namespace taotu; + +namespace taotu { + +const char kRpcTag[] = "RPC0"; + +} // namespace taotu + +RpcChannel::RpcChannel() + : codec_([this](Connecting& connection, + const std::shared_ptr& rpc_message, + TimePoint time_point) { + this->OnRpcMessage(connection, rpc_message, time_point); + }), + services_(nullptr) { + LOG_INFO("RpcChannel::RpcChannel - %p", this); +} +RpcChannel::RpcChannel(Connecting& connection) + : codec_([this](Connecting& connection, + const std::shared_ptr& rpc_message, + TimePoint time_point) { + this->OnRpcMessage(connection, rpc_message, time_point); + }), + connection_(const_cast(&connection)), + services_(nullptr) { + LOG_INFO("RpcChannel::RpcChannel - %p", this); +} +RpcChannel::~RpcChannel() { + LOG_INFO("RpcChannel::~RpcChannel - %p", this); + for (auto itr = outstanding_calls_.begin(); itr != outstanding_calls_.end(); + ++itr) { + auto outstanding_call = itr->second; + delete outstanding_call.response_message_; + delete outstanding_call.DoneCallback_; + } +} + +void RpcChannel::CallMethod( + const ::google::protobuf::MethodDescriptor* method_descriptor, + ::google::protobuf::RpcController* rpc_controller, + const ::google::protobuf::Message* request_message, + ::google::protobuf::Message* response_message, + ::google::protobuf::Closure* DoneCallback) { + RpcMessage rpc_message; + rpc_message.set_type(REQUEST); + int64_t id = id_.fetch_add(1) + 1; + rpc_message.set_id(id); + rpc_message.set_service(method_descriptor->service()->name()); + rpc_message.set_method(method_descriptor->name()); + rpc_message.set_request(request_message->SerializeAsString()); + OutstandingCall outstanding_call = {response_message, DoneCallback}; + { + LockGuard lock_guard(outstanding_calls_lock_); + outstanding_calls_[id] = outstanding_call; + } + codec_.Send(*connection_, rpc_message); +} + +void RpcChannel::OnMessage(Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time) { + codec_.OnMessage(connection, io_buffer, receive_time); +} + +void RpcChannel::OnRpcMessage( + Connecting& connection, const std::shared_ptr& rpc_message_ptr, + TimePoint receive_time) { + RpcMessage& rpc_message = *rpc_message_ptr; + if (rpc_message.type() == RESPONSE) { + int64_t id = rpc_message.id(); + OutstandingCall outstanding_call = {nullptr, nullptr}; + { + LockGuard lock_guard(outstanding_calls_lock_); + auto itr = outstanding_calls_.find(id); + if (itr != outstanding_calls_.end()) { // Find the id + outstanding_call = itr->second; + outstanding_calls_.erase(itr); + } + } + if (outstanding_call.response_message_ != nullptr) { + std::unique_ptr response_message_ptr( + outstanding_call.response_message_); + if (rpc_message.has_response()) { + outstanding_call.response_message_->ParseFromString( + rpc_message.response()); + } + if (outstanding_call.DoneCallback_ != nullptr) { + outstanding_call.DoneCallback_->Run(); + } + } + } else if (rpc_message.type() == REQUEST) { + ErrorCode error_code = WRONG_PROTO; + if (services_ != nullptr) { + auto itr = services_->find(rpc_message.service()); + if (itr != services_->end()) { + auto service = itr->second; + const auto* service_descriptor = service->GetDescriptor(); + const auto* method_descriptor = + service_descriptor->FindMethodByName(rpc_message.method()); + if (method_descriptor != nullptr) { + std::unique_ptr request_message_ptr( + service->GetRequestPrototype(method_descriptor).New()); + if (request_message_ptr->ParseFromString(rpc_message.request())) { + auto response_message_t = + service->GetResponsePrototype(method_descriptor).New(); + int64_t id = rpc_message.id(); + service->CallMethod( + method_descriptor, nullptr, request_message_ptr.get(), + response_message_t, + google::protobuf::NewCallback(this, &RpcChannel::DoneCallback, + response_message_t, id)); + error_code = NO_ERROR; + } else { + error_code = INVALID_REQUEST; + } + } else { + error_code = NO_METHOD; + } + } else { + error_code = NO_SERVICE; + } + } else { + error_code = NO_SERVICE; + } + if (error_code != NO_ERROR) { + RpcMessage rpc_response; + rpc_response.set_type(RESPONSE); + rpc_response.set_id(rpc_message.id()); + rpc_response.set_error(error_code); + codec_.Send(connection, rpc_response); + } + } else if (rpc_message.type() == ERROR) { + } +} + +void RpcChannel::DoneCallback(::google::protobuf::Message* response_message, + int64_t id) { + std::unique_ptr response_message_ptr( + response_message); + RpcMessage rpc_message; + rpc_message.set_type(RESPONSE); + rpc_message.set_id(id); + rpc_message.set_response(response_message->SerializeAsString()); + codec_.Send(*connection_, rpc_message); +} diff --git a/src/rpc_channel.h b/src/rpc_channel.h new file mode 100644 index 00000000..1ea80477 --- /dev/null +++ b/src/rpc_channel.h @@ -0,0 +1,101 @@ +/** + * @file rpc_channel.h + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief Declarations of class "RpcChannel" which represents the single RPC + * message communication pipe. + * @date 2023-07-21 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#ifndef TAOTU_SRC_RPC_CHANNEL_H_ +#define TAOTU_SRC_RPC_CHANNEL_H_ + +#include + +#include +#include +#include + +#include "connecting.h" +#include "io_buffer.h" +#include "rpc.pb.h" +#include "rpc_codec.h" +#include "spin_lock.h" +#include "time_point.h" + +namespace google { + +namespace protobuf { + +class Descriptor; +class ServiceDescriptor; +class MethodDescriptor; +class Message; + +class Closure; + +class RpcController; +class Service; + +} // namespace protobuf + +} // namespace google + +namespace taotu { + +extern const char kRpcTag[]; + +/** + * @brief "RpcChannel" represents a communication pipe to a RPC service. + * + */ +class RpcChannel : public ::google::protobuf::RpcChannel { + public: + RpcChannel(); + explicit RpcChannel(Connecting& connection); + ~RpcChannel(); + + void SetConnection(Connecting& connection) { connection_ = &connection; } + + void SetServices( + std::unordered_map* services) { + services_ = services; + } + + void CallMethod(const ::google::protobuf::MethodDescriptor* method_descriptor, + ::google::protobuf::RpcController* rpc_controller, + const ::google::protobuf::Message* request_message, + ::google::protobuf::Message* response_message, + ::google::protobuf::Closure* DoneCallback); + + void OnMessage(Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time); + + private: + void OnRpcMessage(Connecting& connection, + const std::shared_ptr& rpc_message_ptr, + TimePoint receive_time); + + void DoneCallback(::google::protobuf::Message* response_message, int64_t id); + + struct OutstandingCall { + ::google::protobuf::Message* response_message_; + ::google::protobuf::Closure* DoneCallback_; + }; + + RpcCodecT codec_; + Connecting* connection_; + std::atomic_int64_t id_; + + MutexLock outstanding_calls_lock_; + std::unordered_map outstanding_calls_; + + const std::unordered_map* + services_; +}; + +} // namespace taotu + +#endif // !TAOTU_SRC_RPC_CHANNEL_H_ diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc new file mode 100644 index 00000000..65d2c5e5 --- /dev/null +++ b/src/rpc_codec.cc @@ -0,0 +1,196 @@ +/** + * @file rpc_codec.cc + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief + * @date 2023-08-14 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#include "rpc_codec.h" + +#include +#include +#include +#include + +#include +#ifdef __MACH__ +#include +#define htobe16(x) OSSwapHostToBigInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define htobe32(x) OSSwapHostToBigInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define htobe64(x) OSSwapHostToBigInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#else +#include +#endif + +#include + +#include "logger.h" +#include "rpc.pb.h" + +using namespace taotu; + +namespace { + +int ProtobufVersionCheck() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + return 0; +} +int __attribute__((unused)) dummy = ProtobufVersionCheck(); + +} // namespace + +void RpcCodec::Send(Connecting& connection, + const ::google::protobuf::Message& message) { + IoBuffer io_buffer; + FillEmptyBuffer(&io_buffer, message); + const_cast(connection).Send(&io_buffer); +} + +void RpcCodec::OnMessage(Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time) { + while (io_buffer->GetReadableBytes() >= + static_cast(kMinMessageLength + kHeaderLength)) { + const int32_t len = io_buffer->GetReadableInt32(); + if (len > kMaxMessageLength || len < kMinMessageLength) { + ErrCallback_(connection, io_buffer, receive_time, + ErrorCode::kInvalidLength); + break; + } else if (io_buffer->GetReadableBytes() >= + static_cast(kHeaderLength + len)) { + if (RawCallback_ && + !RawCallback_(connection, + std::string_view(io_buffer->GetReadablePosition(), + kHeaderLength + len), + receive_time)) { + io_buffer->Refresh(kHeaderLength + len); + continue; + } + std::shared_ptr<::google::protobuf::Message> message(prototype_->New()); + ErrorCode error_code = Parse( + io_buffer->GetReadablePosition() + kHeaderLength, len, message.get()); + if (error_code == ErrorCode::kNoError) { + MessageCallback_(connection, message, receive_time); + io_buffer->Refresh(kHeaderLength + len); + } else { + ErrCallback_(connection, io_buffer, receive_time, error_code); + break; + } + } else { + break; + } + } +} + +bool RpcCodec::ParseFromBuffer(std::string_view buffer, + ::google::protobuf::Message* message) { + return message->ParseFromArray(buffer.data(), buffer.size()); +} +int RpcCodec::Serialize2Buffer(const ::google::protobuf::Message& message, + IoBuffer* io_buffer) { + size_t byte_size = message.ByteSizeLong(); + io_buffer->EnsureWritableSpace(byte_size + kChecksumLength); + uint8_t* start = reinterpret_cast( + const_cast(io_buffer->GetWritablePosition())); + uint8_t* end = message.SerializeWithCachedSizesToArray(start); + if (end - start != byte_size || byte_size != message.ByteSizeLong()) { + LOG_ERROR( + "Protocol message was modified concurrently during serialization. Or " + "Byte size calculation and serialization were inconsistent (This may " + "indicate a bug in protocol buffers or it may be caused by concurrent " + "modification of the message.). This shouldn't be called if all the " + "sizes are equal."); + return -1; + } + io_buffer->RefreshW(byte_size); + return byte_size; +} + +namespace { +const std::string kNoErrorStr = "NoError"; +const std::string kInvalidLengthStr = "InvalidLength"; +const std::string kCheckSumErrorStr = "CheckSumError"; +const std::string kInvalidNameLenStr = "InvalidNameLen"; +const std::string kUnknownMessageTypeStr = "UnknownMessageType"; +const std::string kParseErrorStr = "ParseError"; +const std::string kUnknownErrorStr = "UnknownError"; +} // namespace + +const std::string& RpcCodec::ErrorCode2String(ErrorCode error_code) { + switch (error_code) { + case ErrorCode::kNoError: + return kNoErrorStr; + case ErrorCode::kInvalidLength: + return kInvalidLengthStr; + case ErrorCode::kChecksumError: + return kCheckSumErrorStr; + case ErrorCode::kInvalidNameLength: + return kInvalidNameLenStr; + case ErrorCode::kUnknownMessageType: + return kUnknownMessageTypeStr; + case ErrorCode::kParseError: + return kParseErrorStr; + default: + return kUnknownErrorStr; + } +} + +RpcCodec::ErrorCode RpcCodec::Parse(const char* buffer, int length, + ::google::protobuf::Message* message) { + ErrorCode error_code = ErrorCode::kNoError; + if (ValidateChecksum(buffer, length)) { + if (::memcmp(reinterpret_cast(buffer), tag_.data(), + tag_.size()) == 0) { // Parse from the buffer + const char* data = buffer + tag_.size(); + int32_t data_length = + length - kChecksumLength - static_cast(tag_.size()); + if (!ParseFromBuffer(std::string_view(data, data_length), message)) { + error_code = ErrorCode::kParseError; + } + } else { + error_code = ErrorCode::kUnknownMessageType; + } + } else { + error_code = ErrorCode::kChecksumError; + } + return error_code; +} +void RpcCodec::FillEmptyBuffer(IoBuffer* io_buffer, + const ::google::protobuf::Message& message) { + io_buffer->Append(static_cast(tag_.c_str()), tag_.size()); + int byte_size = Serialize2Buffer(message, io_buffer); + int32_t checksum = Checksum(io_buffer->GetReadablePosition(), + static_cast(io_buffer->GetReadableBytes())); + io_buffer->AppendInt32(checksum); + int32_t len = htobe32(static_cast(io_buffer->GetReadableBytes())); + io_buffer->SetHeadContent(&len, sizeof(len)); +} + +int32_t RpcCodec::Checksum(const void* buffer, int length) { + return static_cast( + ::adler32(1, static_cast(buffer), length)); +} +bool RpcCodec::ValidateChecksum(const char* buffer, int length) { + int32_t expected_checksum = AsInt32(buffer + length - kChecksumLength); + int32_t checksum = Checksum(buffer, length - kChecksumLength); + return expected_checksum == checksum; +} +int32_t RpcCodec::AsInt32(const char* buffer) { + int32_t be32 = 0; + ::memcpy(&be32, buffer, sizeof(be32)); + return be32toh(be32); +} +void RpcCodec::DefaultErrorCallback(Connecting& connection, IoBuffer* io_buffer, + TimePoint time_point, + ErrorCode error_code) { + LOG_ERROR("RpcCodec::DefaultErrorCallback - %s", + ErrorCode2String(error_code)); + if (connection.IsConnected()) { + const_cast(connection).ShutDownWrite(); + } +} diff --git a/src/rpc_codec.h b/src/rpc_codec.h new file mode 100644 index 00000000..7389e090 --- /dev/null +++ b/src/rpc_codec.h @@ -0,0 +1,182 @@ +/** + * @file rpc_codec.h + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief + * @date 2023-08-14 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#ifndef TAOTU_SRC_RPC_CODEC_H_ +#define TAOTU_SRC_RPC_CODEC_H_ + +#include + +#include +#include +#include + +#include "connecting.h" +#include "io_buffer.h" +#include "non_copyable_movable.h" +#include "rpc.pb.h" +#include "time_point.h" + +namespace google { + +namespace protobuf { + +class Message; + +} // namespace protobuf + +} // namespace google + +namespace taotu { + +// RPC message format: +// ---------------------------------------------- +// | Field | Length | Content | +// | size | 4-byte | M+N+4 | +// | tag | M-byte | could be "RPC0", etc. | +// | payload | N-byte | | +// | checksum | 4-byte | adler32 of tag+payload | +// ---------------------------------------------- + +/** + * @brief "RpcCodec" is a RPC message codec. You should not use it directly but + * use "RpcCodecT" instead. + * + */ +class RpcCodec : NonCopyableMovable { + public: + static const int kHeaderLength = sizeof(int32_t); + static const int kChecksumLength = sizeof(int32_t); + static constexpr int kMaxMessageLength = 64 * 1024 * 1024; + + enum class ErrorCode { + kNoError = 0, + kInvalidLength, + kChecksumError, + kInvalidNameLength, + kUnknownMessageType, + kParseError, + }; + + typedef std::function&, + TimePoint)> + ProtobufMessageCallback; + typedef std::function + RawMessageCallback; + typedef std::function + ErrorCallback; + + RpcCodec(const ::google::protobuf::Message* prototype, + std::string_view tag_arg, + const ProtobufMessageCallback& MessageCallback, + const RawMessageCallback& RawCallback = RawMessageCallback{}, + const ErrorCallback& ErrCallback = DefaultErrorCallback) + : prototype_(prototype), + tag_(tag_arg), + kMinMessageLength(tag_arg.size() + kChecksumLength), + MessageCallback_(MessageCallback), + RawCallback_(RawCallback), + ErrCallback_(ErrCallback) {} + + virtual ~RpcCodec() = default; + + const std::string& GetTag() const { return tag_; } + + void Send(Connecting& connection, const ::google::protobuf::Message& message); + + void OnMessage(Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time); + + virtual bool ParseFromBuffer(std::string_view buffer, + ::google::protobuf::Message* message); + virtual int Serialize2Buffer(const ::google::protobuf::Message& message, + IoBuffer* io_buffer); + + static const std::string& ErrorCode2String(ErrorCode error_code); + + ErrorCode Parse(const char* buffer, int length, + ::google::protobuf::Message* message); + void FillEmptyBuffer(IoBuffer* io_buffer, + const ::google::protobuf::Message& message); + + static int32_t Checksum(const void* buffer, int length); + static bool ValidateChecksum(const char* buffer, int length); + static int32_t AsInt32(const char* buffer); + static void DefaultErrorCallback(Connecting& connection, IoBuffer* io_buffer, + TimePoint time_point, ErrorCode error_code); + + private: + const ::google::protobuf::Message* prototype_; + const std::string tag_; + const int kMinMessageLength; + + ProtobufMessageCallback MessageCallback_; + RawMessageCallback RawCallback_; + ErrorCallback ErrCallback_; +}; + +/** + * @brief "RpcCodecT" is a RPC message codec with the template version. You + * should use it instead of "RpcCodec". + * + */ +template +class RpcCodecT { + public: + typedef std::function&, + TimePoint)> + ProtobufMessageCallback; + typedef RpcCodec::RawMessageCallback RawMessageCallback; + typedef RpcCodec::ErrorCallback ErrorCallback; + + explicit RpcCodecT( + const ProtobufMessageCallback& MessageCallback, + const RawMessageCallback& RawCallback = RawMessageCallback{}, + const ErrorCallback& ErrCallback = RpcCodec::DefaultErrorCallback) + : MessageCallback_(MessageCallback), + codec_( + &MSG::default_instance(), TAG, + [this](Connecting& connection, + const std::shared_ptr<::google::protobuf::Message>& message, + TimePoint receive_time) { + this->OnRpcMessage(connection, message, receive_time); + }, + RawCallback, ErrCallback) {} + + const std::string& GetTag() const { return codec_.GetTag(); } + + void Send(Connecting& connection, const MSG& message) { + codec_.Send(connection, message); + } + + void OnMessage(Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time) { + codec_.OnMessage(connection, io_buffer, receive_time); + } + + void OnRpcMessage(Connecting& connection, + const std::shared_ptr<::google::protobuf::Message>& message, + TimePoint receive_time) { + MessageCallback_(connection, std::dynamic_pointer_cast(message), + receive_time); + } + + void FillEmptyBuffer(IoBuffer* io_buffer, const MSG& message) { + codec_.FillEmptyBuffer(io_buffer, message); + } + + private: + ProtobufMessageCallback MessageCallback_; + RpcCodec codec_; +}; + +} // namespace taotu + +#endif // !TAOTU_SRC_RPC_CODEC_H_ diff --git a/src/rpc_server.cc b/src/rpc_server.cc new file mode 100644 index 00000000..c807df8a --- /dev/null +++ b/src/rpc_server.cc @@ -0,0 +1,34 @@ +/** + * @file rpc_server.cc + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief Implementation of class "RpcServer" which the encapsulation of the RPC + * server. + * @date 2023-08-13 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#include "rpc_server.h" + +#include +#include + +#include "logger.h" +#include "rpc_channel.h" +#include "server.h" + +using namespace taotu; + +RpcServer::RpcServer(EventManagers* event_managers, + const NetAddress& listen_address) + : server_(event_managers, listen_address) { + server_.SetConnectionCallback([this](Connecting& connection) { + this->OnConnectionCallback(connection); + }); +} + +void RpcServer::RegisterService(::google::protobuf::Service*) {} +void RpcServer::Start() {} + +void RpcServer::OnConnectionCallback(Connecting& connection) {} diff --git a/src/rpc_server.h b/src/rpc_server.h new file mode 100644 index 00000000..a4f20345 --- /dev/null +++ b/src/rpc_server.h @@ -0,0 +1,57 @@ +/** + * @file rpc_server.h + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief Declarations of class "RpcServer" which the encapsulation of the RPC + * server. + * @date 2023-08-13 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#ifndef TAOTU_SRC_RPC_SERVER_H_ +#define TAOTU_SRC_RPC_SERVER_H_ + +#include + +#include "connecting.h" +#include "event_manager.h" +#include "net_address.h" +#include "server.h" + +namespace google { + +namespace protobuf { + +class Service; + +} // namespace protobuf + +} // namespace google + +namespace taotu { + +/** + * @brief "RpcServer" offers the ability of server for RPC services generated by + * Protobuf. + * + */ +class RpcServer { + public: + typedef std::vector EventManagers; + + RpcServer(EventManagers* event_managers, const NetAddress& listen_address); + + void RegisterService(::google::protobuf::Service*); + void Start(); + + private: + void OnConnectionCallback(Connecting& connection); + + Server server_; + std::unordered_map services_; +}; + +} // namespace taotu + +#endif // !TAOTU_SRC_RPC_SERVER_H_ From 68167c079ce34a713004e9b78d8dc0d4e1406374 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 15 Aug 2023 21:24:52 -0400 Subject: [PATCH 20/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 ++ .github/workflows/cmake.yml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index efaebfbf..30fd20ba 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -17,6 +17,8 @@ jobs: - uses: actions/checkout@v2 - name: init run: mkdir build + - name: Install Protobuf + run: sudo apt-get install protobuf-compiler libprotobuf-dev - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 949f304c..af8396dc 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -22,6 +22,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install Protobuf + run: sudo apt-get install protobuf-compiler libprotobuf-dev + - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a From 862a65fe5c90be4d879599d559c5d97d405d8681 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 09:48:48 -0400 Subject: [PATCH 21/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- .github/workflows/cmake.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 30fd20ba..69df8a1e 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,7 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install protobuf-compiler libprotobuf-dev + run: sudo apt-get install protobuf-compiler libprotobuf-dev pkg-config - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index af8396dc..6083d9ab 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v2 - name: Install Protobuf - run: sudo apt-get install protobuf-compiler libprotobuf-dev + run: sudo apt-get install protobuf-compiler libprotobuf-dev pkg-config - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a From f358210a58ced647a1c81a224cec61a3db4108e2 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 10:49:07 -0400 Subject: [PATCH 22/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- .github/workflows/cmake.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 69df8a1e..cbfce7ba 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,7 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install protobuf-compiler libprotobuf-dev pkg-config + run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6083d9ab..f003901f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v2 - name: Install Protobuf - run: sudo apt-get install protobuf-compiler libprotobuf-dev pkg-config + run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a From ad4d3d01d15a183aab19a4db076ef78aec9edfa6 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 11:15:06 -0400 Subject: [PATCH 23/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index cbfce7ba..a2c010ae 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,7 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev + run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev && sudo find /usr/ -name ProtobufConfig.cmake 2>/dev/null && sudo find /usr/ -name protobuf-config.cmake 2>/dev/null - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually From 31b170123e12b254497a63e381b08ebfa3c042a0 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 11:18:43 -0400 Subject: [PATCH 24/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index a2c010ae..e0a1821f 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,7 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev && sudo find /usr/ -name ProtobufConfig.cmake 2>/dev/null && sudo find /usr/ -name protobuf-config.cmake 2>/dev/null + run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev && sudo find / -name ProtobufConfig.cmake 2>/dev/null && sudo find / -name protobuf-config.cmake 2>/dev/null - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually From 868dd4eb9acf698fdf410bda8c2273cbc91307b9 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 11:24:19 -0400 Subject: [PATCH 25/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index e0a1821f..1dfbf74c 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,7 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev && sudo find / -name ProtobufConfig.cmake 2>/dev/null && sudo find / -name protobuf-config.cmake 2>/dev/null + run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev && sudo find / -name ProtobufConfig.cmake && sudo find / -name protobuf-config.cmake - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually From d255b1fa5865466e8072d7fc8c1fbbf60f0102da Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 22:20:28 -0400 Subject: [PATCH 26/78] [src] Delete generated pb code files --- src/rpc.pb.cc | 1886 ----------------------------------------- src/rpc.pb.h | 2224 ------------------------------------------------- 2 files changed, 4110 deletions(-) delete mode 100644 src/rpc.pb.cc delete mode 100644 src/rpc.pb.h diff --git a/src/rpc.pb.cc b/src/rpc.pb.cc deleted file mode 100644 index 9c8866ac..00000000 --- a/src/rpc.pb.cc +++ /dev/null @@ -1,1886 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: rpc.proto - -#include "rpc.pb.h" - -#include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" -PROTOBUF_PRAGMA_INIT_SEG -namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; -namespace taotu { -template -PROTOBUF_CONSTEXPR RpcMessage::RpcMessage( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_._has_bits_)*/{} - , /*decltype(_impl_._cached_size_)*/{} - , /*decltype(_impl_.service_)*/ { - &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} - } - - , /*decltype(_impl_.method_)*/ { - &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} - } - - , /*decltype(_impl_.request_)*/ { - &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} - } - - , /*decltype(_impl_.response_)*/ { - &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} - } - - , /*decltype(_impl_.id_)*/ ::uint64_t{0u} - - , /*decltype(_impl_.type_)*/ 0 - - , /*decltype(_impl_.error_)*/ 0 -} {} -struct RpcMessageDefaultTypeInternal { - PROTOBUF_CONSTEXPR RpcMessageDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} - ~RpcMessageDefaultTypeInternal() {} - union { - RpcMessage _instance; - }; -}; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 RpcMessageDefaultTypeInternal _RpcMessage_default_instance_; -template -PROTOBUF_CONSTEXPR ListRpcRequest::ListRpcRequest( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_._has_bits_)*/{} - , /*decltype(_impl_._cached_size_)*/{} - , /*decltype(_impl_.service_name_)*/ { - &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} - } - - , /*decltype(_impl_.list_method_)*/ false -} {} -struct ListRpcRequestDefaultTypeInternal { - PROTOBUF_CONSTEXPR ListRpcRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} - ~ListRpcRequestDefaultTypeInternal() {} - union { - ListRpcRequest _instance; - }; -}; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ListRpcRequestDefaultTypeInternal _ListRpcRequest_default_instance_; -template -PROTOBUF_CONSTEXPR ListRpcResponse::ListRpcResponse( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.service_name_)*/{} - , /*decltype(_impl_.method_name_)*/{} - , /*decltype(_impl_.error_)*/ 0 - - , /*decltype(_impl_._cached_size_)*/{}} {} -struct ListRpcResponseDefaultTypeInternal { - PROTOBUF_CONSTEXPR ListRpcResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} - ~ListRpcResponseDefaultTypeInternal() {} - union { - ListRpcResponse _instance; - }; -}; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ListRpcResponseDefaultTypeInternal _ListRpcResponse_default_instance_; -template -PROTOBUF_CONSTEXPR GetServiceRequest::GetServiceRequest( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.service_name_)*/ { - &::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized {} - } - - , /*decltype(_impl_._cached_size_)*/{}} {} -struct GetServiceRequestDefaultTypeInternal { - PROTOBUF_CONSTEXPR GetServiceRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} - ~GetServiceRequestDefaultTypeInternal() {} - union { - GetServiceRequest _instance; - }; -}; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GetServiceRequestDefaultTypeInternal _GetServiceRequest_default_instance_; -template -PROTOBUF_CONSTEXPR GetServiceResponse::GetServiceResponse( - ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.proto_file_)*/{} - , /*decltype(_impl_.proto_file_name_)*/{} - , /*decltype(_impl_.error_)*/ 0 - - , /*decltype(_impl_._cached_size_)*/{}} {} -struct GetServiceResponseDefaultTypeInternal { - PROTOBUF_CONSTEXPR GetServiceResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} - ~GetServiceResponseDefaultTypeInternal() {} - union { - GetServiceResponse _instance; - }; -}; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GetServiceResponseDefaultTypeInternal _GetServiceResponse_default_instance_; -} // namespace taotu -static ::_pb::Metadata file_level_metadata_rpc_2eproto[5]; -static const ::_pb::EnumDescriptor* file_level_enum_descriptors_rpc_2eproto[2]; -static const ::_pb::ServiceDescriptor* - file_level_service_descriptors_rpc_2eproto[1]; -const ::uint32_t TableStruct_rpc_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _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(::taotu::RpcMessage, _impl_.type_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.id_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.service_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.method_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.request_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.response_), - PROTOBUF_FIELD_OFFSET(::taotu::RpcMessage, _impl_.error_), - ~0u, - ~0u, - 0, - 1, - 2, - 3, - 4, - PROTOBUF_FIELD_OFFSET(::taotu::ListRpcRequest, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::taotu::ListRpcRequest, _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(::taotu::ListRpcRequest, _impl_.service_name_), - PROTOBUF_FIELD_OFFSET(::taotu::ListRpcRequest, _impl_.list_method_), - 0, - 1, - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::taotu::ListRpcResponse, _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(::taotu::ListRpcResponse, _impl_.error_), - PROTOBUF_FIELD_OFFSET(::taotu::ListRpcResponse, _impl_.service_name_), - PROTOBUF_FIELD_OFFSET(::taotu::ListRpcResponse, _impl_.method_name_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::taotu::GetServiceRequest, _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(::taotu::GetServiceRequest, _impl_.service_name_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::taotu::GetServiceResponse, _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(::taotu::GetServiceResponse, _impl_.error_), - PROTOBUF_FIELD_OFFSET(::taotu::GetServiceResponse, _impl_.proto_file_), - PROTOBUF_FIELD_OFFSET(::taotu::GetServiceResponse, _impl_.proto_file_name_), -}; - -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, 15, -1, sizeof(::taotu::RpcMessage)}, - { 22, 32, -1, sizeof(::taotu::ListRpcRequest)}, - { 34, -1, -1, sizeof(::taotu::ListRpcResponse)}, - { 45, -1, -1, sizeof(::taotu::GetServiceRequest)}, - { 54, -1, -1, sizeof(::taotu::GetServiceResponse)}, -}; - -static const ::_pb::Message* const file_default_instances[] = { - &::taotu::_RpcMessage_default_instance_._instance, - &::taotu::_ListRpcRequest_default_instance_._instance, - &::taotu::_ListRpcResponse_default_instance_._instance, - &::taotu::_GetServiceRequest_default_instance_._instance, - &::taotu::_GetServiceResponse_default_instance_._instance, -}; -const char descriptor_table_protodef_rpc_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - "\n\trpc.proto\022\005taotu\"\362\001\n\nRpcMessage\022 \n\004typ" - "e\030\001 \001(\0162\022.taotu.MessageType\022\n\n\002id\030\002 \001(\006\022" - "\024\n\007service\030\003 \001(\tH\000\210\001\001\022\023\n\006method\030\004 \001(\tH\001\210" - "\001\001\022\024\n\007request\030\005 \001(\014H\002\210\001\001\022\025\n\010response\030\006 \001" - "(\014H\003\210\001\001\022$\n\005error\030\007 \001(\0162\020.taotu.ErrorCode" - "H\004\210\001\001B\n\n\010_serviceB\t\n\007_methodB\n\n\010_request" - "B\013\n\t_responseB\010\n\006_error\"f\n\016ListRpcReques" - "t\022\031\n\014service_name\030\001 \001(\tH\000\210\001\001\022\030\n\013list_met" - "hod\030\002 \001(\010H\001\210\001\001B\017\n\r_service_nameB\016\n\014_list" - "_method\"]\n\017ListRpcResponse\022\037\n\005error\030\001 \001(" - "\0162\020.taotu.ErrorCode\022\024\n\014service_name\030\002 \003(" - "\t\022\023\n\013method_name\030\003 \003(\t\")\n\021GetServiceRequ" - "est\022\024\n\014service_name\030\001 \001(\t\"b\n\022GetServiceR" - "esponse\022\037\n\005error\030\001 \001(\0162\020.taotu.ErrorCode" - "\022\022\n\nproto_file\030\002 \003(\t\022\027\n\017proto_file_name\030" - "\003 \003(\t*>\n\013MessageType\022\t\n\005OTHER\020\000\022\013\n\007REQUE" - "ST\020\001\022\014\n\010RESPONSE\020\002\022\t\n\005ERROR\020\003*\201\001\n\tErrorC" - "ode\022\014\n\010NO_ERROR\020\000\022\017\n\013WRONG_PROTO\020\001\022\016\n\nNO" - "_SERVICE\020\002\022\r\n\tNO_METHOD\020\003\022\023\n\017INVALID_REQ" - "UEST\020\004\022\024\n\020INVALID_RESPONSE\020\005\022\013\n\007TIMEOUT\020" - "\0062\211\001\n\nRpcService\0228\n\007ListRpc\022\025.taotu.List" - "RpcRequest\032\026.taotu.ListRpcResponse\022A\n\nGe" - "tService\022\030.taotu.GetServiceRequest\032\031.tao" - "tu.GetServiceResponseB\t\200\001\001\210\001\001\220\001\001b\006proto3" -}; -static ::absl::once_flag descriptor_table_rpc_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_rpc_2eproto = { - false, - false, - 960, - descriptor_table_protodef_rpc_2eproto, - "rpc.proto", - &descriptor_table_rpc_2eproto_once, - nullptr, - 0, - 5, - schemas, - file_default_instances, - TableStruct_rpc_2eproto::offsets, - file_level_metadata_rpc_2eproto, - file_level_enum_descriptors_rpc_2eproto, - file_level_service_descriptors_rpc_2eproto, -}; - -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. -PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_rpc_2eproto_getter() { - return &descriptor_table_rpc_2eproto; -} -// Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_rpc_2eproto(&descriptor_table_rpc_2eproto); -namespace taotu { -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* MessageType_descriptor() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rpc_2eproto); - return file_level_enum_descriptors_rpc_2eproto[0]; -} -bool MessageType_IsValid(int value) { - switch (value) { - case 0: - case 1: - case 2: - case 3: - return true; - default: - return false; - } -} -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ErrorCode_descriptor() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rpc_2eproto); - return file_level_enum_descriptors_rpc_2eproto[1]; -} -bool ErrorCode_IsValid(int value) { - switch (value) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - return true; - default: - return false; - } -} -// =================================================================== - -class RpcMessage::_Internal { - public: - using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr ::int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(RpcMessage, _impl_._has_bits_); - static void set_has_service(HasBits* has_bits) { - (*has_bits)[0] |= 1u; - } - static void set_has_method(HasBits* has_bits) { - (*has_bits)[0] |= 2u; - } - static void set_has_request(HasBits* has_bits) { - (*has_bits)[0] |= 4u; - } - static void set_has_response(HasBits* has_bits) { - (*has_bits)[0] |= 8u; - } - static void set_has_error(HasBits* has_bits) { - (*has_bits)[0] |= 16u; - } -}; - -RpcMessage::RpcMessage(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(arena); - // @@protoc_insertion_point(arena_constructor:taotu.RpcMessage) -} -RpcMessage::RpcMessage(const RpcMessage& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - RpcMessage* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_._has_bits_){from._impl_._has_bits_} - , /*decltype(_impl_._cached_size_)*/{} - , decltype(_impl_.service_) {} - - , decltype(_impl_.method_) {} - - , decltype(_impl_.request_) {} - - , decltype(_impl_.response_) {} - - , decltype(_impl_.id_) {} - - , decltype(_impl_.type_) {} - - , decltype(_impl_.error_) {} - }; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _impl_.service_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_impl_.service_.Set(from._internal_service(), _this->GetArenaForAllocation()); - } - _impl_.method_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.method_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if ((from._impl_._has_bits_[0] & 0x00000002u) != 0) { - _this->_impl_.method_.Set(from._internal_method(), _this->GetArenaForAllocation()); - } - _impl_.request_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.request_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if ((from._impl_._has_bits_[0] & 0x00000004u) != 0) { - _this->_impl_.request_.Set(from._internal_request(), _this->GetArenaForAllocation()); - } - _impl_.response_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.response_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if ((from._impl_._has_bits_[0] & 0x00000008u) != 0) { - _this->_impl_.response_.Set(from._internal_response(), _this->GetArenaForAllocation()); - } - ::memcpy(&_impl_.id_, &from._impl_.id_, - static_cast<::size_t>(reinterpret_cast(&_impl_.error_) - - reinterpret_cast(&_impl_.id_)) + sizeof(_impl_.error_)); - // @@protoc_insertion_point(copy_constructor:taotu.RpcMessage) -} - -inline void RpcMessage::SharedCtor(::_pb::Arena* arena) { - (void)arena; - new (&_impl_) Impl_{ - decltype(_impl_._has_bits_){} - , /*decltype(_impl_._cached_size_)*/{} - , decltype(_impl_.service_) {} - - , decltype(_impl_.method_) {} - - , decltype(_impl_.request_) {} - - , decltype(_impl_.response_) {} - - , decltype(_impl_.id_) { ::uint64_t{0u} } - - , decltype(_impl_.type_) { 0 } - - , decltype(_impl_.error_) { 0 } - - }; - _impl_.service_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.method_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.method_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.request_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.request_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.response_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.response_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING -} - -RpcMessage::~RpcMessage() { - // @@protoc_insertion_point(destructor:taotu.RpcMessage) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void RpcMessage::SharedDtor() { - ABSL_DCHECK(GetArenaForAllocation() == nullptr); - _impl_.service_.Destroy(); - _impl_.method_.Destroy(); - _impl_.request_.Destroy(); - _impl_.response_.Destroy(); -} - -void RpcMessage::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void RpcMessage::Clear() { -// @@protoc_insertion_point(message_clear_start:taotu.RpcMessage) - ::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 & 0x0000000fu) { - if (cached_has_bits & 0x00000001u) { - _impl_.service_.ClearNonDefaultToEmpty(); - } - if (cached_has_bits & 0x00000002u) { - _impl_.method_.ClearNonDefaultToEmpty(); - } - if (cached_has_bits & 0x00000004u) { - _impl_.request_.ClearNonDefaultToEmpty(); - } - if (cached_has_bits & 0x00000008u) { - _impl_.response_.ClearNonDefaultToEmpty(); - } - } - ::memset(&_impl_.id_, 0, static_cast<::size_t>( - reinterpret_cast(&_impl_.type_) - - reinterpret_cast(&_impl_.id_)) + sizeof(_impl_.type_)); - _impl_.error_ = 0; - _impl_._has_bits_.Clear(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* RpcMessage::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - _Internal::HasBits has_bits{}; - while (!ctx->Done(&ptr)) { - ::uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // .taotu.MessageType type = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { - ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - _internal_set_type(static_cast<::taotu::MessageType>(val)); - } else { - goto handle_unusual; - } - continue; - // fixed64 id = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 17)) { - _impl_.id_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::uint64_t>(ptr); - ptr += sizeof(::uint64_t); - } else { - goto handle_unusual; - } - continue; - // optional string service = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { - auto str = _internal_mutable_service(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.RpcMessage.service")); - } else { - goto handle_unusual; - } - continue; - // optional string method = 4; - case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { - auto str = _internal_mutable_method(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.RpcMessage.method")); - } else { - goto handle_unusual; - } - continue; - // optional bytes request = 5; - case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 42)) { - auto str = _internal_mutable_request(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - } else { - goto handle_unusual; - } - continue; - // optional bytes response = 6; - case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 50)) { - auto str = _internal_mutable_response(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - } else { - goto handle_unusual; - } - continue; - // optional .taotu.ErrorCode error = 7; - case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 56)) { - ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - _internal_set_error(static_cast<::taotu::ErrorCode>(val)); - } else { - goto handle_unusual; - } - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - _impl_._has_bits_.Or(has_bits); - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -::uint8_t* RpcMessage::_InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:taotu.RpcMessage) - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - // .taotu.MessageType type = 1; - if (this->_internal_type() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteEnumToArray( - 1, this->_internal_type(), target); - } - - // fixed64 id = 2; - if (this->_internal_id() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteFixed64ToArray( - 2, this->_internal_id(), target); - } - - cached_has_bits = _impl_._has_bits_[0]; - // optional string service = 3; - if (cached_has_bits & 0x00000001u) { - const std::string& _s = this->_internal_service(); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.RpcMessage.service"); - target = stream->WriteStringMaybeAliased(3, _s, target); - } - - // optional string method = 4; - if (cached_has_bits & 0x00000002u) { - const std::string& _s = this->_internal_method(); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.RpcMessage.method"); - target = stream->WriteStringMaybeAliased(4, _s, target); - } - - // optional bytes request = 5; - if (cached_has_bits & 0x00000004u) { - const std::string& _s = this->_internal_request(); - target = stream->WriteBytesMaybeAliased(5, _s, target); - } - - // optional bytes response = 6; - if (cached_has_bits & 0x00000008u) { - const std::string& _s = this->_internal_response(); - target = stream->WriteBytesMaybeAliased(6, _s, target); - } - - // optional .taotu.ErrorCode error = 7; - if (cached_has_bits & 0x00000010u) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteEnumToArray( - 7, this->_internal_error(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:taotu.RpcMessage) - return target; -} - -::size_t RpcMessage::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:taotu.RpcMessage) - ::size_t total_size = 0; - - ::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 & 0x0000000fu) { - // optional string service = 3; - if (cached_has_bits & 0x00000001u) { - total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_service()); - } - - // optional string method = 4; - if (cached_has_bits & 0x00000002u) { - total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_method()); - } - - // optional bytes request = 5; - if (cached_has_bits & 0x00000004u) { - total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->_internal_request()); - } - - // optional bytes response = 6; - if (cached_has_bits & 0x00000008u) { - total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->_internal_response()); - } - - } - // fixed64 id = 2; - if (this->_internal_id() != 0) { - total_size += 9; - } - - // .taotu.MessageType type = 1; - if (this->_internal_type() != 0) { - total_size += 1 + - ::_pbi::WireFormatLite::EnumSize(this->_internal_type()); - } - - // optional .taotu.ErrorCode error = 7; - if (cached_has_bits & 0x00000010u) { - total_size += 1 + - ::_pbi::WireFormatLite::EnumSize(this->_internal_error()); - } - - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData RpcMessage::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - RpcMessage::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*RpcMessage::GetClassData() const { return &_class_data_; } - - -void RpcMessage::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:taotu.RpcMessage) - 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 & 0x0000000fu) { - if (cached_has_bits & 0x00000001u) { - _this->_internal_set_service(from._internal_service()); - } - if (cached_has_bits & 0x00000002u) { - _this->_internal_set_method(from._internal_method()); - } - if (cached_has_bits & 0x00000004u) { - _this->_internal_set_request(from._internal_request()); - } - if (cached_has_bits & 0x00000008u) { - _this->_internal_set_response(from._internal_response()); - } - } - if (from._internal_id() != 0) { - _this->_internal_set_id(from._internal_id()); - } - if (from._internal_type() != 0) { - _this->_internal_set_type(from._internal_type()); - } - if (cached_has_bits & 0x00000010u) { - _this->_internal_set_error(from._internal_error()); - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void RpcMessage::CopyFrom(const RpcMessage& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:taotu.RpcMessage) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool RpcMessage::IsInitialized() const { - return true; -} - -void RpcMessage::InternalSwap(RpcMessage* other) { - using std::swap; - auto* lhs_arena = GetArenaForAllocation(); - auto* rhs_arena = other->GetArenaForAllocation(); - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); - ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.service_, lhs_arena, - &other->_impl_.service_, rhs_arena); - ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.method_, lhs_arena, - &other->_impl_.method_, rhs_arena); - ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.request_, lhs_arena, - &other->_impl_.request_, rhs_arena); - ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.response_, lhs_arena, - &other->_impl_.response_, rhs_arena); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(RpcMessage, _impl_.error_) - + sizeof(RpcMessage::_impl_.error_) - - PROTOBUF_FIELD_OFFSET(RpcMessage, _impl_.id_)>( - reinterpret_cast(&_impl_.id_), - reinterpret_cast(&other->_impl_.id_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata RpcMessage::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, - file_level_metadata_rpc_2eproto[0]); -} -// =================================================================== - -class ListRpcRequest::_Internal { - public: - using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr ::int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(ListRpcRequest, _impl_._has_bits_); - static void set_has_service_name(HasBits* has_bits) { - (*has_bits)[0] |= 1u; - } - static void set_has_list_method(HasBits* has_bits) { - (*has_bits)[0] |= 2u; - } -}; - -ListRpcRequest::ListRpcRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(arena); - // @@protoc_insertion_point(arena_constructor:taotu.ListRpcRequest) -} -ListRpcRequest::ListRpcRequest(const ListRpcRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - ListRpcRequest* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_._has_bits_){from._impl_._has_bits_} - , /*decltype(_impl_._cached_size_)*/{} - , decltype(_impl_.service_name_) {} - - , decltype(_impl_.list_method_) {} - }; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _impl_.service_name_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_name_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_impl_.service_name_.Set(from._internal_service_name(), _this->GetArenaForAllocation()); - } - _this->_impl_.list_method_ = from._impl_.list_method_; - // @@protoc_insertion_point(copy_constructor:taotu.ListRpcRequest) -} - -inline void ListRpcRequest::SharedCtor(::_pb::Arena* arena) { - (void)arena; - new (&_impl_) Impl_{ - decltype(_impl_._has_bits_){} - , /*decltype(_impl_._cached_size_)*/{} - , decltype(_impl_.service_name_) {} - - , decltype(_impl_.list_method_) { false } - - }; - _impl_.service_name_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_name_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING -} - -ListRpcRequest::~ListRpcRequest() { - // @@protoc_insertion_point(destructor:taotu.ListRpcRequest) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void ListRpcRequest::SharedDtor() { - ABSL_DCHECK(GetArenaForAllocation() == nullptr); - _impl_.service_name_.Destroy(); -} - -void ListRpcRequest::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void ListRpcRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:taotu.ListRpcRequest) - ::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 & 0x00000001u) { - _impl_.service_name_.ClearNonDefaultToEmpty(); - } - _impl_.list_method_ = false; - _impl_._has_bits_.Clear(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* ListRpcRequest::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - _Internal::HasBits has_bits{}; - while (!ctx->Done(&ptr)) { - ::uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // optional string service_name = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { - auto str = _internal_mutable_service_name(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.ListRpcRequest.service_name")); - } else { - goto handle_unusual; - } - continue; - // optional bool list_method = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { - _Internal::set_has_list_method(&has_bits); - _impl_.list_method_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - } else { - goto handle_unusual; - } - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - _impl_._has_bits_.Or(has_bits); - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -::uint8_t* ListRpcRequest::_InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:taotu.ListRpcRequest) - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - cached_has_bits = _impl_._has_bits_[0]; - // optional string service_name = 1; - if (cached_has_bits & 0x00000001u) { - const std::string& _s = this->_internal_service_name(); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.ListRpcRequest.service_name"); - target = stream->WriteStringMaybeAliased(1, _s, target); - } - - // optional bool list_method = 2; - if (cached_has_bits & 0x00000002u) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteBoolToArray( - 2, this->_internal_list_method(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:taotu.ListRpcRequest) - return target; -} - -::size_t ListRpcRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:taotu.ListRpcRequest) - ::size_t total_size = 0; - - ::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) { - // optional string service_name = 1; - if (cached_has_bits & 0x00000001u) { - total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_service_name()); - } - - // optional bool list_method = 2; - if (cached_has_bits & 0x00000002u) { - total_size += 2; - } - - } - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListRpcRequest::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - ListRpcRequest::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListRpcRequest::GetClassData() const { return &_class_data_; } - - -void ListRpcRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:taotu.ListRpcRequest) - 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_service_name(from._internal_service_name()); - } - if (cached_has_bits & 0x00000002u) { - _this->_impl_.list_method_ = from._impl_.list_method_; - } - _this->_impl_._has_bits_[0] |= cached_has_bits; - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void ListRpcRequest::CopyFrom(const ListRpcRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:taotu.ListRpcRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool ListRpcRequest::IsInitialized() const { - return true; -} - -void ListRpcRequest::InternalSwap(ListRpcRequest* other) { - using std::swap; - auto* lhs_arena = GetArenaForAllocation(); - auto* rhs_arena = other->GetArenaForAllocation(); - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); - ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.service_name_, lhs_arena, - &other->_impl_.service_name_, rhs_arena); - - swap(_impl_.list_method_, other->_impl_.list_method_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata ListRpcRequest::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, - file_level_metadata_rpc_2eproto[1]); -} -// =================================================================== - -class ListRpcResponse::_Internal { - public: -}; - -ListRpcResponse::ListRpcResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(arena); - // @@protoc_insertion_point(arena_constructor:taotu.ListRpcResponse) -} -ListRpcResponse::ListRpcResponse(const ListRpcResponse& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - ListRpcResponse* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_.service_name_){from._impl_.service_name_} - , decltype(_impl_.method_name_){from._impl_.method_name_} - , decltype(_impl_.error_) {} - - , /*decltype(_impl_._cached_size_)*/{}}; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _this->_impl_.error_ = from._impl_.error_; - // @@protoc_insertion_point(copy_constructor:taotu.ListRpcResponse) -} - -inline void ListRpcResponse::SharedCtor(::_pb::Arena* arena) { - (void)arena; - new (&_impl_) Impl_{ - decltype(_impl_.service_name_){arena} - , decltype(_impl_.method_name_){arena} - , decltype(_impl_.error_) { 0 } - - , /*decltype(_impl_._cached_size_)*/{} - }; -} - -ListRpcResponse::~ListRpcResponse() { - // @@protoc_insertion_point(destructor:taotu.ListRpcResponse) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void ListRpcResponse::SharedDtor() { - ABSL_DCHECK(GetArenaForAllocation() == nullptr); - _internal_mutable_service_name()->~RepeatedPtrField(); - _internal_mutable_method_name()->~RepeatedPtrField(); -} - -void ListRpcResponse::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void ListRpcResponse::Clear() { -// @@protoc_insertion_point(message_clear_start:taotu.ListRpcResponse) - ::uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - _internal_mutable_service_name()->Clear(); - _internal_mutable_method_name()->Clear(); - _impl_.error_ = 0; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* ListRpcResponse::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - while (!ctx->Done(&ptr)) { - ::uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // .taotu.ErrorCode error = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { - ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - _internal_set_error(static_cast<::taotu::ErrorCode>(val)); - } else { - goto handle_unusual; - } - continue; - // repeated string service_name = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { - ptr -= 1; - do { - ptr += 1; - auto str = _internal_add_service_name(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.ListRpcResponse.service_name")); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); - } else { - goto handle_unusual; - } - continue; - // repeated string method_name = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { - ptr -= 1; - do { - ptr += 1; - auto str = _internal_add_method_name(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.ListRpcResponse.method_name")); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else { - goto handle_unusual; - } - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -::uint8_t* ListRpcResponse::_InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:taotu.ListRpcResponse) - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - // .taotu.ErrorCode error = 1; - if (this->_internal_error() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteEnumToArray( - 1, this->_internal_error(), target); - } - - // repeated string service_name = 2; - for (int i = 0, n = this->_internal_service_name_size(); i < n; ++i) { - const auto& s = this->_internal_service_name(i); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.ListRpcResponse.service_name"); - target = stream->WriteString(2, s, target); - } - - // repeated string method_name = 3; - for (int i = 0, n = this->_internal_method_name_size(); i < n; ++i) { - const auto& s = this->_internal_method_name(i); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.ListRpcResponse.method_name"); - target = stream->WriteString(3, s, target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:taotu.ListRpcResponse) - return target; -} - -::size_t ListRpcResponse::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:taotu.ListRpcResponse) - ::size_t total_size = 0; - - ::uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // repeated string service_name = 2; - total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_service_name().size()); - for (int i = 0, n = _internal_service_name().size(); i < n; ++i) { - total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - _internal_service_name().Get(i)); - } - - // repeated string method_name = 3; - total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_method_name().size()); - for (int i = 0, n = _internal_method_name().size(); i < n; ++i) { - total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - _internal_method_name().Get(i)); - } - - // .taotu.ErrorCode error = 1; - if (this->_internal_error() != 0) { - total_size += 1 + - ::_pbi::WireFormatLite::EnumSize(this->_internal_error()); - } - - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListRpcResponse::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - ListRpcResponse::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListRpcResponse::GetClassData() const { return &_class_data_; } - - -void ListRpcResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:taotu.ListRpcResponse) - ABSL_DCHECK_NE(&from, _this); - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - _this->_internal_mutable_service_name()->MergeFrom(from._internal_service_name()); - _this->_internal_mutable_method_name()->MergeFrom(from._internal_method_name()); - if (from._internal_error() != 0) { - _this->_internal_set_error(from._internal_error()); - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void ListRpcResponse::CopyFrom(const ListRpcResponse& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:taotu.ListRpcResponse) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool ListRpcResponse::IsInitialized() const { - return true; -} - -void ListRpcResponse::InternalSwap(ListRpcResponse* other) { - using std::swap; - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - _internal_mutable_service_name()->InternalSwap( - other->_internal_mutable_service_name()); - _internal_mutable_method_name()->InternalSwap( - other->_internal_mutable_method_name()); - swap(_impl_.error_, other->_impl_.error_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata ListRpcResponse::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, - file_level_metadata_rpc_2eproto[2]); -} -// =================================================================== - -class GetServiceRequest::_Internal { - public: -}; - -GetServiceRequest::GetServiceRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(arena); - // @@protoc_insertion_point(arena_constructor:taotu.GetServiceRequest) -} -GetServiceRequest::GetServiceRequest(const GetServiceRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - GetServiceRequest* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_.service_name_) {} - - , /*decltype(_impl_._cached_size_)*/{}}; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _impl_.service_name_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_name_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (!from._internal_service_name().empty()) { - _this->_impl_.service_name_.Set(from._internal_service_name(), _this->GetArenaForAllocation()); - } - // @@protoc_insertion_point(copy_constructor:taotu.GetServiceRequest) -} - -inline void GetServiceRequest::SharedCtor(::_pb::Arena* arena) { - (void)arena; - new (&_impl_) Impl_{ - decltype(_impl_.service_name_) {} - - , /*decltype(_impl_._cached_size_)*/{} - }; - _impl_.service_name_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_name_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING -} - -GetServiceRequest::~GetServiceRequest() { - // @@protoc_insertion_point(destructor:taotu.GetServiceRequest) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void GetServiceRequest::SharedDtor() { - ABSL_DCHECK(GetArenaForAllocation() == nullptr); - _impl_.service_name_.Destroy(); -} - -void GetServiceRequest::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void GetServiceRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:taotu.GetServiceRequest) - ::uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - _impl_.service_name_.ClearToEmpty(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* GetServiceRequest::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - while (!ctx->Done(&ptr)) { - ::uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // string service_name = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { - auto str = _internal_mutable_service_name(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.GetServiceRequest.service_name")); - } else { - goto handle_unusual; - } - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -::uint8_t* GetServiceRequest::_InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:taotu.GetServiceRequest) - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - // string service_name = 1; - if (!this->_internal_service_name().empty()) { - const std::string& _s = this->_internal_service_name(); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - _s.data(), static_cast(_s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.GetServiceRequest.service_name"); - target = stream->WriteStringMaybeAliased(1, _s, target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:taotu.GetServiceRequest) - return target; -} - -::size_t GetServiceRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:taotu.GetServiceRequest) - ::size_t total_size = 0; - - ::uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string service_name = 1; - if (!this->_internal_service_name().empty()) { - total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_service_name()); - } - - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GetServiceRequest::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - GetServiceRequest::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetServiceRequest::GetClassData() const { return &_class_data_; } - - -void GetServiceRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:taotu.GetServiceRequest) - ABSL_DCHECK_NE(&from, _this); - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - if (!from._internal_service_name().empty()) { - _this->_internal_set_service_name(from._internal_service_name()); - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void GetServiceRequest::CopyFrom(const GetServiceRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:taotu.GetServiceRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool GetServiceRequest::IsInitialized() const { - return true; -} - -void GetServiceRequest::InternalSwap(GetServiceRequest* other) { - using std::swap; - auto* lhs_arena = GetArenaForAllocation(); - auto* rhs_arena = other->GetArenaForAllocation(); - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.service_name_, lhs_arena, - &other->_impl_.service_name_, rhs_arena); -} - -::PROTOBUF_NAMESPACE_ID::Metadata GetServiceRequest::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, - file_level_metadata_rpc_2eproto[3]); -} -// =================================================================== - -class GetServiceResponse::_Internal { - public: -}; - -GetServiceResponse::GetServiceResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(arena); - // @@protoc_insertion_point(arena_constructor:taotu.GetServiceResponse) -} -GetServiceResponse::GetServiceResponse(const GetServiceResponse& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - GetServiceResponse* const _this = this; (void)_this; - new (&_impl_) Impl_{ - decltype(_impl_.proto_file_){from._impl_.proto_file_} - , decltype(_impl_.proto_file_name_){from._impl_.proto_file_name_} - , decltype(_impl_.error_) {} - - , /*decltype(_impl_._cached_size_)*/{}}; - - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - _this->_impl_.error_ = from._impl_.error_; - // @@protoc_insertion_point(copy_constructor:taotu.GetServiceResponse) -} - -inline void GetServiceResponse::SharedCtor(::_pb::Arena* arena) { - (void)arena; - new (&_impl_) Impl_{ - decltype(_impl_.proto_file_){arena} - , decltype(_impl_.proto_file_name_){arena} - , decltype(_impl_.error_) { 0 } - - , /*decltype(_impl_._cached_size_)*/{} - }; -} - -GetServiceResponse::~GetServiceResponse() { - // @@protoc_insertion_point(destructor:taotu.GetServiceResponse) - if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { - (void)arena; - return; - } - SharedDtor(); -} - -inline void GetServiceResponse::SharedDtor() { - ABSL_DCHECK(GetArenaForAllocation() == nullptr); - _internal_mutable_proto_file()->~RepeatedPtrField(); - _internal_mutable_proto_file_name()->~RepeatedPtrField(); -} - -void GetServiceResponse::SetCachedSize(int size) const { - _impl_._cached_size_.Set(size); -} - -void GetServiceResponse::Clear() { -// @@protoc_insertion_point(message_clear_start:taotu.GetServiceResponse) - ::uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - _internal_mutable_proto_file()->Clear(); - _internal_mutable_proto_file_name()->Clear(); - _impl_.error_ = 0; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* GetServiceResponse::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - while (!ctx->Done(&ptr)) { - ::uint32_t tag; - ptr = ::_pbi::ReadTag(ptr, &tag); - switch (tag >> 3) { - // .taotu.ErrorCode error = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { - ::int32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - _internal_set_error(static_cast<::taotu::ErrorCode>(val)); - } else { - goto handle_unusual; - } - continue; - // repeated string proto_file = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { - ptr -= 1; - do { - ptr += 1; - auto str = _internal_add_proto_file(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.GetServiceResponse.proto_file")); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); - } else { - goto handle_unusual; - } - continue; - // repeated string proto_file_name = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { - ptr -= 1; - do { - ptr += 1; - auto str = _internal_add_proto_file_name(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - CHK_(::_pbi::VerifyUTF8(str, "taotu.GetServiceResponse.proto_file_name")); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else { - goto handle_unusual; - } - continue; - default: - goto handle_unusual; - } // switch - handle_unusual: - if ((tag == 0) || ((tag & 7) == 4)) { - CHK_(ptr); - ctx->SetLastTag(tag); - goto message_done; - } - ptr = UnknownFieldParse( - tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - } // while -message_done: - return ptr; -failure: - ptr = nullptr; - goto message_done; -#undef CHK_ -} - -::uint8_t* GetServiceResponse::_InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:taotu.GetServiceResponse) - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - // .taotu.ErrorCode error = 1; - if (this->_internal_error() != 0) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteEnumToArray( - 1, this->_internal_error(), target); - } - - // repeated string proto_file = 2; - for (int i = 0, n = this->_internal_proto_file_size(); i < n; ++i) { - const auto& s = this->_internal_proto_file(i); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.GetServiceResponse.proto_file"); - target = stream->WriteString(2, s, target); - } - - // repeated string proto_file_name = 3; - for (int i = 0, n = this->_internal_proto_file_name_size(); i < n; ++i) { - const auto& s = this->_internal_proto_file_name(i); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "taotu.GetServiceResponse.proto_file_name"); - target = stream->WriteString(3, s, target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:taotu.GetServiceResponse) - return target; -} - -::size_t GetServiceResponse::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:taotu.GetServiceResponse) - ::size_t total_size = 0; - - ::uint32_t cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // repeated string proto_file = 2; - total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_proto_file().size()); - for (int i = 0, n = _internal_proto_file().size(); i < n; ++i) { - total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - _internal_proto_file().Get(i)); - } - - // repeated string proto_file_name = 3; - total_size += 1 * ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_internal_proto_file_name().size()); - for (int i = 0, n = _internal_proto_file_name().size(); i < n; ++i) { - total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - _internal_proto_file_name().Get(i)); - } - - // .taotu.ErrorCode error = 1; - if (this->_internal_error() != 0) { - total_size += 1 + - ::_pbi::WireFormatLite::EnumSize(this->_internal_error()); - } - - return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); -} - -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GetServiceResponse::_class_data_ = { - ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, - GetServiceResponse::MergeImpl -}; -const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetServiceResponse::GetClassData() const { return &_class_data_; } - - -void GetServiceResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { - auto* const _this = static_cast(&to_msg); - auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:taotu.GetServiceResponse) - ABSL_DCHECK_NE(&from, _this); - ::uint32_t cached_has_bits = 0; - (void) cached_has_bits; - - _this->_internal_mutable_proto_file()->MergeFrom(from._internal_proto_file()); - _this->_internal_mutable_proto_file_name()->MergeFrom(from._internal_proto_file_name()); - if (from._internal_error() != 0) { - _this->_internal_set_error(from._internal_error()); - } - _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); -} - -void GetServiceResponse::CopyFrom(const GetServiceResponse& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:taotu.GetServiceResponse) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool GetServiceResponse::IsInitialized() const { - return true; -} - -void GetServiceResponse::InternalSwap(GetServiceResponse* other) { - using std::swap; - _internal_metadata_.InternalSwap(&other->_internal_metadata_); - _internal_mutable_proto_file()->InternalSwap( - other->_internal_mutable_proto_file()); - _internal_mutable_proto_file_name()->InternalSwap( - other->_internal_mutable_proto_file_name()); - swap(_impl_.error_, other->_impl_.error_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata GetServiceResponse::GetMetadata() const { - return ::_pbi::AssignDescriptors( - &descriptor_table_rpc_2eproto_getter, &descriptor_table_rpc_2eproto_once, - file_level_metadata_rpc_2eproto[4]); -} -// =================================================================== - -const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* RpcService::descriptor() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rpc_2eproto); - return file_level_service_descriptors_rpc_2eproto[0]; -} - -const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* RpcService::GetDescriptor() { - return descriptor(); -} - -void RpcService::ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::ListRpcRequest*, ::taotu::ListRpcResponse*, ::google::protobuf::Closure* done) { - controller->SetFailed("Method ListRpc() not implemented."); - done->Run(); -} -void RpcService::GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::GetServiceRequest*, ::taotu::GetServiceResponse*, ::google::protobuf::Closure* done) { - controller->SetFailed("Method GetService() not implemented."); - done->Run(); -} - -void RpcService::CallMethod( - const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method, - ::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::PROTOBUF_NAMESPACE_ID::Message* request, - ::PROTOBUF_NAMESPACE_ID::Message* response, ::google::protobuf::Closure* done) { - ABSL_DCHECK_EQ(method->service(), file_level_service_descriptors_rpc_2eproto[0]); - switch (method->index()) { - case 0: - ListRpc(controller, - ::PROTOBUF_NAMESPACE_ID::internal::DownCast(request), - ::PROTOBUF_NAMESPACE_ID::internal::DownCast<::taotu::ListRpcResponse*>(response), done); - break; - case 1: - GetService(controller, - ::PROTOBUF_NAMESPACE_ID::internal::DownCast(request), - ::PROTOBUF_NAMESPACE_ID::internal::DownCast<::taotu::GetServiceResponse*>(response), done); - break; - - default: - ABSL_LOG(FATAL) << "Bad method index; this should never happen."; - break; - } -} - -const ::PROTOBUF_NAMESPACE_ID::Message& RpcService::GetRequestPrototype( - const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const { - ABSL_DCHECK_EQ(method->service(), descriptor()); - switch (method->index()) { - case 0: - return ::taotu::ListRpcRequest::default_instance(); - case 1: - return ::taotu::GetServiceRequest::default_instance(); - - default: - ABSL_LOG(FATAL) << "Bad method index; this should never happen."; - return *::PROTOBUF_NAMESPACE_ID::MessageFactory::generated_factory() - ->GetPrototype(method->input_type()); - } -} - -const ::PROTOBUF_NAMESPACE_ID::Message& RpcService::GetResponsePrototype( - const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const { - ABSL_DCHECK_EQ(method->service(), descriptor()); - switch (method->index()) { - case 0: - return ::taotu::ListRpcResponse::default_instance(); - case 1: - return ::taotu::GetServiceResponse::default_instance(); - - default: - ABSL_LOG(FATAL) << "Bad method index; this should never happen."; - return *::PROTOBUF_NAMESPACE_ID::MessageFactory::generated_factory() - ->GetPrototype(method->output_type()); - } -} - -RpcService_Stub::RpcService_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel) - : channel_(channel), owns_channel_(false) {} - -RpcService_Stub::RpcService_Stub( - ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, - ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership) - : channel_(channel), - owns_channel_(ownership == - ::PROTOBUF_NAMESPACE_ID::Service::STUB_OWNS_CHANNEL) {} - -RpcService_Stub::~RpcService_Stub() { - if (owns_channel_) delete channel_; -} - -void RpcService_Stub::ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::ListRpcRequest* request, - ::taotu::ListRpcResponse* response, ::google::protobuf::Closure* done) { - channel_->CallMethod(descriptor()->method(0), controller, - request, response, done); -} -void RpcService_Stub::GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::GetServiceRequest* request, - ::taotu::GetServiceResponse* response, ::google::protobuf::Closure* done) { - channel_->CallMethod(descriptor()->method(1), controller, - request, response, done); -} -// @@protoc_insertion_point(namespace_scope) -} // namespace taotu -PROTOBUF_NAMESPACE_OPEN -template<> PROTOBUF_NOINLINE ::taotu::RpcMessage* -Arena::CreateMaybeMessage< ::taotu::RpcMessage >(Arena* arena) { - return Arena::CreateMessageInternal< ::taotu::RpcMessage >(arena); -} -template<> PROTOBUF_NOINLINE ::taotu::ListRpcRequest* -Arena::CreateMaybeMessage< ::taotu::ListRpcRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::taotu::ListRpcRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::taotu::ListRpcResponse* -Arena::CreateMaybeMessage< ::taotu::ListRpcResponse >(Arena* arena) { - return Arena::CreateMessageInternal< ::taotu::ListRpcResponse >(arena); -} -template<> PROTOBUF_NOINLINE ::taotu::GetServiceRequest* -Arena::CreateMaybeMessage< ::taotu::GetServiceRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::taotu::GetServiceRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::taotu::GetServiceResponse* -Arena::CreateMaybeMessage< ::taotu::GetServiceResponse >(Arena* arena) { - return Arena::CreateMessageInternal< ::taotu::GetServiceResponse >(arena); -} -PROTOBUF_NAMESPACE_CLOSE -// @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" diff --git a/src/rpc.pb.h b/src/rpc.pb.h deleted file mode 100644 index 92300597..00000000 --- a/src/rpc.pb.h +++ /dev/null @@ -1,2224 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: rpc.proto - -#ifndef GOOGLE_PROTOBUF_INCLUDED_rpc_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_rpc_2eproto_2epb_2eh - -#include -#include -#include - -#include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4023000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION - -#if 4023001 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/generated_enum_reflection.h" -#include "google/protobuf/service.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_rpc_2eproto - -PROTOBUF_NAMESPACE_OPEN -namespace internal { -class AnyMetadata; -} // namespace internal -PROTOBUF_NAMESPACE_CLOSE - -// Internal implementation detail -- do not use these members. -struct TableStruct_rpc_2eproto { - static const ::uint32_t offsets[]; -}; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_rpc_2eproto; -namespace taotu { -class GetServiceRequest; -struct GetServiceRequestDefaultTypeInternal; -extern GetServiceRequestDefaultTypeInternal _GetServiceRequest_default_instance_; -class GetServiceResponse; -struct GetServiceResponseDefaultTypeInternal; -extern GetServiceResponseDefaultTypeInternal _GetServiceResponse_default_instance_; -class ListRpcRequest; -struct ListRpcRequestDefaultTypeInternal; -extern ListRpcRequestDefaultTypeInternal _ListRpcRequest_default_instance_; -class ListRpcResponse; -struct ListRpcResponseDefaultTypeInternal; -extern ListRpcResponseDefaultTypeInternal _ListRpcResponse_default_instance_; -class RpcMessage; -struct RpcMessageDefaultTypeInternal; -extern RpcMessageDefaultTypeInternal _RpcMessage_default_instance_; -} // namespace taotu -PROTOBUF_NAMESPACE_OPEN -template <> -::taotu::GetServiceRequest* Arena::CreateMaybeMessage<::taotu::GetServiceRequest>(Arena*); -template <> -::taotu::GetServiceResponse* Arena::CreateMaybeMessage<::taotu::GetServiceResponse>(Arena*); -template <> -::taotu::ListRpcRequest* Arena::CreateMaybeMessage<::taotu::ListRpcRequest>(Arena*); -template <> -::taotu::ListRpcResponse* Arena::CreateMaybeMessage<::taotu::ListRpcResponse>(Arena*); -template <> -::taotu::RpcMessage* Arena::CreateMaybeMessage<::taotu::RpcMessage>(Arena*); -PROTOBUF_NAMESPACE_CLOSE - -namespace taotu { -enum MessageType : int { - OTHER = 0, - REQUEST = 1, - RESPONSE = 2, - ERROR = 3, - MessageType_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits<::int32_t>::min(), - MessageType_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits<::int32_t>::max(), -}; - -bool MessageType_IsValid(int value); -constexpr MessageType MessageType_MIN = static_cast(0); -constexpr MessageType MessageType_MAX = static_cast(3); -constexpr int MessageType_ARRAYSIZE = 3 + 1; -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -MessageType_descriptor(); -template -const std::string& MessageType_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to MessageType_Name()."); - return MessageType_Name(static_cast(value)); -} -template <> -inline const std::string& MessageType_Name(MessageType value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool MessageType_Parse(absl::string_view name, MessageType* value) { - return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - MessageType_descriptor(), name, value); -} -enum ErrorCode : int { - NO_ERROR = 0, - WRONG_PROTO = 1, - NO_SERVICE = 2, - NO_METHOD = 3, - INVALID_REQUEST = 4, - INVALID_RESPONSE = 5, - TIMEOUT = 6, - ErrorCode_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits<::int32_t>::min(), - ErrorCode_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits<::int32_t>::max(), -}; - -bool ErrorCode_IsValid(int value); -constexpr ErrorCode ErrorCode_MIN = static_cast(0); -constexpr ErrorCode ErrorCode_MAX = static_cast(6); -constexpr int ErrorCode_ARRAYSIZE = 6 + 1; -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -ErrorCode_descriptor(); -template -const std::string& ErrorCode_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to ErrorCode_Name()."); - return ErrorCode_Name(static_cast(value)); -} -template <> -inline const std::string& ErrorCode_Name(ErrorCode value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool ErrorCode_Parse(absl::string_view name, ErrorCode* value) { - return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - ErrorCode_descriptor(), name, value); -} - -// =================================================================== - - -// ------------------------------------------------------------------- - -class RpcMessage final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.RpcMessage) */ { - public: - inline RpcMessage() : RpcMessage(nullptr) {} - ~RpcMessage() override; - template - explicit PROTOBUF_CONSTEXPR RpcMessage(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - RpcMessage(const RpcMessage& from); - RpcMessage(RpcMessage&& from) noexcept - : RpcMessage() { - *this = ::std::move(from); - } - - inline RpcMessage& operator=(const RpcMessage& from) { - CopyFrom(from); - return *this; - } - inline RpcMessage& operator=(RpcMessage&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); - } - inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const RpcMessage& default_instance() { - return *internal_default_instance(); - } - static inline const RpcMessage* internal_default_instance() { - return reinterpret_cast( - &_RpcMessage_default_instance_); - } - static constexpr int kIndexInFileMessages = - 0; - - friend void swap(RpcMessage& a, RpcMessage& b) { - a.Swap(&b); - } - inline void Swap(RpcMessage* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(RpcMessage* other) { - if (other == this) return; - ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - RpcMessage* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const RpcMessage& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const RpcMessage& from) { - RpcMessage::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - ::size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::uint8_t* _InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(RpcMessage* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { - return "taotu.RpcMessage"; - } - protected: - explicit RpcMessage(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kServiceFieldNumber = 3, - kMethodFieldNumber = 4, - kRequestFieldNumber = 5, - kResponseFieldNumber = 6, - kIdFieldNumber = 2, - kTypeFieldNumber = 1, - kErrorFieldNumber = 7, - }; - // optional string service = 3; - bool has_service() const; - void clear_service() ; - const std::string& service() const; - - - - - template - void set_service(Arg_&& arg, Args_... args); - std::string* mutable_service(); - PROTOBUF_NODISCARD std::string* release_service(); - void set_allocated_service(std::string* ptr); - - private: - const std::string& _internal_service() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_service( - const std::string& value); - std::string* _internal_mutable_service(); - - public: - // optional string method = 4; - bool has_method() const; - void clear_method() ; - const std::string& method() const; - - - - - template - void set_method(Arg_&& arg, Args_... args); - std::string* mutable_method(); - PROTOBUF_NODISCARD std::string* release_method(); - void set_allocated_method(std::string* ptr); - - private: - const std::string& _internal_method() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_method( - const std::string& value); - std::string* _internal_mutable_method(); - - public: - // optional bytes request = 5; - bool has_request() const; - void clear_request() ; - const std::string& request() const; - - - - - template - void set_request(Arg_&& arg, Args_... args); - std::string* mutable_request(); - PROTOBUF_NODISCARD std::string* release_request(); - void set_allocated_request(std::string* ptr); - - private: - const std::string& _internal_request() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_request( - const std::string& value); - std::string* _internal_mutable_request(); - - public: - // optional bytes response = 6; - bool has_response() const; - void clear_response() ; - const std::string& response() const; - - - - - template - void set_response(Arg_&& arg, Args_... args); - std::string* mutable_response(); - PROTOBUF_NODISCARD std::string* release_response(); - void set_allocated_response(std::string* ptr); - - private: - const std::string& _internal_response() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_response( - const std::string& value); - std::string* _internal_mutable_response(); - - public: - // fixed64 id = 2; - void clear_id() ; - ::uint64_t id() const; - void set_id(::uint64_t value); - - private: - ::uint64_t _internal_id() const; - void _internal_set_id(::uint64_t value); - - public: - // .taotu.MessageType type = 1; - void clear_type() ; - ::taotu::MessageType type() const; - void set_type(::taotu::MessageType value); - - private: - ::taotu::MessageType _internal_type() const; - void _internal_set_type(::taotu::MessageType value); - - public: - // optional .taotu.ErrorCode error = 7; - bool has_error() const; - void clear_error() ; - ::taotu::ErrorCode error() const; - void set_error(::taotu::ErrorCode value); - - private: - ::taotu::ErrorCode _internal_error() const; - void _internal_set_error(::taotu::ErrorCode value); - - public: - // @@protoc_insertion_point(class_scope:taotu.RpcMessage) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr method_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr response_; - ::uint64_t id_; - int type_; - int error_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_rpc_2eproto; -};// ------------------------------------------------------------------- - -class ListRpcRequest final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.ListRpcRequest) */ { - public: - inline ListRpcRequest() : ListRpcRequest(nullptr) {} - ~ListRpcRequest() override; - template - explicit PROTOBUF_CONSTEXPR ListRpcRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - ListRpcRequest(const ListRpcRequest& from); - ListRpcRequest(ListRpcRequest&& from) noexcept - : ListRpcRequest() { - *this = ::std::move(from); - } - - inline ListRpcRequest& operator=(const ListRpcRequest& from) { - CopyFrom(from); - return *this; - } - inline ListRpcRequest& operator=(ListRpcRequest&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); - } - inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const ListRpcRequest& default_instance() { - return *internal_default_instance(); - } - static inline const ListRpcRequest* internal_default_instance() { - return reinterpret_cast( - &_ListRpcRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 1; - - friend void swap(ListRpcRequest& a, ListRpcRequest& b) { - a.Swap(&b); - } - inline void Swap(ListRpcRequest* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(ListRpcRequest* other) { - if (other == this) return; - ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - ListRpcRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const ListRpcRequest& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const ListRpcRequest& from) { - ListRpcRequest::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - ::size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::uint8_t* _InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(ListRpcRequest* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { - return "taotu.ListRpcRequest"; - } - protected: - explicit ListRpcRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kServiceNameFieldNumber = 1, - kListMethodFieldNumber = 2, - }; - // optional string service_name = 1; - bool has_service_name() const; - void clear_service_name() ; - const std::string& service_name() const; - - - - - template - void set_service_name(Arg_&& arg, Args_... args); - std::string* mutable_service_name(); - PROTOBUF_NODISCARD std::string* release_service_name(); - void set_allocated_service_name(std::string* ptr); - - private: - const std::string& _internal_service_name() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_service_name( - const std::string& value); - std::string* _internal_mutable_service_name(); - - public: - // optional bool list_method = 2; - bool has_list_method() const; - void clear_list_method() ; - bool list_method() const; - void set_list_method(bool value); - - private: - bool _internal_list_method() const; - void _internal_set_list_method(bool value); - - public: - // @@protoc_insertion_point(class_scope:taotu.ListRpcRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_name_; - bool list_method_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_rpc_2eproto; -};// ------------------------------------------------------------------- - -class ListRpcResponse final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.ListRpcResponse) */ { - public: - inline ListRpcResponse() : ListRpcResponse(nullptr) {} - ~ListRpcResponse() override; - template - explicit PROTOBUF_CONSTEXPR ListRpcResponse(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - ListRpcResponse(const ListRpcResponse& from); - ListRpcResponse(ListRpcResponse&& from) noexcept - : ListRpcResponse() { - *this = ::std::move(from); - } - - inline ListRpcResponse& operator=(const ListRpcResponse& from) { - CopyFrom(from); - return *this; - } - inline ListRpcResponse& operator=(ListRpcResponse&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); - } - inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const ListRpcResponse& default_instance() { - return *internal_default_instance(); - } - static inline const ListRpcResponse* internal_default_instance() { - return reinterpret_cast( - &_ListRpcResponse_default_instance_); - } - static constexpr int kIndexInFileMessages = - 2; - - friend void swap(ListRpcResponse& a, ListRpcResponse& b) { - a.Swap(&b); - } - inline void Swap(ListRpcResponse* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(ListRpcResponse* other) { - if (other == this) return; - ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - ListRpcResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const ListRpcResponse& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const ListRpcResponse& from) { - ListRpcResponse::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - ::size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::uint8_t* _InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(ListRpcResponse* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { - return "taotu.ListRpcResponse"; - } - protected: - explicit ListRpcResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kServiceNameFieldNumber = 2, - kMethodNameFieldNumber = 3, - kErrorFieldNumber = 1, - }; - // repeated string service_name = 2; - int service_name_size() const; - private: - int _internal_service_name_size() const; - - public: - void clear_service_name() ; - const std::string& service_name(int index) const; - std::string* mutable_service_name(int index); - void set_service_name(int index, const std::string& value); - void set_service_name(int index, std::string&& value); - void set_service_name(int index, const char* value); - void set_service_name(int index, const char* value, std::size_t size); - void set_service_name(int index, absl::string_view value); - std::string* add_service_name(); - void add_service_name(const std::string& value); - void add_service_name(std::string&& value); - void add_service_name(const char* value); - void add_service_name(const char* value, std::size_t size); - void add_service_name(absl::string_view value); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& service_name() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_service_name(); - - private: - const std::string& _internal_service_name(int index) const; - std::string* _internal_add_service_name(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_service_name() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_service_name(); - - public: - // repeated string method_name = 3; - int method_name_size() const; - private: - int _internal_method_name_size() const; - - public: - void clear_method_name() ; - const std::string& method_name(int index) const; - std::string* mutable_method_name(int index); - void set_method_name(int index, const std::string& value); - void set_method_name(int index, std::string&& value); - void set_method_name(int index, const char* value); - void set_method_name(int index, const char* value, std::size_t size); - void set_method_name(int index, absl::string_view value); - std::string* add_method_name(); - void add_method_name(const std::string& value); - void add_method_name(std::string&& value); - void add_method_name(const char* value); - void add_method_name(const char* value, std::size_t size); - void add_method_name(absl::string_view value); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& method_name() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_method_name(); - - private: - const std::string& _internal_method_name(int index) const; - std::string* _internal_add_method_name(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_method_name() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_method_name(); - - public: - // .taotu.ErrorCode error = 1; - void clear_error() ; - ::taotu::ErrorCode error() const; - void set_error(::taotu::ErrorCode value); - - private: - ::taotu::ErrorCode _internal_error() const; - void _internal_set_error(::taotu::ErrorCode value); - - public: - // @@protoc_insertion_point(class_scope:taotu.ListRpcResponse) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField service_name_; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField method_name_; - int error_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_rpc_2eproto; -};// ------------------------------------------------------------------- - -class GetServiceRequest final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.GetServiceRequest) */ { - public: - inline GetServiceRequest() : GetServiceRequest(nullptr) {} - ~GetServiceRequest() override; - template - explicit PROTOBUF_CONSTEXPR GetServiceRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - GetServiceRequest(const GetServiceRequest& from); - GetServiceRequest(GetServiceRequest&& from) noexcept - : GetServiceRequest() { - *this = ::std::move(from); - } - - inline GetServiceRequest& operator=(const GetServiceRequest& from) { - CopyFrom(from); - return *this; - } - inline GetServiceRequest& operator=(GetServiceRequest&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); - } - inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const GetServiceRequest& default_instance() { - return *internal_default_instance(); - } - static inline const GetServiceRequest* internal_default_instance() { - return reinterpret_cast( - &_GetServiceRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 3; - - friend void swap(GetServiceRequest& a, GetServiceRequest& b) { - a.Swap(&b); - } - inline void Swap(GetServiceRequest* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(GetServiceRequest* other) { - if (other == this) return; - ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - GetServiceRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const GetServiceRequest& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const GetServiceRequest& from) { - GetServiceRequest::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - ::size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::uint8_t* _InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(GetServiceRequest* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { - return "taotu.GetServiceRequest"; - } - protected: - explicit GetServiceRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kServiceNameFieldNumber = 1, - }; - // string service_name = 1; - void clear_service_name() ; - const std::string& service_name() const; - - - - - template - void set_service_name(Arg_&& arg, Args_... args); - std::string* mutable_service_name(); - PROTOBUF_NODISCARD std::string* release_service_name(); - void set_allocated_service_name(std::string* ptr); - - private: - const std::string& _internal_service_name() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_service_name( - const std::string& value); - std::string* _internal_mutable_service_name(); - - public: - // @@protoc_insertion_point(class_scope:taotu.GetServiceRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_name_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_rpc_2eproto; -};// ------------------------------------------------------------------- - -class GetServiceResponse final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:taotu.GetServiceResponse) */ { - public: - inline GetServiceResponse() : GetServiceResponse(nullptr) {} - ~GetServiceResponse() override; - template - explicit PROTOBUF_CONSTEXPR GetServiceResponse(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - GetServiceResponse(const GetServiceResponse& from); - GetServiceResponse(GetServiceResponse&& from) noexcept - : GetServiceResponse() { - *this = ::std::move(from); - } - - inline GetServiceResponse& operator=(const GetServiceResponse& from) { - CopyFrom(from); - return *this; - } - inline GetServiceResponse& operator=(GetServiceResponse&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); - } - inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const GetServiceResponse& default_instance() { - return *internal_default_instance(); - } - static inline const GetServiceResponse* internal_default_instance() { - return reinterpret_cast( - &_GetServiceResponse_default_instance_); - } - static constexpr int kIndexInFileMessages = - 4; - - friend void swap(GetServiceResponse& a, GetServiceResponse& b) { - a.Swap(&b); - } - inline void Swap(GetServiceResponse* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(GetServiceResponse* other) { - if (other == this) return; - ABSL_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - GetServiceResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const GetServiceResponse& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const GetServiceResponse& from) { - GetServiceResponse::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - ::size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::uint8_t* _InternalSerialize( - ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(GetServiceResponse* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { - return "taotu.GetServiceResponse"; - } - protected: - explicit GetServiceResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kProtoFileFieldNumber = 2, - kProtoFileNameFieldNumber = 3, - kErrorFieldNumber = 1, - }; - // repeated string proto_file = 2; - int proto_file_size() const; - private: - int _internal_proto_file_size() const; - - public: - void clear_proto_file() ; - const std::string& proto_file(int index) const; - std::string* mutable_proto_file(int index); - void set_proto_file(int index, const std::string& value); - void set_proto_file(int index, std::string&& value); - void set_proto_file(int index, const char* value); - void set_proto_file(int index, const char* value, std::size_t size); - void set_proto_file(int index, absl::string_view value); - std::string* add_proto_file(); - void add_proto_file(const std::string& value); - void add_proto_file(std::string&& value); - void add_proto_file(const char* value); - void add_proto_file(const char* value, std::size_t size); - void add_proto_file(absl::string_view value); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& proto_file() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_proto_file(); - - private: - const std::string& _internal_proto_file(int index) const; - std::string* _internal_add_proto_file(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_proto_file() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_proto_file(); - - public: - // repeated string proto_file_name = 3; - int proto_file_name_size() const; - private: - int _internal_proto_file_name_size() const; - - public: - void clear_proto_file_name() ; - const std::string& proto_file_name(int index) const; - std::string* mutable_proto_file_name(int index); - void set_proto_file_name(int index, const std::string& value); - void set_proto_file_name(int index, std::string&& value); - void set_proto_file_name(int index, const char* value); - void set_proto_file_name(int index, const char* value, std::size_t size); - void set_proto_file_name(int index, absl::string_view value); - std::string* add_proto_file_name(); - void add_proto_file_name(const std::string& value); - void add_proto_file_name(std::string&& value); - void add_proto_file_name(const char* value); - void add_proto_file_name(const char* value, std::size_t size); - void add_proto_file_name(absl::string_view value); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& proto_file_name() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_proto_file_name(); - - private: - const std::string& _internal_proto_file_name(int index) const; - std::string* _internal_add_proto_file_name(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& _internal_proto_file_name() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* _internal_mutable_proto_file_name(); - - public: - // .taotu.ErrorCode error = 1; - void clear_error() ; - ::taotu::ErrorCode error() const; - void set_error(::taotu::ErrorCode value); - - private: - ::taotu::ErrorCode _internal_error() const; - void _internal_set_error(::taotu::ErrorCode value); - - public: - // @@protoc_insertion_point(class_scope:taotu.GetServiceResponse) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField proto_file_; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField proto_file_name_; - int error_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_rpc_2eproto; -}; - -// =================================================================== - - -// ------------------------------------------------------------------- - -class RpcService_Stub; -class RpcService : public ::PROTOBUF_NAMESPACE_ID::Service { - protected: - RpcService() = default; - - public: - using Stub = RpcService_Stub; - - RpcService(const RpcService&) = delete; - RpcService& operator=(const RpcService&) = delete; - virtual ~RpcService() = default; - - static const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* descriptor(); - - virtual void ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::ListRpcRequest* request, - ::taotu::ListRpcResponse* response, - ::google::protobuf::Closure* done); - virtual void GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::GetServiceRequest* request, - ::taotu::GetServiceResponse* response, - ::google::protobuf::Closure* done); - - // implements Service ---------------------------------------------- - const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* GetDescriptor() override; - - void CallMethod(const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method, - ::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::PROTOBUF_NAMESPACE_ID::Message* request, - ::PROTOBUF_NAMESPACE_ID::Message* response, - ::google::protobuf::Closure* done) override; - - const ::PROTOBUF_NAMESPACE_ID::Message& GetRequestPrototype( - const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const override; - - const ::PROTOBUF_NAMESPACE_ID::Message& GetResponsePrototype( - const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const override; -}; - -class RpcService_Stub final : public RpcService { - public: - RpcService_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel); - RpcService_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, - ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership); - - RpcService_Stub(const RpcService_Stub&) = delete; - RpcService_Stub& operator=(const RpcService_Stub&) = delete; - - ~RpcService_Stub() override; - - inline ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel() { return channel_; } - - // implements RpcService ------------------------------------------ - void ListRpc(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::ListRpcRequest* request, - ::taotu::ListRpcResponse* response, - ::google::protobuf::Closure* done) override; - void GetService(::PROTOBUF_NAMESPACE_ID::RpcController* controller, - const ::taotu::GetServiceRequest* request, - ::taotu::GetServiceResponse* response, - ::google::protobuf::Closure* done) override; - - private: - ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel_; - bool owns_channel_; -}; -// =================================================================== - - - -// =================================================================== - - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -// ------------------------------------------------------------------- - -// RpcMessage - -// .taotu.MessageType type = 1; -inline void RpcMessage::clear_type() { - _impl_.type_ = 0; -} -inline ::taotu::MessageType RpcMessage::type() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.type) - return _internal_type(); -} -inline void RpcMessage::set_type(::taotu::MessageType value) { - _internal_set_type(value); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.type) -} -inline ::taotu::MessageType RpcMessage::_internal_type() const { - return static_cast<::taotu::MessageType>(_impl_.type_); -} -inline void RpcMessage::_internal_set_type(::taotu::MessageType value) { - ; - _impl_.type_ = value; -} - -// fixed64 id = 2; -inline void RpcMessage::clear_id() { - _impl_.id_ = ::uint64_t{0u}; -} -inline ::uint64_t RpcMessage::id() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.id) - return _internal_id(); -} -inline void RpcMessage::set_id(::uint64_t value) { - _internal_set_id(value); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.id) -} -inline ::uint64_t RpcMessage::_internal_id() const { - return _impl_.id_; -} -inline void RpcMessage::_internal_set_id(::uint64_t value) { - ; - _impl_.id_ = value; -} - -// optional string service = 3; -inline bool RpcMessage::has_service() const { - bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; - return value; -} -inline void RpcMessage::clear_service() { - _impl_.service_.ClearToEmpty(); - _impl_._has_bits_[0] &= ~0x00000001u; -} -inline const std::string& RpcMessage::service() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.service) - return _internal_service(); -} -template -inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_service(Arg_&& arg, - Args_... args) { - _impl_._has_bits_[0] |= 0x00000001u; - _impl_.service_.Set(static_cast(arg), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.service) -} -inline std::string* RpcMessage::mutable_service() { - std::string* _s = _internal_mutable_service(); - // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.service) - return _s; -} -inline const std::string& RpcMessage::_internal_service() const { - return _impl_.service_.Get(); -} -inline void RpcMessage::_internal_set_service(const std::string& value) { - _impl_._has_bits_[0] |= 0x00000001u; - - - _impl_.service_.Set(value, GetArenaForAllocation()); -} -inline std::string* RpcMessage::_internal_mutable_service() { - _impl_._has_bits_[0] |= 0x00000001u; - return _impl_.service_.Mutable( GetArenaForAllocation()); -} -inline std::string* RpcMessage::release_service() { - // @@protoc_insertion_point(field_release:taotu.RpcMessage.service) - if ((_impl_._has_bits_[0] & 0x00000001u) == 0) { - return nullptr; - } - _impl_._has_bits_[0] &= ~0x00000001u; - auto* released = _impl_.service_.Release(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - return released; -} -inline void RpcMessage::set_allocated_service(std::string* value) { - if (value != nullptr) { - _impl_._has_bits_[0] |= 0x00000001u; - } else { - _impl_._has_bits_[0] &= ~0x00000001u; - } - _impl_.service_.SetAllocated(value, GetArenaForAllocation()); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.service_.IsDefault()) { - _impl_.service_.Set("", GetArenaForAllocation()); - } - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.service) -} - -// optional string method = 4; -inline bool RpcMessage::has_method() const { - bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; - return value; -} -inline void RpcMessage::clear_method() { - _impl_.method_.ClearToEmpty(); - _impl_._has_bits_[0] &= ~0x00000002u; -} -inline const std::string& RpcMessage::method() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.method) - return _internal_method(); -} -template -inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_method(Arg_&& arg, - Args_... args) { - _impl_._has_bits_[0] |= 0x00000002u; - _impl_.method_.Set(static_cast(arg), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.method) -} -inline std::string* RpcMessage::mutable_method() { - std::string* _s = _internal_mutable_method(); - // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.method) - return _s; -} -inline const std::string& RpcMessage::_internal_method() const { - return _impl_.method_.Get(); -} -inline void RpcMessage::_internal_set_method(const std::string& value) { - _impl_._has_bits_[0] |= 0x00000002u; - - - _impl_.method_.Set(value, GetArenaForAllocation()); -} -inline std::string* RpcMessage::_internal_mutable_method() { - _impl_._has_bits_[0] |= 0x00000002u; - return _impl_.method_.Mutable( GetArenaForAllocation()); -} -inline std::string* RpcMessage::release_method() { - // @@protoc_insertion_point(field_release:taotu.RpcMessage.method) - if ((_impl_._has_bits_[0] & 0x00000002u) == 0) { - return nullptr; - } - _impl_._has_bits_[0] &= ~0x00000002u; - auto* released = _impl_.method_.Release(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.method_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - return released; -} -inline void RpcMessage::set_allocated_method(std::string* value) { - if (value != nullptr) { - _impl_._has_bits_[0] |= 0x00000002u; - } else { - _impl_._has_bits_[0] &= ~0x00000002u; - } - _impl_.method_.SetAllocated(value, GetArenaForAllocation()); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.method_.IsDefault()) { - _impl_.method_.Set("", GetArenaForAllocation()); - } - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.method) -} - -// optional bytes request = 5; -inline bool RpcMessage::has_request() const { - bool value = (_impl_._has_bits_[0] & 0x00000004u) != 0; - return value; -} -inline void RpcMessage::clear_request() { - _impl_.request_.ClearToEmpty(); - _impl_._has_bits_[0] &= ~0x00000004u; -} -inline const std::string& RpcMessage::request() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.request) - return _internal_request(); -} -template -inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_request(Arg_&& arg, - Args_... args) { - _impl_._has_bits_[0] |= 0x00000004u; - _impl_.request_.SetBytes(static_cast(arg), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.request) -} -inline std::string* RpcMessage::mutable_request() { - std::string* _s = _internal_mutable_request(); - // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.request) - return _s; -} -inline const std::string& RpcMessage::_internal_request() const { - return _impl_.request_.Get(); -} -inline void RpcMessage::_internal_set_request(const std::string& value) { - _impl_._has_bits_[0] |= 0x00000004u; - - - _impl_.request_.Set(value, GetArenaForAllocation()); -} -inline std::string* RpcMessage::_internal_mutable_request() { - _impl_._has_bits_[0] |= 0x00000004u; - return _impl_.request_.Mutable( GetArenaForAllocation()); -} -inline std::string* RpcMessage::release_request() { - // @@protoc_insertion_point(field_release:taotu.RpcMessage.request) - if ((_impl_._has_bits_[0] & 0x00000004u) == 0) { - return nullptr; - } - _impl_._has_bits_[0] &= ~0x00000004u; - auto* released = _impl_.request_.Release(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.request_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - return released; -} -inline void RpcMessage::set_allocated_request(std::string* value) { - if (value != nullptr) { - _impl_._has_bits_[0] |= 0x00000004u; - } else { - _impl_._has_bits_[0] &= ~0x00000004u; - } - _impl_.request_.SetAllocated(value, GetArenaForAllocation()); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.request_.IsDefault()) { - _impl_.request_.Set("", GetArenaForAllocation()); - } - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.request) -} - -// optional bytes response = 6; -inline bool RpcMessage::has_response() const { - bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; - return value; -} -inline void RpcMessage::clear_response() { - _impl_.response_.ClearToEmpty(); - _impl_._has_bits_[0] &= ~0x00000008u; -} -inline const std::string& RpcMessage::response() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.response) - return _internal_response(); -} -template -inline PROTOBUF_ALWAYS_INLINE void RpcMessage::set_response(Arg_&& arg, - Args_... args) { - _impl_._has_bits_[0] |= 0x00000008u; - _impl_.response_.SetBytes(static_cast(arg), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.response) -} -inline std::string* RpcMessage::mutable_response() { - std::string* _s = _internal_mutable_response(); - // @@protoc_insertion_point(field_mutable:taotu.RpcMessage.response) - return _s; -} -inline const std::string& RpcMessage::_internal_response() const { - return _impl_.response_.Get(); -} -inline void RpcMessage::_internal_set_response(const std::string& value) { - _impl_._has_bits_[0] |= 0x00000008u; - - - _impl_.response_.Set(value, GetArenaForAllocation()); -} -inline std::string* RpcMessage::_internal_mutable_response() { - _impl_._has_bits_[0] |= 0x00000008u; - return _impl_.response_.Mutable( GetArenaForAllocation()); -} -inline std::string* RpcMessage::release_response() { - // @@protoc_insertion_point(field_release:taotu.RpcMessage.response) - if ((_impl_._has_bits_[0] & 0x00000008u) == 0) { - return nullptr; - } - _impl_._has_bits_[0] &= ~0x00000008u; - auto* released = _impl_.response_.Release(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.response_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - return released; -} -inline void RpcMessage::set_allocated_response(std::string* value) { - if (value != nullptr) { - _impl_._has_bits_[0] |= 0x00000008u; - } else { - _impl_._has_bits_[0] &= ~0x00000008u; - } - _impl_.response_.SetAllocated(value, GetArenaForAllocation()); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.response_.IsDefault()) { - _impl_.response_.Set("", GetArenaForAllocation()); - } - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:taotu.RpcMessage.response) -} - -// optional .taotu.ErrorCode error = 7; -inline bool RpcMessage::has_error() const { - bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; - return value; -} -inline void RpcMessage::clear_error() { - _impl_.error_ = 0; - _impl_._has_bits_[0] &= ~0x00000010u; -} -inline ::taotu::ErrorCode RpcMessage::error() const { - // @@protoc_insertion_point(field_get:taotu.RpcMessage.error) - return _internal_error(); -} -inline void RpcMessage::set_error(::taotu::ErrorCode value) { - _internal_set_error(value); - // @@protoc_insertion_point(field_set:taotu.RpcMessage.error) -} -inline ::taotu::ErrorCode RpcMessage::_internal_error() const { - return static_cast<::taotu::ErrorCode>(_impl_.error_); -} -inline void RpcMessage::_internal_set_error(::taotu::ErrorCode value) { - _impl_._has_bits_[0] |= 0x00000010u; - _impl_.error_ = value; -} - -// ------------------------------------------------------------------- - -// ListRpcRequest - -// optional string service_name = 1; -inline bool ListRpcRequest::has_service_name() const { - bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; - return value; -} -inline void ListRpcRequest::clear_service_name() { - _impl_.service_name_.ClearToEmpty(); - _impl_._has_bits_[0] &= ~0x00000001u; -} -inline const std::string& ListRpcRequest::service_name() const { - // @@protoc_insertion_point(field_get:taotu.ListRpcRequest.service_name) - return _internal_service_name(); -} -template -inline PROTOBUF_ALWAYS_INLINE void ListRpcRequest::set_service_name(Arg_&& arg, - Args_... args) { - _impl_._has_bits_[0] |= 0x00000001u; - _impl_.service_name_.Set(static_cast(arg), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:taotu.ListRpcRequest.service_name) -} -inline std::string* ListRpcRequest::mutable_service_name() { - std::string* _s = _internal_mutable_service_name(); - // @@protoc_insertion_point(field_mutable:taotu.ListRpcRequest.service_name) - return _s; -} -inline const std::string& ListRpcRequest::_internal_service_name() const { - return _impl_.service_name_.Get(); -} -inline void ListRpcRequest::_internal_set_service_name(const std::string& value) { - _impl_._has_bits_[0] |= 0x00000001u; - - - _impl_.service_name_.Set(value, GetArenaForAllocation()); -} -inline std::string* ListRpcRequest::_internal_mutable_service_name() { - _impl_._has_bits_[0] |= 0x00000001u; - return _impl_.service_name_.Mutable( GetArenaForAllocation()); -} -inline std::string* ListRpcRequest::release_service_name() { - // @@protoc_insertion_point(field_release:taotu.ListRpcRequest.service_name) - if ((_impl_._has_bits_[0] & 0x00000001u) == 0) { - return nullptr; - } - _impl_._has_bits_[0] &= ~0x00000001u; - auto* released = _impl_.service_name_.Release(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.service_name_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - return released; -} -inline void ListRpcRequest::set_allocated_service_name(std::string* value) { - if (value != nullptr) { - _impl_._has_bits_[0] |= 0x00000001u; - } else { - _impl_._has_bits_[0] &= ~0x00000001u; - } - _impl_.service_name_.SetAllocated(value, GetArenaForAllocation()); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.service_name_.IsDefault()) { - _impl_.service_name_.Set("", GetArenaForAllocation()); - } - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:taotu.ListRpcRequest.service_name) -} - -// optional bool list_method = 2; -inline bool ListRpcRequest::has_list_method() const { - bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; - return value; -} -inline void ListRpcRequest::clear_list_method() { - _impl_.list_method_ = false; - _impl_._has_bits_[0] &= ~0x00000002u; -} -inline bool ListRpcRequest::list_method() const { - // @@protoc_insertion_point(field_get:taotu.ListRpcRequest.list_method) - return _internal_list_method(); -} -inline void ListRpcRequest::set_list_method(bool value) { - _internal_set_list_method(value); - // @@protoc_insertion_point(field_set:taotu.ListRpcRequest.list_method) -} -inline bool ListRpcRequest::_internal_list_method() const { - return _impl_.list_method_; -} -inline void ListRpcRequest::_internal_set_list_method(bool value) { - _impl_._has_bits_[0] |= 0x00000002u; - _impl_.list_method_ = value; -} - -// ------------------------------------------------------------------- - -// ListRpcResponse - -// .taotu.ErrorCode error = 1; -inline void ListRpcResponse::clear_error() { - _impl_.error_ = 0; -} -inline ::taotu::ErrorCode ListRpcResponse::error() const { - // @@protoc_insertion_point(field_get:taotu.ListRpcResponse.error) - return _internal_error(); -} -inline void ListRpcResponse::set_error(::taotu::ErrorCode value) { - _internal_set_error(value); - // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.error) -} -inline ::taotu::ErrorCode ListRpcResponse::_internal_error() const { - return static_cast<::taotu::ErrorCode>(_impl_.error_); -} -inline void ListRpcResponse::_internal_set_error(::taotu::ErrorCode value) { - ; - _impl_.error_ = value; -} - -// repeated string service_name = 2; -inline int ListRpcResponse::_internal_service_name_size() const { - return _impl_.service_name_.size(); -} -inline int ListRpcResponse::service_name_size() const { - return _internal_service_name_size(); -} -inline void ListRpcResponse::clear_service_name() { - _internal_mutable_service_name()->Clear(); -} -inline std::string* ListRpcResponse::add_service_name() { - std::string* _s = _internal_add_service_name(); - // @@protoc_insertion_point(field_add_mutable:taotu.ListRpcResponse.service_name) - return _s; -} -inline const std::string& ListRpcResponse::service_name(int index) const { - // @@protoc_insertion_point(field_get:taotu.ListRpcResponse.service_name) - return _internal_service_name(index); -} -inline std::string* ListRpcResponse::mutable_service_name(int index) { - // @@protoc_insertion_point(field_mutable:taotu.ListRpcResponse.service_name) - return _internal_mutable_service_name()->Mutable(index); -} -inline void ListRpcResponse::set_service_name(int index, const std::string& value) { - _internal_mutable_service_name()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::set_service_name(int index, std::string&& value) { - _internal_mutable_service_name()->Mutable(index)->assign(std::move(value)); - // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::set_service_name(int index, const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_service_name()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::set_service_name(int index, const char* value, - std::size_t size) { - _internal_mutable_service_name()->Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::set_service_name(int index, absl::string_view value) { - _internal_mutable_service_name()->Mutable(index)->assign(value.data(), - value.size()); - // @@protoc_insertion_point(field_set_string_piece:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::add_service_name(const std::string& value) { - _internal_mutable_service_name()->Add()->assign(value); - // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::add_service_name(std::string&& value) { - _internal_mutable_service_name()->Add(std::move(value)); - // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::add_service_name(const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_service_name()->Add()->assign(value); - // @@protoc_insertion_point(field_add_char:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::add_service_name(const char* value, std::size_t size) { - _internal_mutable_service_name()->Add()->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:taotu.ListRpcResponse.service_name) -} -inline void ListRpcResponse::add_service_name(absl::string_view value) { - _internal_mutable_service_name()->Add()->assign(value.data(), value.size()); - // @@protoc_insertion_point(field_add_string_piece:taotu.ListRpcResponse.service_name) -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -ListRpcResponse::service_name() const { - // @@protoc_insertion_point(field_list:taotu.ListRpcResponse.service_name) - return _internal_service_name(); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* ListRpcResponse::mutable_service_name() { - // @@protoc_insertion_point(field_mutable_list:taotu.ListRpcResponse.service_name) - return _internal_mutable_service_name(); -} -inline const std::string& ListRpcResponse::_internal_service_name(int index) const { - return _internal_service_name().Get(index); -} -inline std::string* ListRpcResponse::_internal_add_service_name() { - return _internal_mutable_service_name()->Add(); -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -ListRpcResponse::_internal_service_name() const { - return _impl_.service_name_; -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* -ListRpcResponse::_internal_mutable_service_name() { - return &_impl_.service_name_; -} - -// repeated string method_name = 3; -inline int ListRpcResponse::_internal_method_name_size() const { - return _impl_.method_name_.size(); -} -inline int ListRpcResponse::method_name_size() const { - return _internal_method_name_size(); -} -inline void ListRpcResponse::clear_method_name() { - _internal_mutable_method_name()->Clear(); -} -inline std::string* ListRpcResponse::add_method_name() { - std::string* _s = _internal_add_method_name(); - // @@protoc_insertion_point(field_add_mutable:taotu.ListRpcResponse.method_name) - return _s; -} -inline const std::string& ListRpcResponse::method_name(int index) const { - // @@protoc_insertion_point(field_get:taotu.ListRpcResponse.method_name) - return _internal_method_name(index); -} -inline std::string* ListRpcResponse::mutable_method_name(int index) { - // @@protoc_insertion_point(field_mutable:taotu.ListRpcResponse.method_name) - return _internal_mutable_method_name()->Mutable(index); -} -inline void ListRpcResponse::set_method_name(int index, const std::string& value) { - _internal_mutable_method_name()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::set_method_name(int index, std::string&& value) { - _internal_mutable_method_name()->Mutable(index)->assign(std::move(value)); - // @@protoc_insertion_point(field_set:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::set_method_name(int index, const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_method_name()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::set_method_name(int index, const char* value, - std::size_t size) { - _internal_mutable_method_name()->Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::set_method_name(int index, absl::string_view value) { - _internal_mutable_method_name()->Mutable(index)->assign(value.data(), - value.size()); - // @@protoc_insertion_point(field_set_string_piece:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::add_method_name(const std::string& value) { - _internal_mutable_method_name()->Add()->assign(value); - // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::add_method_name(std::string&& value) { - _internal_mutable_method_name()->Add(std::move(value)); - // @@protoc_insertion_point(field_add:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::add_method_name(const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_method_name()->Add()->assign(value); - // @@protoc_insertion_point(field_add_char:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::add_method_name(const char* value, std::size_t size) { - _internal_mutable_method_name()->Add()->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:taotu.ListRpcResponse.method_name) -} -inline void ListRpcResponse::add_method_name(absl::string_view value) { - _internal_mutable_method_name()->Add()->assign(value.data(), value.size()); - // @@protoc_insertion_point(field_add_string_piece:taotu.ListRpcResponse.method_name) -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -ListRpcResponse::method_name() const { - // @@protoc_insertion_point(field_list:taotu.ListRpcResponse.method_name) - return _internal_method_name(); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* ListRpcResponse::mutable_method_name() { - // @@protoc_insertion_point(field_mutable_list:taotu.ListRpcResponse.method_name) - return _internal_mutable_method_name(); -} -inline const std::string& ListRpcResponse::_internal_method_name(int index) const { - return _internal_method_name().Get(index); -} -inline std::string* ListRpcResponse::_internal_add_method_name() { - return _internal_mutable_method_name()->Add(); -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -ListRpcResponse::_internal_method_name() const { - return _impl_.method_name_; -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* -ListRpcResponse::_internal_mutable_method_name() { - return &_impl_.method_name_; -} - -// ------------------------------------------------------------------- - -// GetServiceRequest - -// string service_name = 1; -inline void GetServiceRequest::clear_service_name() { - _impl_.service_name_.ClearToEmpty(); -} -inline const std::string& GetServiceRequest::service_name() const { - // @@protoc_insertion_point(field_get:taotu.GetServiceRequest.service_name) - return _internal_service_name(); -} -template -inline PROTOBUF_ALWAYS_INLINE void GetServiceRequest::set_service_name(Arg_&& arg, - Args_... args) { - ; - _impl_.service_name_.Set(static_cast(arg), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:taotu.GetServiceRequest.service_name) -} -inline std::string* GetServiceRequest::mutable_service_name() { - std::string* _s = _internal_mutable_service_name(); - // @@protoc_insertion_point(field_mutable:taotu.GetServiceRequest.service_name) - return _s; -} -inline const std::string& GetServiceRequest::_internal_service_name() const { - return _impl_.service_name_.Get(); -} -inline void GetServiceRequest::_internal_set_service_name(const std::string& value) { - ; - - - _impl_.service_name_.Set(value, GetArenaForAllocation()); -} -inline std::string* GetServiceRequest::_internal_mutable_service_name() { - ; - return _impl_.service_name_.Mutable( GetArenaForAllocation()); -} -inline std::string* GetServiceRequest::release_service_name() { - // @@protoc_insertion_point(field_release:taotu.GetServiceRequest.service_name) - return _impl_.service_name_.Release(); -} -inline void GetServiceRequest::set_allocated_service_name(std::string* value) { - _impl_.service_name_.SetAllocated(value, GetArenaForAllocation()); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.service_name_.IsDefault()) { - _impl_.service_name_.Set("", GetArenaForAllocation()); - } - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:taotu.GetServiceRequest.service_name) -} - -// ------------------------------------------------------------------- - -// GetServiceResponse - -// .taotu.ErrorCode error = 1; -inline void GetServiceResponse::clear_error() { - _impl_.error_ = 0; -} -inline ::taotu::ErrorCode GetServiceResponse::error() const { - // @@protoc_insertion_point(field_get:taotu.GetServiceResponse.error) - return _internal_error(); -} -inline void GetServiceResponse::set_error(::taotu::ErrorCode value) { - _internal_set_error(value); - // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.error) -} -inline ::taotu::ErrorCode GetServiceResponse::_internal_error() const { - return static_cast<::taotu::ErrorCode>(_impl_.error_); -} -inline void GetServiceResponse::_internal_set_error(::taotu::ErrorCode value) { - ; - _impl_.error_ = value; -} - -// repeated string proto_file = 2; -inline int GetServiceResponse::_internal_proto_file_size() const { - return _impl_.proto_file_.size(); -} -inline int GetServiceResponse::proto_file_size() const { - return _internal_proto_file_size(); -} -inline void GetServiceResponse::clear_proto_file() { - _internal_mutable_proto_file()->Clear(); -} -inline std::string* GetServiceResponse::add_proto_file() { - std::string* _s = _internal_add_proto_file(); - // @@protoc_insertion_point(field_add_mutable:taotu.GetServiceResponse.proto_file) - return _s; -} -inline const std::string& GetServiceResponse::proto_file(int index) const { - // @@protoc_insertion_point(field_get:taotu.GetServiceResponse.proto_file) - return _internal_proto_file(index); -} -inline std::string* GetServiceResponse::mutable_proto_file(int index) { - // @@protoc_insertion_point(field_mutable:taotu.GetServiceResponse.proto_file) - return _internal_mutable_proto_file()->Mutable(index); -} -inline void GetServiceResponse::set_proto_file(int index, const std::string& value) { - _internal_mutable_proto_file()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::set_proto_file(int index, std::string&& value) { - _internal_mutable_proto_file()->Mutable(index)->assign(std::move(value)); - // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::set_proto_file(int index, const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_proto_file()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::set_proto_file(int index, const char* value, - std::size_t size) { - _internal_mutable_proto_file()->Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::set_proto_file(int index, absl::string_view value) { - _internal_mutable_proto_file()->Mutable(index)->assign(value.data(), - value.size()); - // @@protoc_insertion_point(field_set_string_piece:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::add_proto_file(const std::string& value) { - _internal_mutable_proto_file()->Add()->assign(value); - // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::add_proto_file(std::string&& value) { - _internal_mutable_proto_file()->Add(std::move(value)); - // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::add_proto_file(const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_proto_file()->Add()->assign(value); - // @@protoc_insertion_point(field_add_char:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::add_proto_file(const char* value, std::size_t size) { - _internal_mutable_proto_file()->Add()->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:taotu.GetServiceResponse.proto_file) -} -inline void GetServiceResponse::add_proto_file(absl::string_view value) { - _internal_mutable_proto_file()->Add()->assign(value.data(), value.size()); - // @@protoc_insertion_point(field_add_string_piece:taotu.GetServiceResponse.proto_file) -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -GetServiceResponse::proto_file() const { - // @@protoc_insertion_point(field_list:taotu.GetServiceResponse.proto_file) - return _internal_proto_file(); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* GetServiceResponse::mutable_proto_file() { - // @@protoc_insertion_point(field_mutable_list:taotu.GetServiceResponse.proto_file) - return _internal_mutable_proto_file(); -} -inline const std::string& GetServiceResponse::_internal_proto_file(int index) const { - return _internal_proto_file().Get(index); -} -inline std::string* GetServiceResponse::_internal_add_proto_file() { - return _internal_mutable_proto_file()->Add(); -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -GetServiceResponse::_internal_proto_file() const { - return _impl_.proto_file_; -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* -GetServiceResponse::_internal_mutable_proto_file() { - return &_impl_.proto_file_; -} - -// repeated string proto_file_name = 3; -inline int GetServiceResponse::_internal_proto_file_name_size() const { - return _impl_.proto_file_name_.size(); -} -inline int GetServiceResponse::proto_file_name_size() const { - return _internal_proto_file_name_size(); -} -inline void GetServiceResponse::clear_proto_file_name() { - _internal_mutable_proto_file_name()->Clear(); -} -inline std::string* GetServiceResponse::add_proto_file_name() { - std::string* _s = _internal_add_proto_file_name(); - // @@protoc_insertion_point(field_add_mutable:taotu.GetServiceResponse.proto_file_name) - return _s; -} -inline const std::string& GetServiceResponse::proto_file_name(int index) const { - // @@protoc_insertion_point(field_get:taotu.GetServiceResponse.proto_file_name) - return _internal_proto_file_name(index); -} -inline std::string* GetServiceResponse::mutable_proto_file_name(int index) { - // @@protoc_insertion_point(field_mutable:taotu.GetServiceResponse.proto_file_name) - return _internal_mutable_proto_file_name()->Mutable(index); -} -inline void GetServiceResponse::set_proto_file_name(int index, const std::string& value) { - _internal_mutable_proto_file_name()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::set_proto_file_name(int index, std::string&& value) { - _internal_mutable_proto_file_name()->Mutable(index)->assign(std::move(value)); - // @@protoc_insertion_point(field_set:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::set_proto_file_name(int index, const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_proto_file_name()->Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::set_proto_file_name(int index, const char* value, - std::size_t size) { - _internal_mutable_proto_file_name()->Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::set_proto_file_name(int index, absl::string_view value) { - _internal_mutable_proto_file_name()->Mutable(index)->assign(value.data(), - value.size()); - // @@protoc_insertion_point(field_set_string_piece:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::add_proto_file_name(const std::string& value) { - _internal_mutable_proto_file_name()->Add()->assign(value); - // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::add_proto_file_name(std::string&& value) { - _internal_mutable_proto_file_name()->Add(std::move(value)); - // @@protoc_insertion_point(field_add:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::add_proto_file_name(const char* value) { - ABSL_DCHECK(value != nullptr); - _internal_mutable_proto_file_name()->Add()->assign(value); - // @@protoc_insertion_point(field_add_char:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::add_proto_file_name(const char* value, std::size_t size) { - _internal_mutable_proto_file_name()->Add()->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:taotu.GetServiceResponse.proto_file_name) -} -inline void GetServiceResponse::add_proto_file_name(absl::string_view value) { - _internal_mutable_proto_file_name()->Add()->assign(value.data(), value.size()); - // @@protoc_insertion_point(field_add_string_piece:taotu.GetServiceResponse.proto_file_name) -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -GetServiceResponse::proto_file_name() const { - // @@protoc_insertion_point(field_list:taotu.GetServiceResponse.proto_file_name) - return _internal_proto_file_name(); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* GetServiceResponse::mutable_proto_file_name() { - // @@protoc_insertion_point(field_mutable_list:taotu.GetServiceResponse.proto_file_name) - return _internal_mutable_proto_file_name(); -} -inline const std::string& GetServiceResponse::_internal_proto_file_name(int index) const { - return _internal_proto_file_name().Get(index); -} -inline std::string* GetServiceResponse::_internal_add_proto_file_name() { - return _internal_mutable_proto_file_name()->Add(); -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -GetServiceResponse::_internal_proto_file_name() const { - return _impl_.proto_file_name_; -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* -GetServiceResponse::_internal_mutable_proto_file_name() { - return &_impl_.proto_file_name_; -} - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif // __GNUC__ - -// @@protoc_insertion_point(namespace_scope) -} // namespace taotu - - -PROTOBUF_NAMESPACE_OPEN - -template <> -struct is_proto_enum<::taotu::MessageType> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::taotu::MessageType>() { - return ::taotu::MessageType_descriptor(); -} -template <> -struct is_proto_enum<::taotu::ErrorCode> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::taotu::ErrorCode>() { - return ::taotu::ErrorCode_descriptor(); -} - -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_rpc_2eproto_2epb_2eh From 088dfe171e8d477653efa15e23a30d1cc12e51f4 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 22:22:06 -0400 Subject: [PATCH 27/78] [config] Add files to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index dc6b6b6d..d6cb97fd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .vscode/* build*/* .idea/* +src/rpc.pb* cmake-build-debug/* cmake-build-release/* CMakeLists.txt.user From 269d9dbe5395a571088420796f4f8eec34f231fb Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 22:23:21 -0400 Subject: [PATCH 28/78] [src] Develop RPC module --- src/rpc_codec.cc | 2 +- src/rpc_server.cc | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 65d2c5e5..440387a1 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -49,7 +49,7 @@ void RpcCodec::Send(Connecting& connection, const ::google::protobuf::Message& message) { IoBuffer io_buffer; FillEmptyBuffer(&io_buffer, message); - const_cast(connection).Send(&io_buffer); + connection.Send(&io_buffer); } void RpcCodec::OnMessage(Connecting& connection, IoBuffer* io_buffer, diff --git a/src/rpc_server.cc b/src/rpc_server.cc index c807df8a..2d1dde39 100644 --- a/src/rpc_server.cc +++ b/src/rpc_server.cc @@ -28,7 +28,31 @@ RpcServer::RpcServer(EventManagers* event_managers, }); } -void RpcServer::RegisterService(::google::protobuf::Service*) {} -void RpcServer::Start() {} +void RpcServer::RegisterService(::google::protobuf::Service* service) { + const auto service_descriptor = service->GetDescriptor(); + services_[service_descriptor->name()] = service; +} +void RpcServer::Start() { server_.Start(); } -void RpcServer::OnConnectionCallback(Connecting& connection) {} +void RpcServer::OnConnectionCallback(Connecting& connection) { + LOG_NOTICE("RpcServer - [ IP(%s), Port(%s) ] -> [ IP(%s), Port(%s) ] %s", + connection.GetLocalNetAddress().GetIp().c_str(), + std::to_string(connection.GetLocalNetAddress().GetPort()).c_str(), + connection.GetPeerNetAddress().GetIp().c_str(), + std::to_string(connection.GetPeerNetAddress().GetPort()).c_str(), + (connection.IsConnected() ? "UP" : "DOWN")); + if (connection.IsConnected()) { + std::shared_ptr rpc_channel = + std::make_shared(connection); + rpc_channel->SetServices(&services_); + connection.RegisterOnMessageCallback( + [&rpc_channel](Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time) { + rpc_channel->OnMessage(connection, io_buffer, receive_time); + }); + connection.SetContext>(rpc_channel); + } else { + connection.SetContext>( + std::shared_ptr()); + } +} From e6254248aa0517d8f7b0c90445bb7ff3a3272529 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 22:24:17 -0400 Subject: [PATCH 29/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 1dfbf74c..cbfce7ba 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,7 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev && sudo find / -name ProtobufConfig.cmake && sudo find / -name protobuf-config.cmake + run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually From 65ee5e5b66298bc53620cd03f1c4a9f766ebb4a0 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 22:24:56 -0400 Subject: [PATCH 30/78] [src] Modify CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b06317cc..434190be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -FIND_PACKAGE(Protobuf CONFIG REQUIRED) +FIND_PACKAGE(Protobuf REQUIRED) SET(PROTO_PATH "${CMAKE_SOURCE_DIR}/src/") SET(TIME_PROTO "${PROTO_PATH}/rpc.proto") From f28cb8399eaea6e2fcc1c6c2ab8a71ef28da6f9e Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 16 Aug 2023 22:30:28 -0400 Subject: [PATCH 31/78] [src] Modify CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 434190be..b06317cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -FIND_PACKAGE(Protobuf REQUIRED) +FIND_PACKAGE(Protobuf CONFIG REQUIRED) SET(PROTO_PATH "${CMAKE_SOURCE_DIR}/src/") SET(TIME_PROTO "${PROTO_PATH}/rpc.proto") From 5f9f4a15b37383e58335e72b3a19695716c4daac Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 19 Aug 2023 02:00:40 -0400 Subject: [PATCH 32/78] [src] Modify enum using --- src/connecting.cc | 34 +++++++++++++++++----------------- src/connecting.h | 10 +++++++--- src/connector.cc | 20 +++++++++++--------- src/connector.h | 6 +++--- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/connecting.cc b/src/connecting.cc index d8c1edd8..f27ce50b 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -29,7 +29,7 @@ Connecting::Connecting(EventManager* event_manager, int socket_fd, eventer_(event_manager->GetPoller(), socket_fd), local_address_(local_address), peer_address_(peer_address), - state_(kConnecting) { + state_(ConnectionState::kConnecting) { socketer_.SetKeepAlive(true); eventer_.RegisterReadCallback( [this](TimePoint receive_time) { this->DoReading(receive_time); }); @@ -71,7 +71,7 @@ void Connecting::DoWriting() { if (WriteCompleteCallback_) { WriteCompleteCallback_(*this); } - if (kDisconnecting == state_.load() && + if (ConnectionState::kDisconnecting == state_.load() && !eventer_ .HasWriteEvents()) { // If the state of this TCP connection is // disconnecting and the writing event of @@ -89,10 +89,10 @@ void Connecting::DoWriting() { } } void Connecting::DoClosing() { - if (state_.load() != kDisconnected) { + if (state_.load() != ConnectionState::kDisconnected) { LOG_DEBUG("Fd(%d) with state(\"%s\") is closing.", Fd(), GetConnectionStateInfo(state_).c_str()); - SetState(kDisconnected); + SetState(ConnectionState::kDisconnected); StopReadingWriting(); if (OnConnectionCallback_) { OnConnectionCallback_(*this); @@ -120,21 +120,21 @@ void Connecting::DoWithError() const { } void Connecting::OnEstablishing() { - if (kConnecting == + if (ConnectionState::kConnecting == state_.load()) { // This TCP connection can only be created once - SetState(kConnected); + SetState(ConnectionState::kConnected); OnConnectionCallback_(*this); StartReading(); } } void Connecting::Send(const void* message, size_t msg_len) { - if (kDisconnected == state_.load()) { + if (ConnectionState::kDisconnected == state_.load()) { LOG_ERROR("Fd(%d) is disconnected, so give up sending the message!!!", Fd()); return; } - if (kConnected == state_.load()) { + if (ConnectionState::kConnected == state_.load()) { ssize_t sent_bytes = 0; size_t unsent_bytes = msg_len; bool fault = false; // 'false' represents that there is no error @@ -188,8 +188,8 @@ void Connecting::Send(IoBuffer* io_buffer) { } void Connecting::ShutDownWrite() { - if (kConnected == state_.load()) { - SetState(kDisconnecting); + if (ConnectionState::kConnected == state_.load()) { + SetState(ConnectionState::kDisconnecting); if (!eventer_ .HasWriteEvents()) { // If the writing event is not paid attention // to, shut down the writing end (this end) @@ -199,8 +199,8 @@ void Connecting::ShutDownWrite() { } void Connecting::ForceClose() { - if (kDisconnected != state_.load()) { - SetState(kDisconnecting); + if (ConnectionState::kDisconnected != state_.load()) { + SetState(ConnectionState::kDisconnecting); DoClosing(); } } @@ -208,7 +208,7 @@ void Connecting::ForceClose() { // FIXME: Make it be effective in the condition that the connection has been // destroyed. void Connecting::ForceCloseAfter(int64_t delay_microseconds) { - if (kDisconnected != state_.load()) { + if (ConnectionState::kDisconnected != state_.load()) { event_manager_->RunAfter(delay_microseconds, [this]() { this->ForceClose(); }); } @@ -216,13 +216,13 @@ void Connecting::ForceCloseAfter(int64_t delay_microseconds) { std::string Connecting::GetConnectionStateInfo(ConnectionState state) { switch (state) { - case kDisconnected: + case ConnectionState::kDisconnected: return "Disconnected"; - case kConnecting: + case ConnectionState::kConnecting: return "Connecting"; - case kConnected: + case ConnectionState::kConnected: return "Connected"; - case kDisconnecting: + case ConnectionState::kDisconnecting: return "Disconnecting"; } return std::string{}; diff --git a/src/connecting.h b/src/connecting.h index 49135a61..977ad788 100644 --- a/src/connecting.h +++ b/src/connecting.h @@ -138,8 +138,12 @@ class Connecting : NonCopyableMovable { // Shut down the writing end (close half == stop writing indeed) void ShutDownWrite(); - bool IsConnected() const { return kConnected == state_.load(); } - bool IsDisconnected() const { return kDisconnected == state_.load(); } + bool IsConnected() const { + return ConnectionState::kConnected == state_.load(); + } + bool IsDisconnected() const { + return ConnectionState::kDisconnected == state_.load(); + } void SetTcpNoDelay(bool on) { socketer_.SetTcpNoDelay(on); } @@ -149,7 +153,7 @@ class Connecting : NonCopyableMovable { void ForceCloseAfter(int64_t delay_microseconds); private: - enum ConnectionState { + enum class ConnectionState { kDisconnected, kConnecting, kConnected, diff --git a/src/connector.cc b/src/connector.cc index 110d0198..f0d5bb49 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -25,10 +25,12 @@ #include "time_point.h" using namespace taotu; +namespace { enum { kMaxRetryDelayMicroseconds = 30 * 1000 * 1000, kInitRetryDelayMicroseconds = 500 * 1000, }; +} static struct sockaddr_in6 GetLocalSocketAddress6(int socket_fd) { struct sockaddr_in6 local_addr {}; ::memset(&local_addr, 0, sizeof(local_addr)); @@ -63,7 +65,7 @@ Connector::Connector(EventManager* event_manager, const NetAddress& server_address) : event_manager_(event_manager), server_address_(server_address), - state_(kDisconnected), + state_(ConnectState::kDisconnected), can_connect_(false), retry_delay_microseconds_(static_cast(kInitRetryDelayMicroseconds)) { } @@ -73,15 +75,15 @@ void Connector::Start() { Connect(); } void Connector::Restart() { - SetState(kDisconnected); + SetState(ConnectState::kDisconnected); retry_delay_microseconds_ = static_cast(kInitRetryDelayMicroseconds); Start(); } void Connector::Stop() { can_connect_ = false; - if (kConnecting == state_) { - SetState(kDisconnected); + if (ConnectState::kConnecting == state_) { + SetState(ConnectState::kDisconnected); DoRetrying(RemoveAndReset()); } } @@ -136,7 +138,7 @@ void Connector::Connect() { } } void Connector::DoConnecting(int conn_fd) { - SetState(kConnecting); + SetState(ConnectState::kConnecting); eventer_ = std::make_unique(event_manager_->GetPoller(), conn_fd); eventer_->RegisterWriteCallback([this]() { this->DoWriting(); }); eventer_->RegisterErrorCallback([this]() { this->DoWithError(); }); @@ -145,7 +147,7 @@ void Connector::DoConnecting(int conn_fd) { void Connector::DoRetrying(int conn_fd) { LOG_WARN("Connector fd(%d) is closing for retrying!", conn_fd); ::close(conn_fd); - SetState(kDisconnected); + SetState(ConnectState::kDisconnected); if (can_connect_) { LOG_DEBUG("Connector fd(%d) is retrying to connect.", conn_fd); event_manager_->RunAfter(retry_delay_microseconds_, @@ -159,7 +161,7 @@ void Connector::DoRetrying(int conn_fd) { } void Connector::DoWriting() { LOG_DEBUG("Connector fd(%d) is writing.", eventer_->Fd()); - if (kConnecting == state_) { + if (ConnectState::kConnecting == state_) { int conn_fd = RemoveAndReset(); int error = GetSocketError(conn_fd); if (error) { @@ -191,7 +193,7 @@ void Connector::DoWriting() { LOG_DEBUG("Connector fd(%d) is self-connected.", conn_fd); DoRetrying(conn_fd); } else { - SetState(kConnected); + SetState(ConnectState::kConnected); if (can_connect_ && NewConnectionCallback_) { NewConnectionCallback_(conn_fd); } else { @@ -203,7 +205,7 @@ void Connector::DoWriting() { void Connector::DoWithError() { LOG_ERROR("Connector fd(%d) has the error with the state(%d).", eventer_->Fd(), state_); - if (kConnecting == state_) { + if (ConnectState::kConnecting == state_) { int conn_fd = RemoveAndReset(); int error = GetSocketError(conn_fd); char errno_info[512]; diff --git a/src/connector.h b/src/connector.h index 0cf08044..a20f9ce2 100644 --- a/src/connector.h +++ b/src/connector.h @@ -67,19 +67,19 @@ class Connector : NonCopyableMovable { private: typedef std::unique_ptr EventerPtr; - enum State { kDisconnected, kConnecting, kConnected }; + enum class ConnectState { kDisconnected, kConnecting, kConnected }; // After successful connecting, call it to reset because the TCP connection's // file descriptor is disposable int RemoveAndReset(); - void SetState(State state) { state_ = state; } + void SetState(ConnectState state) { state_ = state; } // Pointer to the specific "EventManager" ("Reactor") EventManager* event_manager_; NetAddress server_address_; - State state_; + ConnectState state_; bool can_connect_; int retry_delay_microseconds_; From 06e1561aa77ecd93e6cf76f3417d67fe2d65b6fb Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 19 Aug 2023 02:05:15 -0400 Subject: [PATCH 33/78] [src] Add comments --- src/rpc_codec.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 440387a1..3b8adb40 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -145,7 +145,7 @@ RpcCodec::ErrorCode RpcCodec::Parse(const char* buffer, int length, ErrorCode error_code = ErrorCode::kNoError; if (ValidateChecksum(buffer, length)) { if (::memcmp(reinterpret_cast(buffer), tag_.data(), - tag_.size()) == 0) { // Parse from the buffer + tag_.size()) == 0) { // Check the tag (the message type) const char* data = buffer + tag_.size(); int32_t data_length = length - kChecksumLength - static_cast(tag_.size()); From c71fa0db433fc1fa2ea7ea01c1ae289e6fbe90c4 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 19 Aug 2023 11:51:20 -0400 Subject: [PATCH 34/78] [src] Make the connection pointer initialized when construct RpcChannel instance --- src/rpc_channel.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc_channel.cc b/src/rpc_channel.cc index 426165b5..f6da19ab 100644 --- a/src/rpc_channel.cc +++ b/src/rpc_channel.cc @@ -31,6 +31,7 @@ RpcChannel::RpcChannel() TimePoint time_point) { this->OnRpcMessage(connection, rpc_message, time_point); }), + connection_(nullptr), services_(nullptr) { LOG_INFO("RpcChannel::RpcChannel - %p", this); } From 65420b3f797fb4d523c6110a86705edaacdaf6e7 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 04:04:27 -0400 Subject: [PATCH 35/78] [src] Complete Sync RPC channel for RPC client --- src/connector.cc | 7 +- src/rpc_channel.cc | 158 ++++++++++++++++++++++++++++++++++++++------- src/rpc_channel.h | 60 ++++++++++++++--- src/rpc_codec.cc | 115 ++++++++++++++++++++++++++++----- src/rpc_codec.h | 107 +++++++++++++++++++++++------- src/rpc_server.cc | 10 +-- 6 files changed, 379 insertions(+), 78 deletions(-) diff --git a/src/connector.cc b/src/connector.cc index f0d5bb49..e454f4dc 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -91,6 +91,10 @@ void Connector::Connect() { int sock_fd = ::socket(server_address_.GetFamily(), SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_TCP); + if (sock_fd < 0) { + LOG_ERROR("Fail to initialize for connector!!!"); + return; + } #ifndef __linux__ int flags = ::fcntl(sock_fd, F_GETFL, 0); flags |= O_NONBLOCK; @@ -99,9 +103,6 @@ void Connector::Connect() { flags |= FD_CLOEXEC; ::fcntl(sock_fd, F_SETFD, flags); #endif - if (sock_fd < 0) { - LOG_ERROR("Fail to initialize for connector!!!"); - } int status = ::connect(sock_fd, server_address_.GetNetAddress(), server_address_.GetSize()); int saved_errno = (0 == status) ? 0 : errno; diff --git a/src/rpc_channel.cc b/src/rpc_channel.cc index f6da19ab..6cb9ee15 100644 --- a/src/rpc_channel.cc +++ b/src/rpc_channel.cc @@ -16,6 +16,7 @@ #include "logger.h" #include "rpc.pb.h" #include "spin_lock.h" +#include "time_point.h" using namespace taotu; @@ -25,17 +26,17 @@ const char kRpcTag[] = "RPC0"; } // namespace taotu -RpcChannel::RpcChannel() +RpcAsyncChannel::RpcAsyncChannel() : codec_([this](Connecting& connection, - const std::shared_ptr& rpc_message, - TimePoint time_point) { - this->OnRpcMessage(connection, rpc_message, time_point); + const std::shared_ptr& rpc_message_ptr, + TimePoint receive_time) { + this->OnRpcMessage(connection, rpc_message_ptr, receive_time); }), connection_(nullptr), services_(nullptr) { - LOG_INFO("RpcChannel::RpcChannel - %p", this); + LOG_INFO("RpcAsyncChannel::RpcAsyncChannel - %p", this); } -RpcChannel::RpcChannel(Connecting& connection) +RpcAsyncChannel::RpcAsyncChannel(Connecting& connection) : codec_([this](Connecting& connection, const std::shared_ptr& rpc_message, TimePoint time_point) { @@ -43,19 +44,23 @@ RpcChannel::RpcChannel(Connecting& connection) }), connection_(const_cast(&connection)), services_(nullptr) { - LOG_INFO("RpcChannel::RpcChannel - %p", this); + LOG_INFO("RpcAsyncChannel::RpcAsyncChannel - %p", this); } -RpcChannel::~RpcChannel() { - LOG_INFO("RpcChannel::~RpcChannel - %p", this); +RpcAsyncChannel::~RpcAsyncChannel() { + LOG_INFO("RpcAsyncChannel::~RpcAsyncChannel - %p", this); for (auto itr = outstanding_calls_.begin(); itr != outstanding_calls_.end(); ++itr) { auto outstanding_call = itr->second; - delete outstanding_call.response_message_; - delete outstanding_call.DoneCallback_; + if (outstanding_call.response_message_ != nullptr) { + delete outstanding_call.response_message_; + } + if (outstanding_call.DoneCallback_ != nullptr) { + delete outstanding_call.DoneCallback_; + } } } -void RpcChannel::CallMethod( +void RpcAsyncChannel::CallMethod( const ::google::protobuf::MethodDescriptor* method_descriptor, ::google::protobuf::RpcController* rpc_controller, const ::google::protobuf::Message* request_message, @@ -76,12 +81,12 @@ void RpcChannel::CallMethod( codec_.Send(*connection_, rpc_message); } -void RpcChannel::OnMessage(Connecting& connection, IoBuffer* io_buffer, - TimePoint receive_time) { +void RpcAsyncChannel::OnMessage(Connecting& connection, IoBuffer* io_buffer, + TimePoint receive_time) { codec_.OnMessage(connection, io_buffer, receive_time); } -void RpcChannel::OnRpcMessage( +void RpcAsyncChannel::OnRpcMessage( Connecting& connection, const std::shared_ptr& rpc_message_ptr, TimePoint receive_time) { RpcMessage& rpc_message = *rpc_message_ptr; @@ -123,11 +128,11 @@ void RpcChannel::OnRpcMessage( auto response_message_t = service->GetResponsePrototype(method_descriptor).New(); int64_t id = rpc_message.id(); - service->CallMethod( - method_descriptor, nullptr, request_message_ptr.get(), - response_message_t, - google::protobuf::NewCallback(this, &RpcChannel::DoneCallback, - response_message_t, id)); + service->CallMethod(method_descriptor, nullptr, + request_message_ptr.get(), response_message_t, + google::protobuf::NewCallback( + this, &RpcAsyncChannel::DoneCallback, + response_message_t, id)); error_code = NO_ERROR; } else { error_code = INVALID_REQUEST; @@ -152,8 +157,8 @@ void RpcChannel::OnRpcMessage( } } -void RpcChannel::DoneCallback(::google::protobuf::Message* response_message, - int64_t id) { +void RpcAsyncChannel::DoneCallback( + ::google::protobuf::Message* response_message, int64_t id) { std::unique_ptr response_message_ptr( response_message); RpcMessage rpc_message; @@ -162,3 +167,112 @@ void RpcChannel::DoneCallback(::google::protobuf::Message* response_message, rpc_message.set_response(response_message->SerializeAsString()); codec_.Send(*connection_, rpc_message); } + +RpcSyncChannel::RpcSyncChannel(const NetAddress& server_address) + : server_address_(server_address), + codec_([this](int sock_fd, const std::shared_ptr& rpc_message, + TimePoint receive_time) { + this->OnRpcMessage(sock_fd, rpc_message, receive_time); + }), + socket_fd_(::socket(server_address.GetFamily(), + SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP)), + services_(nullptr) { + LOG_INFO("RpcSyncChannel::RpcSyncChannel - %p", this); + if (socket_fd_ < 0) { + LOG_ERROR("Fail to initialize for the socket fd of new RpcSyncChannel!!!"); + ::exit(-1); + } +#ifndef __linux__ + int flags = ::fcntl(sock_fd, F_GETFL, 0); + flags |= FD_CLOEXEC; + ::fcntl(sock_fd, F_SETFD, flags); +#endif + if (::connect(socket_fd_, server_address_.GetNetAddress(), + server_address_.GetSize()) == -1) { + LOG_ERROR("RpcSyncChannel cannot connect to [ IP(%s), Port(%s) ]!!!", + server_address_.GetIp().c_str(), + std::to_string(server_address_.GetPort()).c_str()); + ::close(socket_fd_); + socket_fd_ = -100; + } +} +RpcSyncChannel::~RpcSyncChannel() { + LOG_INFO("RpcSyncChannel::~RpcSyncChannel - %p", this); + if (socket_fd_ >= 0) { + ::close(socket_fd_); + } + for (auto itr = outstanding_calls_.begin(); itr != outstanding_calls_.end(); + ++itr) { + auto outstanding_call = itr->second; + if (outstanding_call.response_message_ != nullptr) { + delete outstanding_call.response_message_; + } + if (outstanding_call.DoneCallback_ != nullptr) { + delete outstanding_call.DoneCallback_; + } + } +} + +void RpcSyncChannel::CallMethod( + const ::google::protobuf::MethodDescriptor* method_descriptor, + ::google::protobuf::RpcController* rpc_controller, + const ::google::protobuf::Message* request_message, + ::google::protobuf::Message* response_message, + ::google::protobuf::Closure* DoneCallback) { + std::shared_ptr rpc_message; + rpc_message->set_type(REQUEST); + int64_t id = id_.fetch_add(1) + 1; + rpc_message->set_id(id); + rpc_message->set_service(method_descriptor->service()->name()); + rpc_message->set_method(method_descriptor->name()); + rpc_message->set_request(request_message->SerializeAsString()); + OutstandingCall outstanding_call = {response_message, DoneCallback}; + { + LockGuard lock_guard(outstanding_calls_lock_); + outstanding_calls_[id] = outstanding_call; + } + if (socket_fd_ < 0) { + return; + } + codec_.Send(socket_fd_, *rpc_message); + if (socket_fd_ < 0) { + return; + } + OnMessage(socket_fd_, &io_buffer_, TimePoint{}); +} + +void RpcSyncChannel::OnMessage(int sock_fd, IoBuffer* io_buffer, + TimePoint receive_time) { + codec_.OnMessage(sock_fd, io_buffer, receive_time); +} + +void RpcSyncChannel::OnRpcMessage( + int sock_fd, const std::shared_ptr& rpc_message_ptr, + TimePoint receive_time) { + RpcMessage& rpc_message = *rpc_message_ptr; + if (rpc_message.type() == RESPONSE) { + int64_t id = rpc_message.id(); + OutstandingCall outstanding_call = {nullptr, nullptr}; + { + LockGuard lock_guard(outstanding_calls_lock_); + auto itr = outstanding_calls_.find(id); + if (itr != outstanding_calls_.end()) { // Find the id + outstanding_call = itr->second; + outstanding_calls_.erase(itr); + } + } + if (outstanding_call.response_message_ != nullptr) { + std::unique_ptr response_message_ptr( + outstanding_call.response_message_); + if (rpc_message.has_response()) { + outstanding_call.response_message_->ParseFromString( + rpc_message.response()); + } + if (outstanding_call.DoneCallback_ != nullptr) { + outstanding_call.DoneCallback_->Run(); + } + } + } else { + LOG_ERROR("RpcSyncClient - Rpc message type is not RESPONSE!!!"); + } +} diff --git a/src/rpc_channel.h b/src/rpc_channel.h index 1ea80477..f8c85583 100644 --- a/src/rpc_channel.h +++ b/src/rpc_channel.h @@ -1,8 +1,8 @@ /** * @file rpc_channel.h * @author Sigma711 (sigma711 at foxmail dot com) - * @brief Declarations of class "RpcChannel" which represents the single RPC - * message communication pipe. + * @brief Declarations of class "RpcAsyncChannel" and "RpcSyncChannel" which + * represents the single RPC message communication pipe. * @date 2023-07-21 * * @copyright Copyright (c) 2023 Sigma711 @@ -20,6 +20,7 @@ #include "connecting.h" #include "io_buffer.h" +#include "net_address.h" #include "rpc.pb.h" #include "rpc_codec.h" #include "spin_lock.h" @@ -48,14 +49,15 @@ namespace taotu { extern const char kRpcTag[]; /** - * @brief "RpcChannel" represents a communication pipe to a RPC service. + * @brief "RpcAsyncChannel" represents a async communication pipe to a RPC + * service. * */ -class RpcChannel : public ::google::protobuf::RpcChannel { +class RpcAsyncChannel : public ::google::protobuf::RpcChannel { public: - RpcChannel(); - explicit RpcChannel(Connecting& connection); - ~RpcChannel(); + RpcAsyncChannel(); + explicit RpcAsyncChannel(Connecting& connection); + ~RpcAsyncChannel(); void SetConnection(Connecting& connection) { connection_ = &connection; } @@ -68,7 +70,7 @@ class RpcChannel : public ::google::protobuf::RpcChannel { ::google::protobuf::RpcController* rpc_controller, const ::google::protobuf::Message* request_message, ::google::protobuf::Message* response_message, - ::google::protobuf::Closure* DoneCallback); + ::google::protobuf::Closure* DoneCallback) override; void OnMessage(Connecting& connection, IoBuffer* io_buffer, TimePoint receive_time); @@ -96,6 +98,48 @@ class RpcChannel : public ::google::protobuf::RpcChannel { services_; }; +/** + * @brief "RpcSyncChannel" represents a sync communication pipe to a RPC + * service. + * + */ +class RpcSyncChannel : public ::google::protobuf::RpcChannel { + public: + explicit RpcSyncChannel(const NetAddress& server_address); + ~RpcSyncChannel(); + + void CallMethod(const ::google::protobuf::MethodDescriptor* method_descriptor, + ::google::protobuf::RpcController* rpc_controller, + const ::google::protobuf::Message* request_message, + ::google::protobuf::Message* response_message, + ::google::protobuf::Closure* DoneCallback) override; + + void OnMessage(int sock_fd, IoBuffer* io_buffer, TimePoint receive); + + private: + void OnRpcMessage(int sock_fd, + const std::shared_ptr& rpc_message_ptr, + TimePoint receive_time); + + struct OutstandingCall { + ::google::protobuf::Message* response_message_; + ::google::protobuf::Closure* DoneCallback_; + }; + + const NetAddress& server_address_; + + RpcCodecT codec_; + int socket_fd_; + IoBuffer io_buffer_; + std::atomic_int64_t id_; + + MutexLock outstanding_calls_lock_; + std::unordered_map outstanding_calls_; + + const std::unordered_map* + services_; +}; + } // namespace taotu #endif // !TAOTU_SRC_RPC_CHANNEL_H_ diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 3b8adb40..869663cc 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -13,9 +13,8 @@ #include #include #include +#include #include - -#include #ifdef __MACH__ #include #define htobe16(x) OSSwapHostToBigInt16(x) @@ -43,6 +42,23 @@ int ProtobufVersionCheck() { } int __attribute__((unused)) dummy = ProtobufVersionCheck(); +static bool CheckSocketStatusValid(int sock_fd) { + if (sock_fd < 0) { + return false; + } + int error; + socklen_t len = sizeof(error); + if (::getsockopt(sock_fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { + LOG_ERROR("Fd(%d) - getsockopt() failed!", sock_fd); + return false; + } + if (error != 0) { + LOG_ERROR("Fd(%d) - errno(%d)!", sock_fd, error); + return false; + } + return true; +} + } // namespace void RpcCodec::Send(Connecting& connection, @@ -51,6 +67,18 @@ void RpcCodec::Send(Connecting& connection, FillEmptyBuffer(&io_buffer, message); connection.Send(&io_buffer); } +void RpcCodec::Send(int sock_fd, const ::google::protobuf::Message& message) { + if (!CheckSocketStatusValid(sock_fd)) { + return; + } + IoBuffer io_buffer; + FillEmptyBuffer(&io_buffer, message); + auto buffer_size = io_buffer.GetReadableBytes(); + while (buffer_size > 0) { + auto bytes_sent = io_buffer.WriteToFd(sock_fd); + buffer_size -= bytes_sent; + } +} void RpcCodec::OnMessage(Connecting& connection, IoBuffer* io_buffer, TimePoint receive_time) { @@ -58,16 +86,16 @@ void RpcCodec::OnMessage(Connecting& connection, IoBuffer* io_buffer, static_cast(kMinMessageLength + kHeaderLength)) { const int32_t len = io_buffer->GetReadableInt32(); if (len > kMaxMessageLength || len < kMinMessageLength) { - ErrCallback_(connection, io_buffer, receive_time, - ErrorCode::kInvalidLength); + AsyncErrCallback_(connection, io_buffer, receive_time, + ErrorCode::kInvalidLength); break; } else if (io_buffer->GetReadableBytes() >= static_cast(kHeaderLength + len)) { - if (RawCallback_ && - !RawCallback_(connection, - std::string_view(io_buffer->GetReadablePosition(), - kHeaderLength + len), - receive_time)) { + if (AsyncRawCallback_ && + !AsyncRawCallback_(connection, + std::string_view(io_buffer->GetReadablePosition(), + kHeaderLength + len), + receive_time)) { io_buffer->Refresh(kHeaderLength + len); continue; } @@ -75,10 +103,10 @@ void RpcCodec::OnMessage(Connecting& connection, IoBuffer* io_buffer, ErrorCode error_code = Parse( io_buffer->GetReadablePosition() + kHeaderLength, len, message.get()); if (error_code == ErrorCode::kNoError) { - MessageCallback_(connection, message, receive_time); + AsyncMessageCallback_(connection, message, receive_time); io_buffer->Refresh(kHeaderLength + len); } else { - ErrCallback_(connection, io_buffer, receive_time, error_code); + AsyncErrCallback_(connection, io_buffer, receive_time, error_code); break; } } else { @@ -86,6 +114,49 @@ void RpcCodec::OnMessage(Connecting& connection, IoBuffer* io_buffer, } } } +void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer, + TimePoint receive_time) { + if (!CheckSocketStatusValid(sock_fd)) { + return; + } + int saved_errno = 0; // FIXME: error check + const ssize_t min_header_len = + static_cast(kMinMessageLength + kHeaderLength); + while (min_header_len >= io_buffer->GetReadableBytes()) { + io_buffer->ReadFromFd(sock_fd, &saved_errno); + if (saved_errno != 0) { + LOG_ERROR("RpcCodec::OnMessage() - Fd(%d) with errno(%d)", sock_fd, + saved_errno); + } + } + const int32_t len = io_buffer->GetReadableInt32(); + if (len > kMaxMessageLength || len < kMinMessageLength) { + SyncErrCallback_(sock_fd, io_buffer, receive_time, + ErrorCode::kInvalidLength); + return; + } + while (io_buffer->GetReadableBytes() <= + static_cast(kHeaderLength + len)) { + io_buffer->ReadFromFd(sock_fd, &saved_errno); + } + if (AsyncRawCallback_ && + !SyncRawCallback_(sock_fd, + std::string_view(io_buffer->GetReadablePosition(), + kHeaderLength + len), + receive_time)) { + io_buffer->Refresh(kHeaderLength + len); + return; + } + std::shared_ptr<::google::protobuf::Message> message(prototype_->New()); + ErrorCode error_code = Parse(io_buffer->GetReadablePosition() + kHeaderLength, + len, message.get()); + if (error_code == ErrorCode::kNoError) { + SyncMessageCallback_(sock_fd, message, receive_time); + io_buffer->Refresh(kHeaderLength + len); + } else { + SyncErrCallback_(sock_fd, io_buffer, receive_time, error_code); + } +} bool RpcCodec::ParseFromBuffer(std::string_view buffer, ::google::protobuf::Message* message) { @@ -112,6 +183,7 @@ int RpcCodec::Serialize2Buffer(const ::google::protobuf::Message& message, } namespace { + const std::string kNoErrorStr = "NoError"; const std::string kInvalidLengthStr = "InvalidLength"; const std::string kCheckSumErrorStr = "CheckSumError"; @@ -119,6 +191,7 @@ const std::string kInvalidNameLenStr = "InvalidNameLen"; const std::string kUnknownMessageTypeStr = "UnknownMessageType"; const std::string kParseErrorStr = "ParseError"; const std::string kUnknownErrorStr = "UnknownError"; + } // namespace const std::string& RpcCodec::ErrorCode2String(ErrorCode error_code) { @@ -145,7 +218,7 @@ RpcCodec::ErrorCode RpcCodec::Parse(const char* buffer, int length, ErrorCode error_code = ErrorCode::kNoError; if (ValidateChecksum(buffer, length)) { if (::memcmp(reinterpret_cast(buffer), tag_.data(), - tag_.size()) == 0) { // Check the tag (the message type) + tag_.size()) == 0) { // Check the tag (data switch protocol) const char* data = buffer + tag_.size(); int32_t data_length = length - kChecksumLength - static_cast(tag_.size()); @@ -185,12 +258,24 @@ int32_t RpcCodec::AsInt32(const char* buffer) { ::memcpy(&be32, buffer, sizeof(be32)); return be32toh(be32); } -void RpcCodec::DefaultErrorCallback(Connecting& connection, IoBuffer* io_buffer, - TimePoint time_point, - ErrorCode error_code) { +void RpcCodec::AsyncDefaultErrorCallback(Connecting& connection, + IoBuffer* io_buffer, + TimePoint time_point, + ErrorCode error_code) { LOG_ERROR("RpcCodec::DefaultErrorCallback - %s", ErrorCode2String(error_code)); if (connection.IsConnected()) { const_cast(connection).ShutDownWrite(); } } +void RpcCodec::SyncDefaultErrorCallback(int sock_fd, IoBuffer* io_buffer, + TimePoint time_point, + ErrorCode error_code) { + LOG_ERROR("RpcCodec::DefaultErrorCallback - %s", + ErrorCode2String(error_code)); + if (!CheckSocketStatusValid(sock_fd)) { + LOG_ERROR( + "RpcCodec::SyncDefaultErrorCallback() - Fd(%d) - socket invalid!!!", + sock_fd); + } +} diff --git a/src/rpc_codec.h b/src/rpc_codec.h index 7389e090..a4eb1033 100644 --- a/src/rpc_codec.h +++ b/src/rpc_codec.h @@ -67,32 +67,52 @@ class RpcCodec : NonCopyableMovable { typedef std::function&, TimePoint)> - ProtobufMessageCallback; + AsyncProtobufMessageCallback; + typedef std::function&, TimePoint)> + SyncProtobufMessageCallback; typedef std::function - RawMessageCallback; + AsyncRawMessageCallback; + typedef std::function + SyncRawMessageCallback; typedef std::function - ErrorCallback; - + AsyncErrorCallback; + typedef std::function + SyncErrorCallback; + + RpcCodec( + const ::google::protobuf::Message* prototype, std::string_view tag_arg, + const AsyncProtobufMessageCallback& AsyncMessageCallback, + const AsyncRawMessageCallback& RawCallback = AsyncRawMessageCallback{}, + const AsyncErrorCallback& ErrCallback = AsyncDefaultErrorCallback) + : prototype_(prototype), + tag_(tag_arg), + kMinMessageLength(tag_arg.size() + kChecksumLength), + AsyncMessageCallback_(AsyncMessageCallback), + AsyncRawCallback_(RawCallback), + AsyncErrCallback_(ErrCallback) {} RpcCodec(const ::google::protobuf::Message* prototype, std::string_view tag_arg, - const ProtobufMessageCallback& MessageCallback, - const RawMessageCallback& RawCallback = RawMessageCallback{}, - const ErrorCallback& ErrCallback = DefaultErrorCallback) + const SyncProtobufMessageCallback& SyncMessageCallback, + const SyncRawMessageCallback& RawCallback = SyncRawMessageCallback{}, + const SyncErrorCallback& ErrCallback = SyncDefaultErrorCallback) : prototype_(prototype), tag_(tag_arg), kMinMessageLength(tag_arg.size() + kChecksumLength), - MessageCallback_(MessageCallback), - RawCallback_(RawCallback), - ErrCallback_(ErrCallback) {} + SyncMessageCallback_(SyncMessageCallback), + SyncRawCallback_(RawCallback), + SyncErrCallback_(ErrCallback) {} virtual ~RpcCodec() = default; const std::string& GetTag() const { return tag_; } void Send(Connecting& connection, const ::google::protobuf::Message& message); + void Send(int sock_fd, const ::google::protobuf::Message& message); void OnMessage(Connecting& connection, IoBuffer* io_buffer, TimePoint receive_time); + void OnMessage(int sock_fd, IoBuffer* io_buffer, TimePoint receive_time); virtual bool ParseFromBuffer(std::string_view buffer, ::google::protobuf::Message* message); @@ -109,17 +129,25 @@ class RpcCodec : NonCopyableMovable { static int32_t Checksum(const void* buffer, int length); static bool ValidateChecksum(const char* buffer, int length); static int32_t AsInt32(const char* buffer); - static void DefaultErrorCallback(Connecting& connection, IoBuffer* io_buffer, - TimePoint time_point, ErrorCode error_code); + static void AsyncDefaultErrorCallback(Connecting& connection, + IoBuffer* io_buffer, + TimePoint time_point, + ErrorCode error_code); + static void SyncDefaultErrorCallback(int sock_Fd, IoBuffer* io_buffer, + TimePoint time_point, + ErrorCode error_code); private: const ::google::protobuf::Message* prototype_; const std::string tag_; const int kMinMessageLength; - ProtobufMessageCallback MessageCallback_; - RawMessageCallback RawCallback_; - ErrorCallback ErrCallback_; + AsyncProtobufMessageCallback AsyncMessageCallback_; + SyncProtobufMessageCallback SyncMessageCallback_; + AsyncRawMessageCallback AsyncRawCallback_; + SyncRawMessageCallback SyncRawCallback_; + AsyncErrorCallback AsyncErrCallback_; + SyncErrorCallback SyncErrCallback_; }; /** @@ -132,15 +160,20 @@ class RpcCodecT { public: typedef std::function&, TimePoint)> - ProtobufMessageCallback; - typedef RpcCodec::RawMessageCallback RawMessageCallback; - typedef RpcCodec::ErrorCallback ErrorCallback; + AsyncProtobufMessageCallback; + typedef std::function&, TimePoint)> + SyncProtobufMessageCallback; + typedef RpcCodec::AsyncRawMessageCallback AsyncRawMessageCallback; + typedef RpcCodec::SyncRawMessageCallback SyncRawMessageCallback; + typedef RpcCodec::AsyncErrorCallback AsyncErrorCallback; + typedef RpcCodec::SyncErrorCallback SyncErrorCallback; explicit RpcCodecT( - const ProtobufMessageCallback& MessageCallback, - const RawMessageCallback& RawCallback = RawMessageCallback{}, - const ErrorCallback& ErrCallback = RpcCodec::DefaultErrorCallback) - : MessageCallback_(MessageCallback), + const AsyncProtobufMessageCallback& AsyncMessageCallback, + const AsyncRawMessageCallback& RawCallback = AsyncRawMessageCallback{}, + const AsyncErrorCallback& ErrCallback = + RpcCodec::AsyncDefaultErrorCallback) + : AsyncMessageCallback_(AsyncMessageCallback), codec_( &MSG::default_instance(), TAG, [this](Connecting& connection, @@ -149,23 +182,46 @@ class RpcCodecT { this->OnRpcMessage(connection, message, receive_time); }, RawCallback, ErrCallback) {} + explicit RpcCodecT( + const SyncProtobufMessageCallback& SyncMessageCallback, + const SyncRawMessageCallback& RawCallback = SyncRawMessageCallback{}, + const SyncErrorCallback& ErrCallback = RpcCodec::SyncDefaultErrorCallback) + : SyncMessageCallback_(SyncMessageCallback), + codec_( + &MSG::default_instance(), TAG, + [this](int sock_fd, + const std::shared_ptr<::google::protobuf::Message>& message, + TimePoint receive_time) { + this->OnRpcMessage(sock_fd, message, receive_time); + }, + RawCallback, ErrCallback) {} const std::string& GetTag() const { return codec_.GetTag(); } void Send(Connecting& connection, const MSG& message) { codec_.Send(connection, message); } + void Send(int sock_fd, const MSG& message) { codec_.Send(sock_fd, message); } void OnMessage(Connecting& connection, IoBuffer* io_buffer, TimePoint receive_time) { codec_.OnMessage(connection, io_buffer, receive_time); } + void OnMessage(int sock_fd, IoBuffer* io_buffer, TimePoint receive_time) { + codec_.OnMessage(sock_fd, io_buffer, receive_time); + } void OnRpcMessage(Connecting& connection, const std::shared_ptr<::google::protobuf::Message>& message, TimePoint receive_time) { - MessageCallback_(connection, std::dynamic_pointer_cast(message), - receive_time); + AsyncMessageCallback_(connection, std::dynamic_pointer_cast(message), + receive_time); + } + void OnRpcMessage(int sock_fd, + const std::shared_ptr<::google::protobuf::Message>& message, + TimePoint receive_time) { + SyncMessageCallback_(sock_fd, std::dynamic_pointer_cast(message), + receive_time); } void FillEmptyBuffer(IoBuffer* io_buffer, const MSG& message) { @@ -173,7 +229,8 @@ class RpcCodecT { } private: - ProtobufMessageCallback MessageCallback_; + AsyncProtobufMessageCallback AsyncMessageCallback_; + SyncProtobufMessageCallback SyncMessageCallback_; RpcCodec codec_; }; diff --git a/src/rpc_server.cc b/src/rpc_server.cc index 2d1dde39..0544e43f 100644 --- a/src/rpc_server.cc +++ b/src/rpc_server.cc @@ -42,17 +42,17 @@ void RpcServer::OnConnectionCallback(Connecting& connection) { std::to_string(connection.GetPeerNetAddress().GetPort()).c_str(), (connection.IsConnected() ? "UP" : "DOWN")); if (connection.IsConnected()) { - std::shared_ptr rpc_channel = - std::make_shared(connection); + std::shared_ptr rpc_channel = + std::make_shared(connection); rpc_channel->SetServices(&services_); connection.RegisterOnMessageCallback( [&rpc_channel](Connecting& connection, IoBuffer* io_buffer, TimePoint receive_time) { rpc_channel->OnMessage(connection, io_buffer, receive_time); }); - connection.SetContext>(rpc_channel); + connection.SetContext>(rpc_channel); } else { - connection.SetContext>( - std::shared_ptr()); + connection.SetContext>( + std::shared_ptr()); } } From d52b30270f1df11a9fe8cdec20ace70308277c06 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 07:47:03 -0400 Subject: [PATCH 36/78] [CI/CD] Add dependencies for installing --- .github/workflows/c-cpp.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index cbfce7ba..5fcb62b8 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -26,7 +26,9 @@ jobs: run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install - name: cmake working-directory: build - run: cmake .. + run: | + export CMAKE_PREFIX_PATH=/usr/local/:/usr/:$CMAKE_PREFIX_PATH:/ + cmake .. - name: make working-directory: build run: make From 561e2131d2923b20547015550055c77e17bd4581 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 07:49:57 -0400 Subject: [PATCH 37/78] [CI/CD] Modify dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 5fcb62b8..fa72888d 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -27,7 +27,7 @@ jobs: - name: cmake working-directory: build run: | - export CMAKE_PREFIX_PATH=/usr/local/:/usr/:$CMAKE_PREFIX_PATH:/ + export CMAKE_PREFIX_PATH=`pkg-config --variable=prefix protobuf`:$CMAKE_PREFIX_PATH:/ cmake .. - name: make working-directory: build From 9677a34e9e06307fe48a7f148143696d2b5631c3 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 07:52:41 -0400 Subject: [PATCH 38/78] [CI/CD] Modify dependencies for installing --- .github/workflows/c-cpp.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index fa72888d..3edf58f4 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -26,9 +26,7 @@ jobs: run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install - name: cmake working-directory: build - run: | - export CMAKE_PREFIX_PATH=`pkg-config --variable=prefix protobuf`:$CMAKE_PREFIX_PATH:/ - cmake .. + run: cmake -DCMAKE_PREFIX_PATH=`pkg-config --variable=prefix protobuf`:$CMAKE_PREFIX_PATH -DCMAKE_BUILD_TYPE=Release .. - name: make working-directory: build run: make From d38a8f188adb240a46be3a5bb809bd9eb2cf3300 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 11:03:28 -0400 Subject: [PATCH 39/78] [CI/CD] Modify dependencies for installing --- .github/workflows/c-cpp.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 3edf58f4..11ad3513 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -26,7 +26,9 @@ jobs: run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install - name: cmake working-directory: build - run: cmake -DCMAKE_PREFIX_PATH=`pkg-config --variable=prefix protobuf`:$CMAKE_PREFIX_PATH -DCMAKE_BUILD_TYPE=Release .. + run: | + echo `pkg-config --variable=prefix protobuf` + cmake -DProtobuf_DIR=`pkg-config --variable=prefix protobuf`:$CMAKE_PREFIX_PATH -DCMAKE_BUILD_TYPE=Release .. - name: make working-directory: build run: make From d966a11d2b6190e0fde78627f2879386943f8a3b Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 11:05:50 -0400 Subject: [PATCH 40/78] [CI/CD] Modify dependencies for installing --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 11ad3513..4c709548 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -28,7 +28,7 @@ jobs: working-directory: build run: | echo `pkg-config --variable=prefix protobuf` - cmake -DProtobuf_DIR=`pkg-config --variable=prefix protobuf`:$CMAKE_PREFIX_PATH -DCMAKE_BUILD_TYPE=Release .. + cmake -DProtobuf_DIR=/usr -DCMAKE_BUILD_TYPE=Release .. - name: make working-directory: build run: make From c79dcad698520134c325511fbc6812c6454877d5 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 11:44:23 -0400 Subject: [PATCH 41/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 4c709548..3df2110b 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -18,7 +18,16 @@ jobs: - name: init run: mkdir build - name: Install Protobuf - run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev + run: | + sudo apt-get install libtool pkg-config wget + wget https://github.com/protocolbuffers/protobuf/archive/refs/tags/v24.1.tar.gz + tar -zxvf v24.1.tar.gz + cd protobuf-24.1 + ./configure + make + make check + sudo make install + sudo ldconfig - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually @@ -26,9 +35,7 @@ jobs: run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install - name: cmake working-directory: build - run: | - echo `pkg-config --variable=prefix protobuf` - cmake -DProtobuf_DIR=/usr -DCMAKE_BUILD_TYPE=Release .. + run: cmake -DProtobuf_DIR=`pkg-config --variable=prefix protobuf` -DCMAKE_BUILD_TYPE=Release .. - name: make working-directory: build run: make From 31f2dff7ea84671cab66920a6b5f029b7958dd38 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 11:47:09 -0400 Subject: [PATCH 42/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 3df2110b..d412091d 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -23,7 +23,9 @@ jobs: wget https://github.com/protocolbuffers/protobuf/archive/refs/tags/v24.1.tar.gz tar -zxvf v24.1.tar.gz cd protobuf-24.1 - ./configure + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release .. make make check sudo make install From cb6d3784bd2d74bfe35bc67f00e90c41932e64c4 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 11:48:26 -0400 Subject: [PATCH 43/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index d412091d..11bd7b6b 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -25,7 +25,7 @@ jobs: cd protobuf-24.1 mkdir build cd build - cmake -DCMAKE_BUILD_TYPE=Release .. + cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. make make check sudo make install From 04980ac74d5e1670cab003d9ac6299dd3efbc601 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 17:09:45 -0400 Subject: [PATCH 44/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 11bd7b6b..7e47e044 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -19,15 +19,13 @@ jobs: run: mkdir build - name: Install Protobuf run: | - sudo apt-get install libtool pkg-config wget - wget https://github.com/protocolbuffers/protobuf/archive/refs/tags/v24.1.tar.gz - tar -zxvf v24.1.tar.gz - cd protobuf-24.1 + sudo apt-get install libtool pkg-config wget git bazel + git clone --recursive https://github.com/protocolbuffers/protobuf/releases/latest + cd protobuf mkdir build cd build cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. make - make check sudo make install sudo ldconfig - name: Install gtest manually From 5cd8330434eb05057ebe8be06a01ad29aec865db Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 22 Aug 2023 17:10:54 -0400 Subject: [PATCH 45/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 7e47e044..b8366d86 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -19,7 +19,7 @@ jobs: run: mkdir build - name: Install Protobuf run: | - sudo apt-get install libtool pkg-config wget git bazel + sudo apt-get install libtool pkg-config wget git git clone --recursive https://github.com/protocolbuffers/protobuf/releases/latest cd protobuf mkdir build From 24f0dcc0a319768d1f6462172debbcd0949ecbbc Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Thu, 24 Aug 2023 21:20:34 -0400 Subject: [PATCH 46/78] [src && example] Unroot ThreadPool from Server --- example/chat_room/chat_server.cc | 6 ++---- example/chat_room/chat_server.h | 2 +- example/chat_room/server_main.cc | 12 ++---------- example/http_server/http_server.cc | 6 ++---- example/http_server/http_server.h | 2 +- example/http_server/main.cc | 16 ++-------------- example/pingpong/pingpong_server.cc | 6 ++---- example/pingpong/pingpong_server.h | 3 +-- example/pingpong/server_main.cc | 12 ++---------- example/simple_discard/discard.cc | 6 ++---- example/simple_discard/discard.h | 3 +-- example/simple_discard/main.cc | 12 ++---------- example/simple_echo/echo.cc | 6 ++---- example/simple_echo/echo.h | 2 +- example/simple_echo/main.cc | 12 ++---------- example/simple_time/main.cc | 12 ++---------- example/simple_time/time.cc | 6 ++---- example/simple_time/time.h | 2 +- src/server.cc | 3 +-- src/server.h | 8 +------- 20 files changed, 32 insertions(+), 105 deletions(-) diff --git a/example/chat_room/chat_server.cc b/example/chat_room/chat_server.cc index 4110018a..6b17dc10 100644 --- a/example/chat_room/chat_server.cc +++ b/example/chat_room/chat_server.cc @@ -13,12 +13,10 @@ #include ChatServer::ChatServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) + bool should_reuse_port, size_t io_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique(&event_managers_, listen_address, - should_reuse_port, - calculation_thread_amount)), + should_reuse_port)), codec_([this](taotu::Connecting& connection, const std::string& message, taotu::TimePoint time_point) { this->OnCodecMessage(connection, message, time_point); diff --git a/example/chat_room/chat_server.h b/example/chat_room/chat_server.h index c1370c7e..416b03ee 100644 --- a/example/chat_room/chat_server.h +++ b/example/chat_room/chat_server.h @@ -23,7 +23,7 @@ class ChatServer : taotu::NonCopyableMovable { typedef std::vector EventManagers; ChatServer(const taotu::NetAddress& listen_address, bool should_reuse_port, - size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); + size_t io_thread_amount = 3); ~ChatServer(); // Start the server diff --git a/example/chat_room/server_main.cc b/example/chat_room/server_main.cc index 3de83172..1d8f8630 100644 --- a/example/chat_room/server_main.cc +++ b/example/chat_room/server_main.cc @@ -13,8 +13,7 @@ #include "chat_server.h" // Call it by: -// './chat_server [port [amount-of-I/O-threads -// [amount-of-calculation-threads]]]' +// './chat_server [port [amount-of-I/O-threads]]' int main(int argc, char* argv[]) { taotu::START_LOG("server_main_log.txt"); if (1 == argc) { @@ -25,18 +24,11 @@ int main(int argc, char* argv[]) { std::stoi(std::string{argv[1]}))}, false}; chat_server.Start(); - } else if (3 == argc) { - ChatServer chat_server{ - taotu::NetAddress{ - static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]}))}; - chat_server.Start(); } else { ChatServer chat_server{ taotu::NetAddress{ static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]})), - static_cast(std::stoi(std::string{argv[3]}))}; + false, static_cast(std::stoi(std::string{argv[2]}))}; chat_server.Start(); } return 0; diff --git a/example/http_server/http_server.cc b/example/http_server/http_server.cc index 4fe0f9d6..8c04f54c 100644 --- a/example/http_server/http_server.cc +++ b/example/http_server/http_server.cc @@ -16,12 +16,10 @@ #include "http_response.h" HttpServer::HttpServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) + bool should_reuse_port, size_t io_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique(&event_managers_, listen_address, - should_reuse_port, - calculation_thread_amount)) { + should_reuse_port)) { server_->SetConnectionCallback([this](taotu::Connecting& connection) { this->OnConnectionCallback(connection); }); diff --git a/example/http_server/http_server.h b/example/http_server/http_server.h index 09642aac..36c99c8a 100644 --- a/example/http_server/http_server.h +++ b/example/http_server/http_server.h @@ -23,7 +23,7 @@ class HttpServer : taotu::NonCopyableMovable { typedef std::vector EventManagers; HttpServer(const taotu::NetAddress& listen_address, bool should_reuse_port, - size_t io_thread_amount = 4, size_t calculation_thread_amount = 0); + size_t io_thread_amount = 4); ~HttpServer(); // Start the server diff --git a/example/http_server/main.cc b/example/http_server/main.cc index a774e5f4..a64046fc 100644 --- a/example/http_server/main.cc +++ b/example/http_server/main.cc @@ -39,8 +39,7 @@ void OnRequest(const HttpParser& http_parser, HttpResponse* http_response) { } // Call it by: -// './http_server [port [amount-of-I/O-threads -// [amount-of-calculation-threads]]]' +// './http_server [port [amount-of-I/O-threads]]' int main(int argc, char* argv[]) { taotu::START_LOG("http_server_log.txt"); if (1 == argc) { @@ -59,22 +58,11 @@ int main(int argc, char* argv[]) { OnRequest(http_parser, http_response); }); http_server.Start(); - } else if (3 == argc) { - HttpServer http_server{ - taotu::NetAddress{ - static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]}))}; - http_server.SetHttpCallback( - [](const HttpParser& http_parser, HttpResponse* http_response) { - OnRequest(http_parser, http_response); - }); - http_server.Start(); } else { HttpServer http_server{ taotu::NetAddress{ static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]})), - static_cast(std::stoi(std::string{argv[3]}))}; + false, static_cast(std::stoi(std::string{argv[2]}))}; http_server.SetHttpCallback( [](const HttpParser& http_parser, HttpResponse* http_response) { OnRequest(http_parser, http_response); diff --git a/example/pingpong/pingpong_server.cc b/example/pingpong/pingpong_server.cc index 7e3cbe36..bf74c948 100644 --- a/example/pingpong/pingpong_server.cc +++ b/example/pingpong/pingpong_server.cc @@ -11,12 +11,10 @@ #include "pingpong_server.h" PingpongServer::PingpongServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) + bool should_reuse_port, size_t io_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique(&event_managers_, listen_address, - should_reuse_port, - calculation_thread_amount)) { + should_reuse_port)) { server_->SetConnectionCallback([this](taotu::Connecting& connection) { this->OnConnectionCallback(connection); }); diff --git a/example/pingpong/pingpong_server.h b/example/pingpong/pingpong_server.h index f2bc0982..908c002f 100644 --- a/example/pingpong/pingpong_server.h +++ b/example/pingpong/pingpong_server.h @@ -20,8 +20,7 @@ class PingpongServer : taotu::NonCopyableMovable { typedef std::vector EventManagers; PingpongServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount = 5, - size_t calculation_thread_amount = 0); + bool should_reuse_port, size_t io_thread_amount = 5); ~PingpongServer(); // Start the server diff --git a/example/pingpong/server_main.cc b/example/pingpong/server_main.cc index 7c133007..35cabccb 100644 --- a/example/pingpong/server_main.cc +++ b/example/pingpong/server_main.cc @@ -16,8 +16,7 @@ #include "pingpong_server.h" // Call it by: -// './pingpong_server [port [amount-of-I/O-threads -// [amount-of-calculation-threads]]]' +// './pingpong_server [port [amount-of-I/O-threads]]' int main(int argc, char* argv[]) { taotu::START_LOG("pingpong_server_log.txt"); if (1 == argc) { @@ -28,18 +27,11 @@ int main(int argc, char* argv[]) { std::stoi(std::string{argv[1]}))}, false}; pingpong_server.Start(); - } else if (3 == argc) { - PingpongServer pingpong_server{ - taotu::NetAddress{ - static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]}))}; - pingpong_server.Start(); } else { PingpongServer pingpong_server{ taotu::NetAddress{ static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]})), - static_cast(std::stoi(std::string{argv[3]}))}; + false, static_cast(std::stoi(std::string{argv[2]}))}; pingpong_server.Start(); } return 0; diff --git a/example/simple_discard/discard.cc b/example/simple_discard/discard.cc index 7e13c623..dab9bc02 100644 --- a/example/simple_discard/discard.cc +++ b/example/simple_discard/discard.cc @@ -16,12 +16,10 @@ #include DiscardServer::DiscardServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) + bool should_reuse_port, size_t io_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique(&event_managers_, listen_address, - should_reuse_port, - calculation_thread_amount)) { + should_reuse_port)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, taotu::TimePoint time_point) { diff --git a/example/simple_discard/discard.h b/example/simple_discard/discard.h index 61e1bb72..ca3902c6 100644 --- a/example/simple_discard/discard.h +++ b/example/simple_discard/discard.h @@ -18,8 +18,7 @@ class DiscardServer : taotu::NonCopyableMovable { typedef std::vector EventManagers; DiscardServer(const taotu::NetAddress& listen_address, bool should_reuse_port, - size_t io_thread_amount = 3, - size_t calculation_thread_amount = 0); + size_t io_thread_amount = 3); ~DiscardServer(); // Start the server diff --git a/example/simple_discard/main.cc b/example/simple_discard/main.cc index 752aebc6..44953921 100644 --- a/example/simple_discard/main.cc +++ b/example/simple_discard/main.cc @@ -17,8 +17,7 @@ #include "discard.h" // Call it by: -// './simple_discard [port [amount-of-I/O-threads -// [amount-of-calculation-threads]]]' +// './simple_discard [port [amount-of-I/O-threads]]' int main(int argc, char* argv[]) { taotu::START_LOG("simple_discard_log.txt"); if (1 == argc) { @@ -29,18 +28,11 @@ int main(int argc, char* argv[]) { std::stoi(std::string{argv[1]}))}, false}; discard_server.Start(); - } else if (3 == argc) { - DiscardServer discard_server{ - taotu::NetAddress{ - static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]}))}; - discard_server.Start(); } else { DiscardServer discard_server{ taotu::NetAddress{ static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]})), - static_cast(std::stoi(std::string{argv[3]}))}; + false, static_cast(std::stoi(std::string{argv[2]}))}; discard_server.Start(); } return 0; diff --git a/example/simple_echo/echo.cc b/example/simple_echo/echo.cc index 0153f8f6..7b01fe81 100644 --- a/example/simple_echo/echo.cc +++ b/example/simple_echo/echo.cc @@ -14,12 +14,10 @@ #include EchoServer::EchoServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) + bool should_reuse_port, size_t io_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique(&event_managers_, listen_address, - should_reuse_port, - calculation_thread_amount)) { + should_reuse_port)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, taotu::TimePoint time_point) { diff --git a/example/simple_echo/echo.h b/example/simple_echo/echo.h index da06d42c..ea69533f 100644 --- a/example/simple_echo/echo.h +++ b/example/simple_echo/echo.h @@ -20,7 +20,7 @@ class EchoServer : taotu::NonCopyableMovable { typedef std::vector EventManagers; EchoServer(const taotu::NetAddress& listen_address, bool should_reuse_port, - size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); + size_t io_thread_amount = 3); ~EchoServer(); // Start the server diff --git a/example/simple_echo/main.cc b/example/simple_echo/main.cc index 323626ce..dd0040c7 100644 --- a/example/simple_echo/main.cc +++ b/example/simple_echo/main.cc @@ -17,8 +17,7 @@ #include "echo.h" // Call it by: -// './simple_echo [port [amount-of-I/O-threads -// [amount-of-calculation-threads]]]' +// './simple_echo [port [amount-of-I/O-threads]]' int main(int argc, char* argv[]) { taotu::START_LOG("simple_echo_log.txt"); if (1 == argc) { @@ -29,18 +28,11 @@ int main(int argc, char* argv[]) { std::stoi(std::string{argv[1]}))}, false}; echo_server.Start(); - } else if (3 == argc) { - EchoServer echo_server{ - taotu::NetAddress{ - static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]}))}; - echo_server.Start(); } else { EchoServer echo_server{ taotu::NetAddress{ static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]})), - static_cast(std::stoi(std::string{argv[3]}))}; + false, static_cast(std::stoi(std::string{argv[2]}))}; echo_server.Start(); } return 0; diff --git a/example/simple_time/main.cc b/example/simple_time/main.cc index bbb8f050..8033eb6b 100644 --- a/example/simple_time/main.cc +++ b/example/simple_time/main.cc @@ -17,8 +17,7 @@ #include "time.h" // Call it by: -// './simple_time [port [amount-of-I/O-threads -// [amount-of-calculation-threads]]]' +// './simple_time [port [amount-of-I/O-threads]]' int main(int argc, char* argv[]) { taotu::START_LOG("simple_time_log.txt"); if (1 == argc) { @@ -29,18 +28,11 @@ int main(int argc, char* argv[]) { std::stoi(std::string{argv[1]}))}, false}; time_server.Start(); - } else if (3 == argc) { - TimeServer time_server{ - taotu::NetAddress{ - static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]}))}; - time_server.Start(); } else { TimeServer time_server{ taotu::NetAddress{ static_cast(std::stoi(std::string{argv[1]}))}, - false, static_cast(std::stoi(std::string{argv[2]})), - static_cast(std::stoi(std::string{argv[3]}))}; + false, static_cast(std::stoi(std::string{argv[2]}))}; time_server.Start(); } return 0; diff --git a/example/simple_time/time.cc b/example/simple_time/time.cc index 79b64291..320bb29c 100644 --- a/example/simple_time/time.cc +++ b/example/simple_time/time.cc @@ -15,12 +15,10 @@ #include TimeServer::TimeServer(const taotu::NetAddress& listen_address, - bool should_reuse_port, size_t io_thread_amount, - size_t calculation_thread_amount) + bool should_reuse_port, size_t io_thread_amount) : event_managers_(io_thread_amount, new taotu::EventManager), server_(std::make_unique(&event_managers_, listen_address, - should_reuse_port, - calculation_thread_amount)) { + should_reuse_port)) { server_->SetMessageCallback([this](taotu::Connecting& connection, taotu::IoBuffer* io_buffer, taotu::TimePoint time_point) { diff --git a/example/simple_time/time.h b/example/simple_time/time.h index 25fab34a..35860e31 100644 --- a/example/simple_time/time.h +++ b/example/simple_time/time.h @@ -18,7 +18,7 @@ class TimeServer : taotu::NonCopyableMovable { typedef std::vector EventManagers; TimeServer(const taotu::NetAddress& listen_address, bool should_reuse_port, - size_t io_thread_amount = 3, size_t calculation_thread_amount = 0); + size_t io_thread_amount = 3); ~TimeServer(); // Start the server diff --git a/src/server.cc b/src/server.cc index f732ee8d..3c166770 100644 --- a/src/server.cc +++ b/src/server.cc @@ -19,9 +19,8 @@ using namespace taotu; Server::Server(EventManagers* event_managers, const NetAddress& listen_address, - bool should_reuse_port, size_t calculation_thread_amount) + bool should_reuse_port) : reactor_manager_(event_managers, listen_address, should_reuse_port), - thread_pool_(calculation_thread_amount), is_started_(false) { reactor_manager_.SetConnectionCallback([this](Connecting& connection) { this->DefaultOnConnectionCallback(connection); diff --git a/src/server.h b/src/server.h index e14ec314..53bdd06c 100644 --- a/src/server.h +++ b/src/server.h @@ -36,8 +36,7 @@ class Server : NonCopyableMovable { explicit Server(EventManagers* event_managers, const NetAddress& listen_address, - bool should_reuse_port = false, - size_t calculation_thread_amount = 4); + bool should_reuse_port = false); void SetConnectionCallback(const std::function& cb); void SetMessageCallback( @@ -45,8 +44,6 @@ class Server : NonCopyableMovable { void SetWriteCompleteCallback(const std::function& cb); void SetCloseCallback(const std::function& cb); - ThreadPool& GetThreadPool() { return thread_pool_; } - // Start all "Reactors" (make all event loops run) void Start(); @@ -60,9 +57,6 @@ class Server : NonCopyableMovable { // Reactor manager (the "engine") ServerReactorManager reactor_manager_; - // Thread pool for calculation - ThreadPool thread_pool_; - std::atomic_bool is_started_; }; From 811ff279f7e7636d76a109070650e6497acfe249 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 01:34:33 -0400 Subject: [PATCH 47/78] [src && example] Develop TimeService example --- .gitignore | 1 + example/CMakeLists.txt | 1 + example/rpc_demo/CMakeLists.txt | 1 + example/rpc_demo/time_service/CMakeLists.txt | 36 +++++++++++++ example/rpc_demo/time_service/server_main.cc | 50 +++++++++++++++++++ .../rpc_demo/time_service/sync_client_main.cc | 32 ++++++++++++ .../rpc_demo/time_service/time_service.proto | 17 +++++++ src/CMakeLists.txt | 9 +++- src/rpc_channel.cc | 37 +++++++------- 9 files changed, 164 insertions(+), 20 deletions(-) create mode 100644 example/rpc_demo/CMakeLists.txt create mode 100644 example/rpc_demo/time_service/CMakeLists.txt create mode 100644 example/rpc_demo/time_service/server_main.cc create mode 100644 example/rpc_demo/time_service/sync_client_main.cc create mode 100644 example/rpc_demo/time_service/time_service.proto diff --git a/.gitignore b/.gitignore index d6cb97fd..c3493eff 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build*/* .idea/* src/rpc.pb* +example/rpc_demo/time_service/time_service.pb* cmake-build-debug/* cmake-build-release/* CMakeLists.txt.user diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index bbb652f5..29e6e69f 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -4,3 +4,4 @@ ADD_SUBDIRECTORY(simple_time) ADD_SUBDIRECTORY(chat_room) ADD_SUBDIRECTORY(pingpong) ADD_SUBDIRECTORY(http_server) +ADD_SUBDIRECTORY(rpc_demo) diff --git a/example/rpc_demo/CMakeLists.txt b/example/rpc_demo/CMakeLists.txt new file mode 100644 index 00000000..a1d52a12 --- /dev/null +++ b/example/rpc_demo/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(time_service) diff --git a/example/rpc_demo/time_service/CMakeLists.txt b/example/rpc_demo/time_service/CMakeLists.txt new file mode 100644 index 00000000..2dbd31d6 --- /dev/null +++ b/example/rpc_demo/time_service/CMakeLists.txt @@ -0,0 +1,36 @@ +FIND_PACKAGE(Protobuf CONFIG REQUIRED) + +SET(PROTO_PATH "${CMAKE_SOURCE_DIR}/example/rpc_demo/time_service/") +SET(TIME_PROTO "${PROTO_PATH}/time_service.proto") +SET(GENERATED_PROTOBUF_PATH "${CMAKE_SOURCE_DIR}/example/rpc_demo/time_service/") + +SET(TIME_SERVICE_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/time_service.pb.cc") +SET(TIME_SERVICE_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/time_service.pb.h") + +ADD_CUSTOM_COMMAND( + OUTPUT ${TIME_SERVICE_PB_H_FILE} + ${TIME_SERVICE_PB_CPP_FILE} + COMMAND protoc + ARGS --proto_path ${PROTO_PATH} + --cpp_out ${GENERATED_PROTOBUF_PATH} + ${TIME_PROTO} + DEPENDS ${TIME_PROTO} +) + +SET(TIME_SERVICE_SYNC_CLIENT_SOURCE + sync_client_main.cc + ${TIME_SERVICE_PB_CPP_FILE} +) + +SET(TIME_SERVICE_SERVER_SOURCE + server_main.cc + ${TIME_SERVICE_PB_CPP_FILE} +) + +ADD_EXECUTABLE(time_service_sync_client ${TIME_SERVICE_SYNC_CLIENT_SOURCE}) +TARGET_LINK_LIBRARIES(time_service_sync_client PUBLIC protobuf::libprotobuf) +TARGET_LINK_LIBRARIES(time_service_sync_client PUBLIC taotu-static) + +ADD_EXECUTABLE(time_service_server ${TIME_SERVICE_SERVER_SOURCE}) +TARGET_LINK_LIBRARIES(time_service_server PUBLIC protobuf::libprotobuf) +TARGET_LINK_LIBRARIES(time_service_server PUBLIC taotu-static) diff --git a/example/rpc_demo/time_service/server_main.cc b/example/rpc_demo/time_service/server_main.cc new file mode 100644 index 00000000..6fffbd09 --- /dev/null +++ b/example/rpc_demo/time_service/server_main.cc @@ -0,0 +1,50 @@ +/** + * @file server_main.cc + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief Main entrance of the server of the time service. + * @date 2023-08-24 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#include + +#include "../../../src/event_manager.h" +#include "../../../src/logger.h" +#include "../../../src/net_address.h" +#include "../../../src/rpc_server.h" +#include "time_service.pb.h" + +class TimeServiceImpl : public timeservice::TimeService { + public: + void GetTime(::google::protobuf::RpcController* controller, + const timeservice::TimeRequest* request, + timeservice::TimeResponse* response, + ::google::protobuf::Closure* done) { + std::time_t now = + std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + ::printf("Received request from time service RPC Client: %s\n", + request->client_id().c_str()); + std::string current_time = std::ctime(&now); + current_time[current_time.size() - 1] = '\0'; + current_time.resize(current_time.size() - 1); + response->set_current_time(current_time); + response->current_time(); + } +}; + +int main() { + taotu::START_LOG("time_service_server_log.txt"); + std::vector event_managers(4, + new taotu::EventManager{}); + taotu::RpcServer rpc_server(&event_managers, taotu::NetAddress{4567}); + TimeServiceImpl time_service_impl; + rpc_server.RegisterService(&time_service_impl); + rpc_server.Start(); + for (auto& event_manager : event_managers) { + delete event_manager; + } + taotu::END_LOG(); + return 0; +} diff --git a/example/rpc_demo/time_service/sync_client_main.cc b/example/rpc_demo/time_service/sync_client_main.cc new file mode 100644 index 00000000..75002540 --- /dev/null +++ b/example/rpc_demo/time_service/sync_client_main.cc @@ -0,0 +1,32 @@ +/** + * @file sync_client_main.cc + * @author Sigma711 (sigma711 at foxmail dot com) + * @brief Main entrance of the sync client of the time service. + * @date 2023-08-24 + * + * @copyright Copyright (c) 2023 Sigma711 + * + */ + +#include + +#include + +#include "../../../src/logger.h" +#include "../../../src/net_address.h" +#include "../../../src/rpc_channel.h" +#include "time_service.pb.h" + +int main() { + taotu::START_LOG("time_service_sync_client_log.txt"); + taotu::RpcSyncChannel rpc_sync_channel(taotu::NetAddress{"127.0.0.1", 4567}); + timeservice::TimeService::Stub stub(&rpc_sync_channel); + timeservice::TimeRequest request; + request.set_client_id("1234"); + timeservice::TimeResponse response; + stub.GetTime(nullptr, &request, &response, nullptr); + ::printf("TimeService RPC Server time: %s\n", + response.current_time().c_str()); + taotu::END_LOG(); + return 0; +} diff --git a/example/rpc_demo/time_service/time_service.proto b/example/rpc_demo/time_service/time_service.proto new file mode 100644 index 00000000..cc5ee396 --- /dev/null +++ b/example/rpc_demo/time_service/time_service.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package timeservice; + +option cc_generic_services = true; + +service TimeService { + rpc GetTime (TimeRequest) returns (TimeResponse) {} +} + +message TimeRequest { + string client_id = 1; +} + +message TimeResponse { + string current_time = 1; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b06317cc..cf462897 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ SET(RPC_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/rpc.pb.h") ADD_CUSTOM_COMMAND( OUTPUT ${RPC_PB_H_FILE} ${RPC_PB_CPP_FILE} - COMMAND protobuf::protoc + COMMAND protoc ARGS --proto_path ${PROTO_PATH} --cpp_out ${GENERATED_PROTOBUF_PATH} ${TIME_PROTO} @@ -42,12 +42,19 @@ SET(TAOTU_SOURCE ) FIND_PACKAGE(Threads REQUIRED) + +FIND_PACKAGE(ZLIB REQUIRED) + ADD_LIBRARY(taotu-static STATIC ${TAOTU_SOURCE}) TARGET_LINK_LIBRARIES(taotu-static ${CMAKE_THREAD_LIBS_INIT}) +TARGET_LINK_LIBRARIES(taotu-static PUBLIC protobuf::libprotobuf) +TARGET_LINK_LIBRARIES(taotu-static PUBLIC ZLIB::ZLIB) SET_TARGET_PROPERTIES(taotu-static PROPERTIES OUTPUT_NAME "taotu") SET_TARGET_PROPERTIES(taotu-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) ADD_LIBRARY(taotu-shared SHARED ${TAOTU_SOURCE}) TARGET_LINK_LIBRARIES(taotu-shared ${CMAKE_THREAD_LIBS_INIT}) +TARGET_LINK_LIBRARIES(taotu-shared PUBLIC protobuf::libprotobuf) +TARGET_LINK_LIBRARIES(taotu-shared PUBLIC ZLIB::ZLIB) SET_TARGET_PROPERTIES(taotu-shared PROPERTIES OUTPUT_NAME "taotu") SET_TARGET_PROPERTIES(taotu-shared PROPERTIES CLEAN_DIRECT_OUTPUT 1) diff --git a/src/rpc_channel.cc b/src/rpc_channel.cc index 6cb9ee15..3593fd89 100644 --- a/src/rpc_channel.cc +++ b/src/rpc_channel.cc @@ -201,16 +201,17 @@ RpcSyncChannel::~RpcSyncChannel() { if (socket_fd_ >= 0) { ::close(socket_fd_); } - for (auto itr = outstanding_calls_.begin(); itr != outstanding_calls_.end(); - ++itr) { - auto outstanding_call = itr->second; - if (outstanding_call.response_message_ != nullptr) { - delete outstanding_call.response_message_; - } - if (outstanding_call.DoneCallback_ != nullptr) { - delete outstanding_call.DoneCallback_; - } - } + // for (auto itr = outstanding_calls_.begin(); itr != + // outstanding_calls_.end(); + // ++itr) { + // auto outstanding_call = itr->second; + // if (outstanding_call.response_message_ != nullptr) { + // delete outstanding_call.response_message_; + // } + // if (outstanding_call.DoneCallback_ != nullptr) { + // delete outstanding_call.DoneCallback_; + // } + // } } void RpcSyncChannel::CallMethod( @@ -219,13 +220,13 @@ void RpcSyncChannel::CallMethod( const ::google::protobuf::Message* request_message, ::google::protobuf::Message* response_message, ::google::protobuf::Closure* DoneCallback) { - std::shared_ptr rpc_message; - rpc_message->set_type(REQUEST); + RpcMessage rpc_message; + rpc_message.set_type(REQUEST); int64_t id = id_.fetch_add(1) + 1; - rpc_message->set_id(id); - rpc_message->set_service(method_descriptor->service()->name()); - rpc_message->set_method(method_descriptor->name()); - rpc_message->set_request(request_message->SerializeAsString()); + rpc_message.set_id(id); + rpc_message.set_service(method_descriptor->service()->name()); + rpc_message.set_method(method_descriptor->name()); + rpc_message.set_request(request_message->SerializeAsString()); OutstandingCall outstanding_call = {response_message, DoneCallback}; { LockGuard lock_guard(outstanding_calls_lock_); @@ -234,7 +235,7 @@ void RpcSyncChannel::CallMethod( if (socket_fd_ < 0) { return; } - codec_.Send(socket_fd_, *rpc_message); + codec_.Send(socket_fd_, rpc_message); if (socket_fd_ < 0) { return; } @@ -262,8 +263,6 @@ void RpcSyncChannel::OnRpcMessage( } } if (outstanding_call.response_message_ != nullptr) { - std::unique_ptr response_message_ptr( - outstanding_call.response_message_); if (rpc_message.has_response()) { outstanding_call.response_message_->ParseFromString( rpc_message.response()); From 1e26ce8ffc4960ae0181566674beb79c4f00bf36 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 01:50:52 -0400 Subject: [PATCH 48/78] [src] Fix the bug of starting once of each EventManager --- src/event_manager.cc | 16 ++++++++++++---- src/event_manager.h | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index babd83b8..f61ef06f 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -99,12 +99,20 @@ EventManager::~EventManager() { } void EventManager::Loop() { - std::call_once(start_once_flag_, [this]() { - thread_ = std::thread([this] { this->Start(); }); - }); + std::unique_lock start_once_lock_guard(start_once_lock_); + if (!start_once_lock_guard.owns_lock()) { + LOG_WARN("EventManager - %p cannot start again!", this); + return; + } + thread_ = std::thread([this] { this->Start(); }); } void EventManager::Work() { - std::call_once(start_once_flag_, [this]() { this->Start(); }); + std::unique_lock start_once_lock_guard(start_once_lock_); + if (!start_once_lock_guard.owns_lock()) { + LOG_WARN("EventManager - %p cannot start again!", this); + return; + } + Start(); } Connecting* EventManager::InsertNewConnection(int socket_fd, diff --git a/src/event_manager.h b/src/event_manager.h index 2040b786..1b089cd1 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -139,7 +139,7 @@ class EventManager : NonCopyableMovable { mutable MutexLock closed_fds_lock_; // Guaranteed to only start myself once - std::once_flag start_once_flag_; + mutable std::mutex start_once_lock_; #ifdef __linux__ // To wake up this I/O thread From e4da8e9d731fea6f8debb06101740f5dae89c91a Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 02:55:05 -0400 Subject: [PATCH 49/78] [src] Fix the bug of UNIX adaption in RpcChannel --- src/rpc_channel.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc_channel.cc b/src/rpc_channel.cc index 3593fd89..46cd9597 100644 --- a/src/rpc_channel.cc +++ b/src/rpc_channel.cc @@ -183,9 +183,9 @@ RpcSyncChannel::RpcSyncChannel(const NetAddress& server_address) ::exit(-1); } #ifndef __linux__ - int flags = ::fcntl(sock_fd, F_GETFL, 0); + int flags = ::fcntl(socket_fd_, F_GETFL, 0); flags |= FD_CLOEXEC; - ::fcntl(sock_fd, F_SETFD, flags); + ::fcntl(socket_fd_, F_SETFD, flags); #endif if (::connect(socket_fd_, server_address_.GetNetAddress(), server_address_.GetSize()) == -1) { From 0c8a5c0c1e05e137cbfd2a0cefbb1b3afa33170d Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 02:58:45 -0400 Subject: [PATCH 50/78] [src] Fix the bug of logger print format in RpcCodec --- src/rpc_codec.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 869663cc..d801b200 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -263,7 +263,7 @@ void RpcCodec::AsyncDefaultErrorCallback(Connecting& connection, TimePoint time_point, ErrorCode error_code) { LOG_ERROR("RpcCodec::DefaultErrorCallback - %s", - ErrorCode2String(error_code)); + ErrorCode2String(error_code).c_str()); if (connection.IsConnected()) { const_cast(connection).ShutDownWrite(); } From 222d01843b8455c9ae8cceeb8891193e42118b41 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 02:59:41 -0400 Subject: [PATCH 51/78] [src] Fix the bug of logger print format in RpcCodec --- src/rpc_codec.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index d801b200..40a8eeb7 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -272,7 +272,7 @@ void RpcCodec::SyncDefaultErrorCallback(int sock_fd, IoBuffer* io_buffer, TimePoint time_point, ErrorCode error_code) { LOG_ERROR("RpcCodec::DefaultErrorCallback - %s", - ErrorCode2String(error_code)); + ErrorCode2String(error_code).c_str()); if (!CheckSocketStatusValid(sock_fd)) { LOG_ERROR( "RpcCodec::SyncDefaultErrorCallback() - Fd(%d) - socket invalid!!!", From 1b996a87caa0f021c04c40415c4de800aa08e199 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 03:08:32 -0400 Subject: [PATCH 52/78] [src] Adjust EventManager --- src/event_manager.cc | 9 +++++---- src/event_manager.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index f61ef06f..6298cf56 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -30,7 +30,8 @@ using namespace taotu; EventManager::EventManager() - : poller_() + : poller_(), + thread_() #ifdef __linux__ , wake_up_eventer_( @@ -93,8 +94,8 @@ EventManager::~EventManager() { ::close(wake_up_pipe_[1]); delete wake_up_eventer_; #endif - if (thread_.joinable()) { - thread_.join(); + if (thread_->joinable()) { + thread_->join(); } } @@ -104,7 +105,7 @@ void EventManager::Loop() { LOG_WARN("EventManager - %p cannot start again!", this); return; } - thread_ = std::thread([this] { this->Start(); }); + thread_ = std::make_unique([this] { this->Start(); }); } void EventManager::Work() { std::unique_lock start_once_lock_guard(start_once_lock_); diff --git a/src/event_manager.h b/src/event_manager.h index 1b089cd1..3783543b 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -118,7 +118,7 @@ class EventManager : NonCopyableMovable { // descriptor -> connection class pointer) ConnectionMap connection_map_; - std::thread thread_; + std::unique_ptr thread_; Timer timer_; From 7e69506e75e0a35cbe05c6292789d764a8259800 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 03:11:56 -0400 Subject: [PATCH 53/78] [src] Fix the bug of starting once of each EventManager --- src/event_manager.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index 6298cf56..1cd3b237 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -100,16 +100,14 @@ EventManager::~EventManager() { } void EventManager::Loop() { - std::unique_lock start_once_lock_guard(start_once_lock_); - if (!start_once_lock_guard.owns_lock()) { + if (!start_once_lock_.try_lock()) { LOG_WARN("EventManager - %p cannot start again!", this); return; } thread_ = std::make_unique([this] { this->Start(); }); } void EventManager::Work() { - std::unique_lock start_once_lock_guard(start_once_lock_); - if (!start_once_lock_guard.owns_lock()) { + if (!start_once_lock_.try_lock()) { LOG_WARN("EventManager - %p cannot start again!", this); return; } @@ -234,6 +232,7 @@ void EventManager::Start() { delete connection; } connection_map_.clear(); + start_once_lock_.unlock(); } void EventManager::DoWithActiveTasks(const TimePoint& return_time) { From 94e8136ba96111da314abc0ff04ac320c735a866 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 03:34:22 -0400 Subject: [PATCH 54/78] [src] Fix the bug of starting once of each EventManager --- src/event_manager.cc | 15 ++++----------- src/event_manager.h | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index 1cd3b237..8a5d2bd6 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -100,18 +100,12 @@ EventManager::~EventManager() { } void EventManager::Loop() { - if (!start_once_lock_.try_lock()) { - LOG_WARN("EventManager - %p cannot start again!", this); - return; - } - thread_ = std::make_unique([this] { this->Start(); }); + std::call_once(start_once_flag_, [this]() { + thread_ = std::make_unique([this] { this->Start(); }); + }); } void EventManager::Work() { - if (!start_once_lock_.try_lock()) { - LOG_WARN("EventManager - %p cannot start again!", this); - return; - } - Start(); + std::call_once(start_once_flag_, [this]() { this->Start(); }); } Connecting* EventManager::InsertNewConnection(int socket_fd, @@ -232,7 +226,6 @@ void EventManager::Start() { delete connection; } connection_map_.clear(); - start_once_lock_.unlock(); } void EventManager::DoWithActiveTasks(const TimePoint& return_time) { diff --git a/src/event_manager.h b/src/event_manager.h index 3783543b..a963deec 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -139,7 +139,7 @@ class EventManager : NonCopyableMovable { mutable MutexLock closed_fds_lock_; // Guaranteed to only start myself once - mutable std::mutex start_once_lock_; + std::once_flag start_once_flag_; #ifdef __linux__ // To wake up this I/O thread From 572a0fa30a459f7356e0af8ad7e00ee9d8f5493d Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 03:36:53 -0400 Subject: [PATCH 55/78] [example] Fix the bug of the creating of EventManager in TimeService Server --- example/rpc_demo/time_service/server_main.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example/rpc_demo/time_service/server_main.cc b/example/rpc_demo/time_service/server_main.cc index 6fffbd09..9868f691 100644 --- a/example/rpc_demo/time_service/server_main.cc +++ b/example/rpc_demo/time_service/server_main.cc @@ -36,8 +36,10 @@ class TimeServiceImpl : public timeservice::TimeService { int main() { taotu::START_LOG("time_service_server_log.txt"); - std::vector event_managers(4, - new taotu::EventManager{}); + std::vector event_managers(4, nullptr); + for (auto& event_manager : event_managers) { + event_manager = new taotu::EventManager{}; + } taotu::RpcServer rpc_server(&event_managers, taotu::NetAddress{4567}); TimeServiceImpl time_service_impl; rpc_server.RegisterService(&time_service_impl); From 4d397bf41894c4fa1ba2f168504a2a7e9d974cc6 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 07:39:03 -0400 Subject: [PATCH 56/78] [src] Add specified buffer size reading API for IoBuffer --- src/io_buffer.cc | 13 +++++++++++++ src/io_buffer.h | 1 + src/rpc_codec.cc | 9 +++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/io_buffer.cc b/src/io_buffer.cc index cd148576..fcf7c087 100644 --- a/src/io_buffer.cc +++ b/src/io_buffer.cc @@ -254,6 +254,19 @@ ssize_t IoBuffer::ReadFromFd(int fd, int* tmp_errno) { } return n; } +ssize_t IoBuffer::ReadFromFd(int fd, size_t read_len, int* tmp_errno) { + EnsureWritableSpace(read_len); + ssize_t res = 0; + while (read_len > 0) { + auto bytes_read = + ::recv(fd, static_cast(const_cast(GetWritablePosition())), + read_len, MSG_NOSIGNAL); + read_len -= bytes_read; + writing_index_ += bytes_read; + res += bytes_read; + } + return res; +} ssize_t IoBuffer::WriteToFd(int fd) { ssize_t n = ::send( diff --git a/src/io_buffer.h b/src/io_buffer.h index eafe2b12..61631cac 100644 --- a/src/io_buffer.h +++ b/src/io_buffer.h @@ -170,6 +170,7 @@ class IoBuffer { // Retrieve content from the file descriptor with discrete reading(coping with // sudden large traffic) to the buffer ssize_t ReadFromFd(int fd, int* tmp_errno); + ssize_t ReadFromFd(int fd, size_t read_len, int* tmp_errno); // Stuff content of the buffer into the file descriptor ssize_t WriteToFd(int fd); diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 40a8eeb7..6e16fb32 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -123,7 +123,7 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer, const ssize_t min_header_len = static_cast(kMinMessageLength + kHeaderLength); while (min_header_len >= io_buffer->GetReadableBytes()) { - io_buffer->ReadFromFd(sock_fd, &saved_errno); + io_buffer->ReadFromFd(sock_fd, min_header_len, &saved_errno); if (saved_errno != 0) { LOG_ERROR("RpcCodec::OnMessage() - Fd(%d) with errno(%d)", sock_fd, saved_errno); @@ -135,9 +135,10 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer, ErrorCode::kInvalidLength); return; } - while (io_buffer->GetReadableBytes() <= - static_cast(kHeaderLength + len)) { - io_buffer->ReadFromFd(sock_fd, &saved_errno); + while (static_cast(kHeaderLength + len) >= + io_buffer->GetReadableBytes()) { + io_buffer->ReadFromFd(sock_fd, static_cast(kHeaderLength + len), + &saved_errno); } if (AsyncRawCallback_ && !SyncRawCallback_(sock_fd, From 51b5c019d5bfe180e160d4d36899594bc07fa59a Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 09:36:12 -0400 Subject: [PATCH 57/78] [example] Call done closure after processing one RPC service --- example/rpc_demo/time_service/server_main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/rpc_demo/time_service/server_main.cc b/example/rpc_demo/time_service/server_main.cc index 9868f691..0c1eccbf 100644 --- a/example/rpc_demo/time_service/server_main.cc +++ b/example/rpc_demo/time_service/server_main.cc @@ -30,7 +30,7 @@ class TimeServiceImpl : public timeservice::TimeService { current_time[current_time.size() - 1] = '\0'; current_time.resize(current_time.size() - 1); response->set_current_time(current_time); - response->current_time(); + done->Run(); } }; From 308fdacfe94c29c0fa63a1683ce5c14d104bb264 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 25 Aug 2023 19:39:25 -0400 Subject: [PATCH 58/78] [src] Fix the bug of blocking reading of RpcCodec for single socket fd --- src/rpc_codec.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 6e16fb32..55ada7c9 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -122,8 +122,9 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer, int saved_errno = 0; // FIXME: error check const ssize_t min_header_len = static_cast(kMinMessageLength + kHeaderLength); - while (min_header_len >= io_buffer->GetReadableBytes()) { - io_buffer->ReadFromFd(sock_fd, min_header_len, &saved_errno); + while (min_header_len > io_buffer->GetReadableBytes()) { + io_buffer->ReadFromFd( + sock_fd, min_header_len - io_buffer->GetReadableBytes(), &saved_errno); if (saved_errno != 0) { LOG_ERROR("RpcCodec::OnMessage() - Fd(%d) with errno(%d)", sock_fd, saved_errno); @@ -135,9 +136,11 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer, ErrorCode::kInvalidLength); return; } - while (static_cast(kHeaderLength + len) >= + while (static_cast(kHeaderLength + len) > io_buffer->GetReadableBytes()) { - io_buffer->ReadFromFd(sock_fd, static_cast(kHeaderLength + len), + io_buffer->ReadFromFd(sock_fd, + static_cast(kHeaderLength + len) - + io_buffer->GetReadableBytes(), &saved_errno); } if (AsyncRawCallback_ && From 389b14c309d4984a0fa4d778fd7e82eb7634a371 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 26 Aug 2023 17:15:01 -0400 Subject: [PATCH 59/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index b8366d86..99f4973d 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -20,8 +20,9 @@ jobs: - name: Install Protobuf run: | sudo apt-get install libtool pkg-config wget git - git clone --recursive https://github.com/protocolbuffers/protobuf/releases/latest + git clone --recursive https://github.com/protocolbuffers/protobuf.git cd protobuf + git checkout tags/v24.2 mkdir build cd build cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. From 7d2d86684999c1c5c916b5f7a6cf251c45feb7cc Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 26 Aug 2023 17:38:03 -0400 Subject: [PATCH 60/78] [src] Modify CMakeLists.txt for deleting shared library generating --- src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf462897..a7b66760 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,9 +52,9 @@ TARGET_LINK_LIBRARIES(taotu-static PUBLIC ZLIB::ZLIB) SET_TARGET_PROPERTIES(taotu-static PROPERTIES OUTPUT_NAME "taotu") SET_TARGET_PROPERTIES(taotu-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) -ADD_LIBRARY(taotu-shared SHARED ${TAOTU_SOURCE}) -TARGET_LINK_LIBRARIES(taotu-shared ${CMAKE_THREAD_LIBS_INIT}) -TARGET_LINK_LIBRARIES(taotu-shared PUBLIC protobuf::libprotobuf) -TARGET_LINK_LIBRARIES(taotu-shared PUBLIC ZLIB::ZLIB) -SET_TARGET_PROPERTIES(taotu-shared PROPERTIES OUTPUT_NAME "taotu") -SET_TARGET_PROPERTIES(taotu-shared PROPERTIES CLEAN_DIRECT_OUTPUT 1) +# ADD_LIBRARY(taotu-shared SHARED ${TAOTU_SOURCE}) +# TARGET_LINK_LIBRARIES(taotu-shared ${CMAKE_THREAD_LIBS_INIT}) +# TARGET_LINK_LIBRARIES(taotu-shared PUBLIC protobuf::libprotobuf) +# TARGET_LINK_LIBRARIES(taotu-shared PUBLIC ZLIB::ZLIB) +# SET_TARGET_PROPERTIES(taotu-shared PROPERTIES OUTPUT_NAME "taotu") +# SET_TARGET_PROPERTIES(taotu-shared PROPERTIES CLEAN_DIRECT_OUTPUT 1) From 1beba85a9d4f647a157e3ac10128c642911d7f4e Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 26 Aug 2023 17:40:33 -0400 Subject: [PATCH 61/78] [CI/CD] Modify dependencies for installing protobuf --- .github/workflows/c-cpp.yml | 2 +- .github/workflows/cmake.yml | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 99f4973d..47cbc447 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - name: init run: mkdir build - - name: Install Protobuf + - name: Install protobuf manually run: | sudo apt-get install libtool pkg-config wget git git clone --recursive https://github.com/protocolbuffers/protobuf.git diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f003901f..361ced37 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -22,8 +22,18 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Install Protobuf - run: sudo apt-get install libtool pkg-config && sudo apt-get install protobuf-compiler libprotobuf-dev + - name: Install protobuf manually + run: | + sudo apt-get install libtool pkg-config wget git + git clone --recursive https://github.com/protocolbuffers/protobuf.git + cd protobuf + git checkout tags/v24.2 + mkdir build + cd build + cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. + make + sudo make install + sudo ldconfig - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a From 0ebfffac6b22903bb0263c8b7591a116c9ffdf44 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Sat, 26 Aug 2023 18:04:00 -0400 Subject: [PATCH 62/78] [src] Extend the ability of RpcSyncChannel (let users set socket options) --- src/rpc_channel.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc_channel.h b/src/rpc_channel.h index f8c85583..4f39a007 100644 --- a/src/rpc_channel.h +++ b/src/rpc_channel.h @@ -116,6 +116,8 @@ class RpcSyncChannel : public ::google::protobuf::RpcChannel { void OnMessage(int sock_fd, IoBuffer* io_buffer, TimePoint receive); + int Fd() const { return socket_fd_; } + private: void OnRpcMessage(int sock_fd, const std::shared_ptr& rpc_message_ptr, From 10f206b84ee1b3d052c83926500a4a43314633ef Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Mon, 28 Aug 2023 19:02:34 -0400 Subject: [PATCH 63/78] [src] Fix the bug of check the thead pointer (nullpter) when destroying EventManager instances --- src/event_manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index 8a5d2bd6..ec9b7165 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -94,7 +94,7 @@ EventManager::~EventManager() { ::close(wake_up_pipe_[1]); delete wake_up_eventer_; #endif - if (thread_->joinable()) { + if (thread_ && thread_->joinable()) { thread_->join(); } } From aa998249e6692c914daf54d9a129ab5712b625b3 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Mon, 28 Aug 2023 19:04:08 -0400 Subject: [PATCH 64/78] [src] Improve Reading Func of IoBuffer for ignoring signals by using the modern API - recvmsg() --- src/io_buffer.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/io_buffer.cc b/src/io_buffer.cc index fcf7c087..8d09a530 100644 --- a/src/io_buffer.cc +++ b/src/io_buffer.cc @@ -240,8 +240,14 @@ ssize_t IoBuffer::ReadFromFd(int fd, int* tmp_errno) { discrete_buffers[1].iov_len = 64 * 1024; // Use extra buffer to receive data if the writable space is not enough const int iov_seq = writable_bytes < 64 * 1024 ? 2 : 1; - ssize_t n = - ::readv(fd, static_cast(discrete_buffers), iov_seq); + // To replace this (because of signals): + // ssize_t n = ::readv(fd, static_cast(discrete_buffers), + // iov_seq); + struct msghdr message; + ::memset(&message, 0, sizeof(message)); // clear the structure + message.msg_iov = discrete_buffers; + message.msg_iovlen = iov_seq; + ssize_t n = ::recvmsg(fd, &message, MSG_NOSIGNAL); if (n < 0) { *tmp_errno = errno; LOG_ERROR("Discrete reading in Fd(%d) failed!!!", fd); From f2141e932974ef7cdc141fe4451a614d5399befb Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Mon, 28 Aug 2023 19:17:21 -0400 Subject: [PATCH 65/78] [src] Print connection error info by the user buffer instead of the return value of strerror_r() in Connecting --- src/connecting.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connecting.cc b/src/connecting.cc index f27ce50b..46468a68 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -116,7 +116,7 @@ void Connecting::DoWithError() const { } char errno_info[512]; auto tmp_ptr = ::strerror_r(saved_errno, errno_info, sizeof(errno_info)); - LOG_ERROR("Fd(%d) gets an error -- %s!!!", Fd(), tmp_ptr); + LOG_ERROR("Fd(%d) gets an error -- %s!!!", Fd(), errno_info); } void Connecting::OnEstablishing() { From 7ba7ed1e08f101b191d874f7bde6f05a47b1ff14 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Mon, 28 Aug 2023 19:27:21 -0400 Subject: [PATCH 66/78] [src] Improve calling strerror_r() (discard its return value) --- src/connecting.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connecting.cc b/src/connecting.cc index 46468a68..4bc5a5be 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -115,7 +115,7 @@ void Connecting::DoWithError() const { saved_errno = opt_val; } char errno_info[512]; - auto tmp_ptr = ::strerror_r(saved_errno, errno_info, sizeof(errno_info)); + ::strerror_r(saved_errno, errno_info, sizeof(errno_info)); LOG_ERROR("Fd(%d) gets an error -- %s!!!", Fd(), errno_info); } From 5653a9630a11e513ca31f87cb25c55a78895fd8c Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Mon, 28 Aug 2023 19:41:40 -0400 Subject: [PATCH 67/78] [src] Make Connecting::DoWithError() adapting to UNIX --- src/connecting.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/connecting.cc b/src/connecting.cc index 4bc5a5be..d3f03510 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -105,6 +105,7 @@ void Connecting::DoClosing() { } } void Connecting::DoWithError() const { +#ifdef __linux__ int opt_val; auto opt_len = static_cast(sizeof(opt_val)); int saved_errno; @@ -114,6 +115,9 @@ void Connecting::DoWithError() const { } else { saved_errno = opt_val; } +#else + int saved_errno = errno; +#endif char errno_info[512]; ::strerror_r(saved_errno, errno_info, sizeof(errno_info)); LOG_ERROR("Fd(%d) gets an error -- %s!!!", Fd(), errno_info); From cba3db6fb98f8b2d54bab31040340fdc00d04eba Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 29 Aug 2023 03:23:05 -0400 Subject: [PATCH 68/78] [src] Fix the bug of pass a shared_ptr by value to a lambda in RpcServer::OnConnectionCallback() --- src/rpc_server.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rpc_server.cc b/src/rpc_server.cc index 0544e43f..1e911c2f 100644 --- a/src/rpc_server.cc +++ b/src/rpc_server.cc @@ -45,11 +45,11 @@ void RpcServer::OnConnectionCallback(Connecting& connection) { std::shared_ptr rpc_channel = std::make_shared(connection); rpc_channel->SetServices(&services_); - connection.RegisterOnMessageCallback( - [&rpc_channel](Connecting& connection, IoBuffer* io_buffer, - TimePoint receive_time) { - rpc_channel->OnMessage(connection, io_buffer, receive_time); - }); + connection.RegisterOnMessageCallback([rpc_channel](Connecting& connection, + IoBuffer* io_buffer, + TimePoint receive_time) { + rpc_channel->OnMessage(connection, io_buffer, receive_time); + }); connection.SetContext>(rpc_channel); } else { connection.SetContext>( From 451995e6061ac257a96d8845b3bb4d76edb51467 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Tue, 29 Aug 2023 04:33:48 -0400 Subject: [PATCH 69/78] [src] Improve EventManager::Quit() (Call WakeUp()) --- src/event_manager.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index ec9b7165..7a853740 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -206,7 +206,10 @@ void EventManager::WakeUp() { #endif } -void EventManager::Quit() { should_quit_.store(true); } +void EventManager::Quit() { + should_quit_.store(true); + WakeUp(); +} void EventManager::Start() { should_quit_.store(false); From fa38d8acd20d08fe740ea4925b9fb6692961873b Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 11:47:16 -0400 Subject: [PATCH 70/78] [src] Fix data type in comparision expressions in RpcCodec --- src/rpc_codec.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc_codec.cc b/src/rpc_codec.cc index 55ada7c9..abb92f62 100644 --- a/src/rpc_codec.cc +++ b/src/rpc_codec.cc @@ -122,7 +122,7 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer, int saved_errno = 0; // FIXME: error check const ssize_t min_header_len = static_cast(kMinMessageLength + kHeaderLength); - while (min_header_len > io_buffer->GetReadableBytes()) { + while (static_cast(min_header_len) > io_buffer->GetReadableBytes()) { io_buffer->ReadFromFd( sock_fd, min_header_len - io_buffer->GetReadableBytes(), &saved_errno); if (saved_errno != 0) { @@ -173,7 +173,8 @@ int RpcCodec::Serialize2Buffer(const ::google::protobuf::Message& message, uint8_t* start = reinterpret_cast( const_cast(io_buffer->GetWritablePosition())); uint8_t* end = message.SerializeWithCachedSizesToArray(start); - if (end - start != byte_size || byte_size != message.ByteSizeLong()) { + if (static_cast(end - start) != byte_size || + byte_size != message.ByteSizeLong()) { LOG_ERROR( "Protocol message was modified concurrently during serialization. Or " "Byte size calculation and serialization were inconsistent (This may " @@ -244,6 +245,7 @@ void RpcCodec::FillEmptyBuffer(IoBuffer* io_buffer, int32_t checksum = Checksum(io_buffer->GetReadablePosition(), static_cast(io_buffer->GetReadableBytes())); io_buffer->AppendInt32(checksum); + (void)byte_size; int32_t len = htobe32(static_cast(io_buffer->GetReadableBytes())); io_buffer->SetHeadContent(&len, sizeof(len)); } From 4716923c00b441455a908516a6e7887fbe9cd8a9 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 11:48:45 -0400 Subject: [PATCH 71/78] [build] Add LSan as a debug build option --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ad2ea1c..c17775c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ SET(CMAKE_CXX_STANDARD 17) SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17") -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -fsanitize=address -Wall -O0 -DTAOTU_DEBUG") +SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -fsanitize=address,leak -Wall -O0 -DTAOTU_DEBUG") ADD_DEFINITIONS(-Wno-format-security) From 62b961a94ba70711879d44e1a4e55957775b8cfb Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 11:59:31 -0400 Subject: [PATCH 72/78] [build] Make CMakeLists.txt adapted to UNIX --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c17775c2..206d50e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,13 @@ SET(CMAKE_CXX_STANDARD 17) SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17") -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -fsanitize=address,leak -Wall -O0 -DTAOTU_DEBUG") +SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -fsanitize=address -Wall -O0 -DTAOTU_DEBUG") + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + message(STATUS "Darwin detected, not using -fsanitize=leak") +else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=leak") +endif() ADD_DEFINITIONS(-Wno-format-security) From faa14ec67449c6ce56a2c9021480ca93db8edff7 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 12:55:23 -0400 Subject: [PATCH 73/78] [src] Discard the return value of ::strerror_r() --- src/connecting.cc | 3 ++- src/connector.cc | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/connecting.cc b/src/connecting.cc index d3f03510..7e59eb45 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -119,7 +119,8 @@ void Connecting::DoWithError() const { int saved_errno = errno; #endif char errno_info[512]; - ::strerror_r(saved_errno, errno_info, sizeof(errno_info)); + auto tmp = ::strerror_r(saved_errno, errno_info, sizeof(errno_info)); + (void)tmp; LOG_ERROR("Fd(%d) gets an error -- %s!!!", Fd(), errno_info); } diff --git a/src/connector.cc b/src/connector.cc index e454f4dc..e069b47e 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -167,8 +167,9 @@ void Connector::DoWriting() { int error = GetSocketError(conn_fd); if (error) { char errno_info[512]; - LOG_WARN("Connector fd(%d) has the error(%s)!", conn_fd, - ::strerror_r(error, errno_info, sizeof(errno_info))); + auto tmp = ::strerror_r(error, errno_info, sizeof(errno_info)); + LOG_WARN("Connector fd(%d) has the error(%s)!", conn_fd, errno_info); + (void)tmp; DoRetrying(conn_fd); } else if ([](int conn_fd) -> bool { struct sockaddr_in6 local_address = @@ -210,8 +211,9 @@ void Connector::DoWithError() { int conn_fd = RemoveAndReset(); int error = GetSocketError(conn_fd); char errno_info[512]; - LOG_WARN("Connector fd(%d) has the error(%s)!", conn_fd, - ::strerror_r(error, errno_info, sizeof(errno_info))); + auto tmp = ::strerror_r(error, errno_info, sizeof(errno_info)); + (void)tmp; + LOG_WARN("Connector fd(%d) has the error(%s)!", conn_fd, errno_info); DoRetrying(conn_fd); } } From 9a957fb3103e7958a0dbd41b71bcadbb179b8de7 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 13:02:38 -0400 Subject: [PATCH 74/78] [src] Do some trivial improvements about unused things --- src/logger.cc | 7 ++++++- src/rpc_channel.cc | 3 +-- src/rpc_channel.h | 3 --- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/logger.cc b/src/logger.cc index 2e981d3d..cd853dc3 100644 --- a/src/logger.cc +++ b/src/logger.cc @@ -180,7 +180,12 @@ Logger::Logger() wrote_index_(-1L), log_file_(NULL), time_now_sec_(0), - write_index_(0L) {} + write_index_(0L) { + (void)filler1_; + (void)filler2_; + (void)filler3_; + (void)filler4_; +} Logger::~Logger() { if (thread_.joinable()) { diff --git a/src/rpc_channel.cc b/src/rpc_channel.cc index 46cd9597..7c7bd4e0 100644 --- a/src/rpc_channel.cc +++ b/src/rpc_channel.cc @@ -175,8 +175,7 @@ RpcSyncChannel::RpcSyncChannel(const NetAddress& server_address) this->OnRpcMessage(sock_fd, rpc_message, receive_time); }), socket_fd_(::socket(server_address.GetFamily(), - SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP)), - services_(nullptr) { + SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP)) { LOG_INFO("RpcSyncChannel::RpcSyncChannel - %p", this); if (socket_fd_ < 0) { LOG_ERROR("Fail to initialize for the socket fd of new RpcSyncChannel!!!"); diff --git a/src/rpc_channel.h b/src/rpc_channel.h index 4f39a007..f708806f 100644 --- a/src/rpc_channel.h +++ b/src/rpc_channel.h @@ -137,9 +137,6 @@ class RpcSyncChannel : public ::google::protobuf::RpcChannel { MutexLock outstanding_calls_lock_; std::unordered_map outstanding_calls_; - - const std::unordered_map* - services_; }; } // namespace taotu From 0394f6a91a3faac5541341ac7402900dd78073fd Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 20:56:39 -0400 Subject: [PATCH 75/78] [CI/CD] Use Ninja instead of Make --- .github/workflows/c-cpp.yml | 12 ++++++------ .github/workflows/cmake.yml | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 47cbc447..93f17718 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -25,9 +25,9 @@ jobs: git checkout tags/v24.2 mkdir build cd build - cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. - make - sudo make install + cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja .. + ninja + sudo ninja install sudo ldconfig - name: Install gtest manually run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a @@ -36,10 +36,10 @@ jobs: run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install - name: cmake working-directory: build - run: cmake -DProtobuf_DIR=`pkg-config --variable=prefix protobuf` -DCMAKE_BUILD_TYPE=Release .. - - name: make + run: cmake -DProtobuf_DIR=`pkg-config --variable=prefix protobuf` -DCMAKE_BUILD_TYPE=Release -G Ninja .. + - name: ninja working-directory: build - run: make + run: ninja - name: gtest working-directory: ${{github.workspace}}/build/output/bin # Execute tests defined by the CMake configuration. diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 361ced37..3c96903e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -30,9 +30,9 @@ jobs: git checkout tags/v24.2 mkdir build cd build - cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. - make - sudo make install + cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja .. + ninja + sudo ninja install sudo ldconfig - name: Install gtest manually @@ -45,11 +45,11 @@ jobs: - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -G Ninja - name: Build # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake -G Ninja --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - name: Test working-directory: ${{github.workspace}}/build/test From baa5d62905ef7e0a62a852c33309e36902327b82 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 20:58:18 -0400 Subject: [PATCH 76/78] [CI/CD] Use Ninja instead of Make --- .github/workflows/c-cpp.yml | 2 +- .github/workflows/cmake.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 93f17718..5c5618a4 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -19,7 +19,7 @@ jobs: run: mkdir build - name: Install protobuf manually run: | - sudo apt-get install libtool pkg-config wget git + sudo apt-get install libtool pkg-config wget git ninja-build git clone --recursive https://github.com/protocolbuffers/protobuf.git cd protobuf git checkout tags/v24.2 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3c96903e..099b5646 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -24,7 +24,7 @@ jobs: - name: Install protobuf manually run: | - sudo apt-get install libtool pkg-config wget git + sudo apt-get install libtool pkg-config wget git ninja-build git clone --recursive https://github.com/protocolbuffers/protobuf.git cd protobuf git checkout tags/v24.2 From d8467d19fae6a8abb9efbb834ee4b87526bf4a65 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 21:10:09 -0400 Subject: [PATCH 77/78] [CI/CD] Adjust the format of GitHub Actions Workflow config files --- .github/workflows/c-cpp.yml | 17 +++++++++++++++-- .github/workflows/cmake.yml | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 5c5618a4..52d89071 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -30,10 +30,23 @@ jobs: sudo ninja install sudo ldconfig - name: Install gtest manually - run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a + run: | + sudo apt-get install libgtest-dev + cd /usr/src/gtest + sudo cmake -DCMAKE_BUILD_TYPE=Release -G Ninja CMakeLists.txt + sudo ninja + sudo cp lib/*.a /usr/lib + sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a + sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually working-directory: ${{github.workspace}}/.. - run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install + run: | + git clone https://github.com/nodejs/llhttp.git + cd llhttp + sudo apt-get install npm + npm install + make + sudo make install - name: cmake working-directory: build run: cmake -DProtobuf_DIR=`pkg-config --variable=prefix protobuf` -DCMAKE_BUILD_TYPE=Release -G Ninja .. diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 099b5646..7a908ffd 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -36,11 +36,24 @@ jobs: sudo ldconfig - name: Install gtest manually - run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a + run: | + sudo apt-get install libgtest-dev + cd /usr/src/gtest + sudo cmake -DCMAKE_BUILD_TYPE=Release -G Ninja CMakeLists.txt + sudo ninja + sudo cp lib/*.a /usr/lib + sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a + sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a - name: Install llhttp manually working-directory: ${{github.workspace}}/.. - run: git clone https://github.com/nodejs/llhttp.git && cd llhttp && sudo apt-get install npm && npm install && make && sudo make install + run: | + git clone https://github.com/nodejs/llhttp.git + cd llhttp + sudo apt-get install npm + npm install + make + sudo make install - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. From fcc70a40ebef971aff14b09f683c683124f24d26 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Wed, 30 Aug 2023 21:11:37 -0400 Subject: [PATCH 78/78] [CI/CD] Modify build the toolchain --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 7a908ffd..ad256ab6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -62,7 +62,7 @@ jobs: - name: Build # Build your program with the given configuration - run: cmake -G Ninja --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - name: Test working-directory: ${{github.workspace}}/build/test