From ac4c10bac9f3110622c63067f3fad4c6e03e11cf Mon Sep 17 00:00:00 2001 From: IronsDu Date: Tue, 6 Mar 2018 15:53:27 +0800 Subject: [PATCH] first commit --- CMakeLists.txt | 19 + LICENSE | 20 + README.md | 178 +++ core_proto/gayrpc_option.proto | 8 + core_proto/meta.proto | 44 + examples/benchmark/BenchmarkClient.cpp | 255 ++++ examples/benchmark/BenchmarkServer.cpp | 106 ++ examples/benchmark/CMakeLists.txt | 15 + examples/benchmark/WaitGroup.h | 54 + .../benchmark/pb/benchmark_service.gayrpc.h | 179 +++ examples/benchmark/pb/benchmark_service.pb.cc | 671 +++++++++ examples/benchmark/pb/benchmark_service.pb.h | 416 ++++++ examples/benchmark/pb/benchmark_service.proto | 18 + examples/echo/CMakeLists.txt | 15 + examples/echo/EchoClient.cpp | 141 ++ examples/echo/EchoServer.cpp | 136 ++ examples/echo/pb/echo_service.gayrpc.h | 214 +++ examples/echo/pb/echo_service.pb.cc | 1254 ++++++++++++++++ examples/echo/pb/echo_service.pb.h | 760 ++++++++++ examples/echo/pb/echo_service.proto | 29 + include/CMakeLists.txt | 19 + include/GayRpcClient.h | 120 ++ include/GayRpcCore.h | 17 + include/GayRpcError.h | 59 + include/GayRpcHelper.h | 81 + include/GayRpcReply.h | 110 ++ include/GayRpcService.h | 16 + include/GayRpcTypeHandler.h | 66 + include/gayrpc_option.pb.cc | 81 + include/gayrpc_option.pb.h | 77 + include/meta.pb.cc | 1319 +++++++++++++++++ include/meta.pb.h | 854 +++++++++++ utils/GayRpcInterceptor.h | 76 + utils/OpPacket.h | 162 ++ utils/UtilsDataHandler.h | 64 + utils/UtilsInterceptor.h | 47 + 36 files changed, 7700 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 README.md create mode 100644 core_proto/gayrpc_option.proto create mode 100644 core_proto/meta.proto create mode 100644 examples/benchmark/BenchmarkClient.cpp create mode 100644 examples/benchmark/BenchmarkServer.cpp create mode 100644 examples/benchmark/CMakeLists.txt create mode 100644 examples/benchmark/WaitGroup.h create mode 100644 examples/benchmark/pb/benchmark_service.gayrpc.h create mode 100644 examples/benchmark/pb/benchmark_service.pb.cc create mode 100644 examples/benchmark/pb/benchmark_service.pb.h create mode 100644 examples/benchmark/pb/benchmark_service.proto create mode 100644 examples/echo/CMakeLists.txt create mode 100644 examples/echo/EchoClient.cpp create mode 100644 examples/echo/EchoServer.cpp create mode 100644 examples/echo/pb/echo_service.gayrpc.h create mode 100644 examples/echo/pb/echo_service.pb.cc create mode 100644 examples/echo/pb/echo_service.pb.h create mode 100644 examples/echo/pb/echo_service.proto create mode 100644 include/CMakeLists.txt create mode 100644 include/GayRpcClient.h create mode 100644 include/GayRpcCore.h create mode 100644 include/GayRpcError.h create mode 100644 include/GayRpcHelper.h create mode 100644 include/GayRpcReply.h create mode 100644 include/GayRpcService.h create mode 100644 include/GayRpcTypeHandler.h create mode 100644 include/gayrpc_option.pb.cc create mode 100644 include/gayrpc_option.pb.h create mode 100644 include/meta.pb.cc create mode 100644 include/meta.pb.h create mode 100644 utils/GayRpcInterceptor.h create mode 100644 utils/OpPacket.h create mode 100644 utils/UtilsDataHandler.h create mode 100644 utils/UtilsInterceptor.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0cd289c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required (VERSION 2.6) +project(gayrpc) + +include_directories("${PROJECT_SOURCE_DIR}/include/") +include_directories("${PROJECT_SOURCE_DIR}/utils/") +include_directories("${PROJECT_SOURCE_DIR}/../brynet/src/") + +if(WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest") +elseif(UNIX) + if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + endif() +endif() + +add_subdirectory(examples/echo) +add_subdirectory(examples/benchmark) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..339b7d7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2018 irons + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..05948d1 --- /dev/null +++ b/README.md @@ -0,0 +1,178 @@ +# gayrpc +基于Protobuf协议的跨平台(Linux和Windows)全双工双向(异步)RPC系统,也即通信两端都可以同时作为服务方和客户端,彼此均可请求对方的服务. + +## 动机 +1. 目前的RPC系统大多用于互联网行业后端系统,他们之间更像一个单向图,但游戏等行业中很常见两个节点之间互相主动请求数据。 +因此我们需要一个全双工RPC,在一个“链接”(虚拟概念,不一定基于TCP,且两者之间只存在逻辑链接而没有网络直连)的两端都可以开启服务或到对端的客户端。 +2. 因为目前很多RPC系统都不是C++写的,而我常用语言是C++,且觉得目前版本C++的开发效率和细节控制非常不错,决定写一个试试。 +3. 有朋友觉得我之前基于C++泛型开发的RPC必定没法做得太强大,因此改为gayrpc这种基于代码生成来做,试试看。 + +## 设计准则 +1. RPC支持拦截器,能够对Request或Response做一些处理(比如监控、认证、加解密) +2. RPC核心不依赖网络和网络传输协议,即:我们可以开发任何网络应用和逻辑来开启RPC两端,将“收到”的消息丢给RPC核心,并通过某个出站拦截器来实现/决定把Request或Response以何种方式传递给谁。 +3. 此RPC是基于异步回调的,我认为这是目前C++里比较安全和靠谱的方式,除了回调地狱让人恶心……,不过可以通过将Lambda抽离出来而不是嵌套稍微好看点吧? +4. RPC系统核心(以及接口)是线程安全的,可以在任意线程调用RPC;且可以在任意线程使用XXXReply::PTR对象返回Response。 +5. RPC是并行的,也即:客户端可以随意发送Request而不必等待之前的完成。 且允许先收到后发出的Request的Response。或许这会让某些业务编写困难,又会陷入回调地狱…… +6. RPC系统会为每一个“链接”生成一个XXXService对象,这样可以让不同的“链接”绑定/持有各自的业务对象(session),这点可以在下面的`服务范例`中看到。(而不是像grpc等系统那样,一个服务只存在一个service,而RPC调用则是类似短链接:收到请求返回数据即可) + +## 依赖 +Windows下可使用 [vcpkg](https://github.com/Microsoft/vcpkg) 进行安装以下依赖库. + +* [protobuf](https://github.com/google/protobuf) +* [brynet](https://github.com/IronsDu/brynet) + +请注意,当使用Windows时,务必使用`vcpkg install brynet --head`安装brynet.
+且务必根据自身系统中的protoc版本对meta.proto和gayrpc_option.proto预先生成代码,请在core_proto 目录里执行: +```sh + protoc --cpp_out=../include meta.proto gayrpc_option.proto +``` + +## 代码生成工具 +地址:`https://github.com/IronsDu/protoc-gen-gayrpc`,由[liuhan](https://github.com/liuhan907)编写完成。
+首先将插件程序放到系统 PATH路径下(比如Linux下的/usr/bin),然后执行代码生成,比如(在具体的服务目录里,比如`gayrpc/examples/echo/pb`): +```sh + protoc -I. -I../../../core_proto --cpp_out=. echo_service.proto + protoc -I. -I../../../core_proto --gayrpc_out=. echo_service.proto +``` + +## Benchmark +```sh +connection num:5000 +took 20349ms, for 2000000 requests +throughput (TPS):100000 +mean:46 ms ,46509491 ns +median:42 ms ,42219427 ns +max:336 ms ,336657507 ns +min:0 ms ,21056 ns +p99:45 ms ,45382276 ns +``` + +## 协议 +目前RPC通信协议底层采用两层协议. +第一层采用二进制协议,且字节序统一为大端. +通信格式如下: + + [data_len | op | data] + 字段解释: + data_len : uint64_t; + op : uint32_t; + data : char[data_len]; + +当`op`值为1时表示RPC消息,此为第二层协议!这时第一层协议中的data的内存布局则为: + + [meta_size | data_size | meta | data] + 字段解释: + meta_size : uint32_t; + data_size : uint64_t; + meta : char[meta_size]; + data : char[data_size]; + +其中`meta`为 `RpcMata`的binary.`data`为某业务上的Protobuf Request或Response类型对象的binary或JSON. + +`RpcMata`的proto定义如下: +``` +syntax = "proto3"; + +message RpcMeta { + enum Type { + REQUEST = 0; + RESPONSE = 1; + }; + + enum DataEncodingType { + BINARY = 0; + JSON = 1; + }; + + message Request { + // 请求的服务函数 + uint64 method = 1; + // 请求方是否期待服务方返回response + bool expect_response = 2; + // 请求方的序号ID + uint64 sequence_id = 3; + }; + + message Response { + // 请求方的序号ID + uint64 sequence_id = 1; + // 执行是否成功 + bool failed = 2; + // (当failed为true)错误码 + int32 error_code = 3; + // (当failed为true)错误原因 + string reason = 4; + }; + + // Rpc类型(请求、回应) + Type type = 1; + // RpcData的编码方式 + DataEncodingType encoding = 2; + // 请求元信息 + Request request_info = 3; + // 回应元信息 + Response response_info = 4; +} +``` + +## 服务描述文件范例 +以下面的服务定义为例: +``` +syntax = "proto3"; + +package dodo.test; + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} + +service EchoServer { + rpc Echo(EchoRequest) returns(EchoResponse){ + option (message_id)= 1 ;//设定消息ID,也就是rpc协议中request_info的method + }; +} +``` + +## 处理请求或Response的实现原理 +1. 编写第一层通信协议的编解码 +2. 将第一层中的`data`作为第二层协议数据,反序列化其中的`meta`作为`RpcMeta`对象 +3. 判断`RpcMata`中的`type` + 1. 如果为`REQUEST`则根据`request_info`中的元信息调用`method`所对应的服务函数. + 此时第二层协议中的`data`则为服务函数的请求请求对象(比如`EchoRequest`). + 2. 如果为`RESPONSE`则根据`response_info`中的元信息调用`sequence_id`对应的回调函数. + 此时第二层协议中的`data`则为服务方返回的Response(比如`EchoResponse`) + +## 发送请求的实现原理 +以`client->echo(echoRequest, responseCallback)`为例 +参考代码:[EchoService.h](https://gitee.com/irons/gayrpc/blob/master/examples/echo/pb/EchoService.h#L62) + +1. 客户端分配 sequence_id,以它为key将 responseCallback保存起来. +2. 将echoRequest序列化为binary作为第二层协议中的`data` +3. 构造RpcMeta对象,将echo函数对应的id号作为request_info的method,并设置sequence_id. +4. 将RpcMeta对象的binary作为第二层协议中的`meta` +5. 用第二层协议的数据写入第一层协议进行发送给服务端. + +## 发送Response的实现原理 +以`replyObj->reply(echoResponse)`为例 +参考代码:[EchoService.h](https://gitee.com/irons/gayrpc/blob/master/examples/echo/pb/EchoService.h#L237) + +1. 首先replyObj里(拷贝)储存了来自于请求中的RpcMata对象. +2. 将echoResponse序列化为binary作为第二层协议中的`data` +3. 构造RpcMeta对象,将备份的RpcMeta对象中的sequence_id设置到前者中response_info的sequence_id. +4. 将RpcMeta对象的binary作为第二层协议中的`meta` +5. 用第二层协议的数据写入第一层协议进行发送给服务端. + +## 编解码参考 +* 对于发送请求或Response都可以走出站拦截器,用于统一的发送消息,最终的序列化参考代码: + [OpPacket.h](https://gitee.com/irons/gayrpc/blob/master/include/OpPacket.h#L138) +* 对于接收请求或Response则都可以走入站拦截器,统一的解析消息,参考代码: + [OpPacket.h](https://gitee.com/irons/gayrpc/blob/master/include/OpPacket.h#L97) + +## 注意点 +* 通信协议的第一层并不是重点,RPC核心在实现上尽量不要依赖它(目前的第一层协议只是某一种范例) +* 同样,RPC核心并不依赖通信采用的传输协议,可以是TCP也可以是UDP或者WebSocket +* RPC服务方的reply顺序与客户端的调用顺序无关,也就是可能后发起的请求先得到返回. diff --git a/core_proto/gayrpc_option.proto b/core_proto/gayrpc_option.proto new file mode 100644 index 0000000..06e5344 --- /dev/null +++ b/core_proto/gayrpc_option.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.MethodOptions { + int32 message_id = 51002; + int32 flag = 51003; +} \ No newline at end of file diff --git a/core_proto/meta.proto b/core_proto/meta.proto new file mode 100644 index 0000000..8118396 --- /dev/null +++ b/core_proto/meta.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; + +package gayrpc.core; + +message RpcMeta { + enum Type { + REQUEST = 0; + RESPONSE = 1; + }; + + enum DataEncodingType { + BINARY = 0; + JSON = 1; + }; + + message Request { + // 请求的服务函数 + uint64 method = 1; + // 请求方是否期待服务方返回response + bool expect_response = 2; + // 请求方的序号ID + uint64 sequence_id = 3; + }; + + message Response { + // 请求方的序号ID + uint64 sequence_id = 1; + // 执行是否成功 + bool failed = 2; + // (当failed为true)错误码 + int32 error_code = 3; + // (当failed为true)错误原因 + string reason = 4; + }; + + // Rpc类型(请求、回应) + Type type = 1; + // RpcData的编码方式 + DataEncodingType encoding = 2; + // 请求元信息 + Request request_info = 3; + // 回应元信息 + Response response_info = 4; +} \ No newline at end of file diff --git a/examples/benchmark/BenchmarkClient.cpp b/examples/benchmark/BenchmarkClient.cpp new file mode 100644 index 0000000..69776b6 --- /dev/null +++ b/examples/benchmark/BenchmarkClient.cpp @@ -0,0 +1,255 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "OpPacket.h" +#include "GayRpcInterceptor.h" +#include "UtilsDataHandler.h" +#include "UtilsInterceptor.h" +#include "WaitGroup.h" + +#include "./pb/benchmark_service.gayrpc.h" + +using namespace brynet; +using namespace brynet::net; +using namespace utils_interceptor; +using namespace dodo::benchmark; + +typedef std::vector LATENTY_TYPE; +typedef std::shared_ptr LATENCY_PTR; + +class BenchmarkClient : public std::enable_shared_from_this +{ +public: + BenchmarkClient(const benchmark_service::EchoServerClient::PTR& client, + const WaitGroup::PTR& wg, + int maxNum, + LATENCY_PTR latency, + std::string payload) + { + mClient = client; + mWg = wg; + maxRequestNum = maxNum; + mCurrentNum = 0; + mLatency = latency; + mPayload = payload; + } + + void sendRequest() + { + // 发送RPC请求 + EchoRequest request; + request.set_message(mPayload); + + mRequestTime = std::chrono::steady_clock::now(); + mClient->echo(request, std::bind(&BenchmarkClient::onEchoResponse, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); + } + +private: + void onEchoResponse(const EchoResponse& response, + const gayrpc::core::RpcError& error) + { + mCurrentNum++; + mLatency->push_back((std::chrono::steady_clock::now() - mRequestTime)); + + if (error.failed()) + { + std::cout << "reason" << error.reason() << std::endl; + return; + } + + if (mCurrentNum < maxRequestNum) + { + sendRequest(); + } + else + { + mWg->done(); + } + } + +private: + WaitGroup::PTR mWg; + benchmark_service::EchoServerClient::PTR mClient; + int mCurrentNum; + int maxRequestNum; + LATENCY_PTR mLatency; + std::chrono::steady_clock::time_point mRequestTime; + std::string mPayload; +}; + +std::atomic connectionCounter(0); + +static void onConnection(const TCPSession::PTR& session, + const WaitGroup::PTR& wg, + int maxRequestNum, + LATENCY_PTR latency, + std::string payload) +{ + connectionCounter++; + std::cout << "connection counter is:" << connectionCounter << std::endl; + + auto rpcHandlerManager = std::make_shared(); + session->setDataCallback([rpcHandlerManager](const TCPSession::PTR& session, + const char* buffer, + size_t len) { + return dataHandle(rpcHandlerManager, buffer, len); + }); + + // 入站拦截器 + auto inboundInterceptor = gayrpc::utils::makeInterceptor(withProtectedCall()); + + // 出站拦截器 + auto outBoundInterceptor = gayrpc::utils::makeInterceptor(withSessionSender(std::weak_ptr(session))); + + // 注册RPC客户端 + auto client = benchmark_service::EchoServerClient::Create(rpcHandlerManager, outBoundInterceptor, inboundInterceptor); + auto b = std::make_shared(client, wg, maxRequestNum, latency, payload); + b->sendRequest(); +} + +int main(int argc, char **argv) +{ + if (argc != 6) + { + fprintf(stderr, "Usage: \n"); + exit(-1); + } + + auto server = std::make_shared(); + server->startWorkThread(std::thread::hardware_concurrency()); + + auto connector = AsyncConnector::Create(); + connector->startWorkerThread(); + auto clientNum = std::atoi(argv[3]); + auto maxRequestNumEveryClient = std::atoi(argv[4]) / clientNum; + auto realyTotalRequestNum = maxRequestNumEveryClient * clientNum; + auto payload = std::string(std::atoi(argv[5]), 'a'); + + auto wg = WaitGroup::Create(); + + std::vector latencyArray; + + auto startTime = std::chrono::steady_clock::now(); + + for (int i = 0; i < clientNum; i++) + { + wg->add(); + + try + { + auto latency = std::make_shared(); + latencyArray.push_back(latency); + + connector->asyncConnect( + argv[1], + atoi(argv[2]), + std::chrono::seconds(10), + [server, wg, maxRequestNumEveryClient, latency, payload](TcpSocket::PTR socket) { + std::cout << "connect success" << std::endl; + socket->SocketNodelay(); + server->addSession( + std::move(socket), + std::bind(onConnection, std::placeholders::_1, wg, maxRequestNumEveryClient, latency, payload), + false, + nullptr, + 1024 * 1024); + }, []() { + std::cout << "connect failed" << std::endl; + }); + } + catch (std::runtime_error& e) + { + std::cout << "error:" << e.what() << std::endl; + } + } + + wg->wait(); + + auto nowTime = std::chrono::steady_clock::now(); + + std::chrono::nanoseconds totalLatenty = std::chrono::nanoseconds::zero(); + LATENTY_TYPE tmp1; + + for (auto& v : latencyArray) + { + for (auto& latency: *v) + { + totalLatenty += latency; + tmp1.push_back(latency); + } + } + std::sort(tmp1.begin(), tmp1.end()); + + auto costTime = std::chrono::duration_cast(nowTime - startTime); + + std::cout << "connection num:" + << connectionCounter + << std::endl; + + std::cout << "took " + << costTime.count() + << "ms, for " + << realyTotalRequestNum + << " requests" + << std::endl; + + std::cout << "throughput (TPS):" + << (realyTotalRequestNum/(std::chrono::duration_cast(costTime)).count()) + << std::endl; + + std::cout << "mean:" + << (std::chrono::duration_cast(totalLatenty).count() / realyTotalRequestNum) + << " ms ," + << (totalLatenty.count() / realyTotalRequestNum) + << " ns" + << std::endl; + + if (tmp1.empty()) + { + std::cout << "latenty is empty" << std::endl; + return 0; + } + + std::cout << "median:" + << (std::chrono::duration_cast(tmp1[tmp1.size()/2]).count()) + << " ms ," + << (tmp1[tmp1.size() / 2].count()) + << " ns" + << std::endl; + + std::cout << "max:" + << (std::chrono::duration_cast(tmp1[tmp1.size()-1]).count()) + << " ms ," + << (tmp1[tmp1.size() - 1].count()) + << " ns" + << std::endl; + + std::cout << "min:" + << (std::chrono::duration_cast(tmp1[0]).count()) + << " ms ," + << (tmp1[0].count()) + << " ns" + << std::endl; + + auto p99Index = tmp1.size() * 99 / 100; + std::chrono::nanoseconds p99Total = std::chrono::nanoseconds::zero(); + for (size_t i = 0; i < p99Index; i++) + { + p99Total += tmp1[i]; + } + std::cout << "p99:" + << (std::chrono::duration_cast(p99Total).count()/ p99Index) + << " ms ," + << (p99Total.count() / p99Index) + << " ns" + << std::endl; + return 0; +} diff --git a/examples/benchmark/BenchmarkServer.cpp b/examples/benchmark/BenchmarkServer.cpp new file mode 100644 index 0000000..04e7f42 --- /dev/null +++ b/examples/benchmark/BenchmarkServer.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "meta.pb.h" +#include "GayRpcCore.h" +#include "OpPacket.h" +#include "UtilsDataHandler.h" +#include "GayRpcInterceptor.h" +#include "UtilsInterceptor.h" + +#include "./pb/benchmark_service.gayrpc.h" + +using namespace brynet; +using namespace brynet::net; +using namespace utils_interceptor; +using namespace dodo::benchmark; +using namespace gayrpc::core; + +std::atomic count(0); + +class MyService : public benchmark_service::EchoServerService +{ +public: + bool echo(const EchoRequest& request, + const benchmark_service::EchoReply::PTR& replyObj) override + { + EchoResponse response; + response.set_message(request.message()); + + replyObj->reply(response); + + return true; + } +}; + +static void counter(const RpcMeta& meta, const google::protobuf::Message& message, const UnaryHandler& next) +{ + count++; + next(meta, message); +} + +static void onConnection(const TCPSession::PTR& session) +{ + auto rpcHandlerManager = std::make_shared(); + session->setDataCallback([rpcHandlerManager](const TCPSession::PTR& session, + const char* buffer, + size_t len) { + return dataHandle(rpcHandlerManager, buffer, len); + }); + + // 入站拦截器 + auto inboundInterceptor = gayrpc::utils::makeInterceptor(withProtectedCall(), counter); + + // 出站拦截器 + auto outBoundInterceptor = gayrpc::utils::makeInterceptor(withSessionSender(std::weak_ptr(session))); + + // 创建服务对象 + auto rpcServer = std::make_shared(); + registerEchoServerService(rpcHandlerManager, rpcServer, inboundInterceptor, outBoundInterceptor); +} + +int main(int argc, char **argv) +{ + if (argc != 2) + { + fprintf(stderr, "Usage: \n"); + exit(-1); + } + + auto server = std::make_shared(); + auto listenThread = ListenThread::Create(); + + listenThread->startListen( + false, + "0.0.0.0", + atoi(argv[1]), + [=](TcpSocket::PTR socket){ + socket->SocketNodelay(); + server->addSession(std::move(socket), + onConnection, + false, + nullptr, + 1024*1024); + }); + + server->startWorkThread(std::thread::hardware_concurrency()); + + EventLoop mainLoop; + std::atomic tmp(0); + + while (true) + { + mainLoop.loop(1000); + std::cout << "count is:" << (count-tmp) << std::endl; + tmp.store(count); + } +} diff --git a/examples/benchmark/CMakeLists.txt b/examples/benchmark/CMakeLists.txt new file mode 100644 index 0000000..bffcb40 --- /dev/null +++ b/examples/benchmark/CMakeLists.txt @@ -0,0 +1,15 @@ +add_executable(benchmark_client BenchmarkClient.cpp ./pb/benchmark_service.pb.cc ../../include/gayrpc_option.pb.cc ../../include/meta.pb.cc) +if(WIN32) + target_link_libraries(benchmark_client ws2_32 brynet) +elseif(UNIX) + find_package(Threads REQUIRED) + target_link_libraries(benchmark_client pthread brynet protobuf) +endif() + +add_executable(benchmark_server BenchmarkServer.cpp ./pb/benchmark_service.pb.cc ../../include/gayrpc_option.pb.cc ../../include/meta.pb.cc) +if(WIN32) + target_link_libraries(benchmark_server ws2_32 brynet) +elseif(UNIX) + find_package(Threads REQUIRED) + target_link_libraries(benchmark_server pthread brynet protobuf) +endif() diff --git a/examples/benchmark/WaitGroup.h b/examples/benchmark/WaitGroup.h new file mode 100644 index 0000000..2dbbaff --- /dev/null +++ b/examples/benchmark/WaitGroup.h @@ -0,0 +1,54 @@ +#ifndef _WAIT_GROUP_H +#define _WAIT_GROUP_H + +#include +#include +#include +#include + +#include + +class WaitGroup : public brynet::NonCopyable +{ +public: + typedef std::shared_ptr PTR; + + static PTR Create() + { + struct make_shared_enabler : public WaitGroup {}; + return std::make_shared(); + } + +public: + void add(int i = 1) + { + mCounter += i; + } + + void done() + { + mCounter--; + mCond.notify_all(); + } + + void wait() + { + std::unique_lock l(mMutex); + mCond.wait(l, [&] { return mCounter <= 0; }); + } + +private: + WaitGroup() + { + } + + virtual ~WaitGroup() + {} + +private: + std::mutex mMutex; + std::atomic mCounter; + std::condition_variable mCond; +}; + +#endif diff --git a/examples/benchmark/pb/benchmark_service.gayrpc.h b/examples/benchmark/pb/benchmark_service.gayrpc.h new file mode 100644 index 0000000..e970c78 --- /dev/null +++ b/examples/benchmark/pb/benchmark_service.gayrpc.h @@ -0,0 +1,179 @@ +// Generated by github.com/IronsDu/protoc-gen-gayrpc +// Coding by github.com/liuhan907 +// DO NOT EDIT!!! + +#ifndef _BENCHMARK_SERVICE_H +#define _BENCHMARK_SERVICE_H + +#include +#include +#include +#include + +#include + +#include "meta.pb.h" +#include "benchmark_service.pb.h" + +#include "GayRpcCore.h" +#include "GayRpcError.h" +#include "GayRpcTypeHandler.h" +#include "GayRpcClient.h" +#include "GayRpcService.h" +#include "GayRpcReply.h" + +namespace dodo { +namespace benchmark { + +namespace benchmark_service +{ + using namespace gayrpc::core; + using namespace google::protobuf::util; + + + enum class EchoServerMsgID:uint64_t + { + echo = 2333, + + }; + + class EchoServerClient : public BaseClient + { + public: + typedef std::shared_ptr PTR; + + typedef std::function EchoHandle; + + + public: + void echo(const dodo::benchmark::EchoRequest& request, + const EchoHandle& handle = nullptr) + { + call(request, static_cast(EchoServerMsgID::echo), handle); + } + + + public: + static PTR Create(const RpcTypeHandleManager::PTR& rpcHandlerManager, + const UnaryServerInterceptor& outboundInterceptor, + const UnaryServerInterceptor& inboundInterceptor) + { + struct make_shared_enabler : public EchoServerClient + { + public: + make_shared_enabler(const UnaryServerInterceptor& outboundInterceptor, + const UnaryServerInterceptor& inboundInterceptor) + : + EchoServerClient(outboundInterceptor, inboundInterceptor) {} + }; + + auto client = PTR(new make_shared_enabler(outboundInterceptor, inboundInterceptor)); + client->installResponseStub(rpcHandlerManager); + + return client; + } + + private: + using BaseClient::BaseClient; + }; + + typedef TemplateReply EchoReply; + + + class EchoServerService : public BaseService + { + public: + typedef std::shared_ptr PTR; + virtual ~EchoServerService() + { + } + + virtual void onClose() {} + + private: + virtual bool echo(const dodo::benchmark::EchoRequest& request, + const EchoReply::PTR& replyObj) = 0; + + + private: + friend void registerEchoServerService(gayrpc::core::RpcTypeHandleManager::PTR rpcTypeHandleManager, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor); + + static bool echo_stub(const RpcMeta& meta, + const std::string& data, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor) + { + dodo::benchmark::EchoRequest request; + if (!request.ParseFromString(data)) + { + std::cerr << "parse EchoRequst error " << std::endl; + return false; + } + + inboundInterceptor(meta, + request, + [service, + outboundInterceptor, + &request](const RpcMeta& meta, const google::protobuf::Message& message) { + auto replyObject = std::make_shared(meta, outboundInterceptor); + service->echo(request, replyObject); + }); + return true; + } + + }; + + inline void registerEchoServerService(gayrpc::core::RpcTypeHandleManager::PTR rpcTypeHandleManager, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor) + { + typedef std::function EchoServerServiceRequestHandler; + + typedef std::unordered_map EchoServerServiceHandlerMap; + + auto serviceHandlerMap = std::make_shared(); + + (*serviceHandlerMap)[static_cast(EchoServerMsgID::echo)] = EchoServerService::echo_stub; + + + auto requestStub = [service, + serviceHandlerMap, + inboundInterceptor, + outboundInterceptor](const RpcMeta& meta, const std::string& data) { + if (meta.type() == RpcMeta::REQUEST) + { + auto it = serviceHandlerMap->find(meta.request_info().method()); + if (it == serviceHandlerMap->end()) + { + std::cerr << "not found handle, method:" << meta.request_info().method(); + return false; + } + + (*it).second(meta, + data, + service, + inboundInterceptor, + outboundInterceptor); + } + return true; + }; + rpcTypeHandleManager->registerTypeHandle(RpcMeta::REQUEST, requestStub); + } + +} + +} +} + +#endif + diff --git a/examples/benchmark/pb/benchmark_service.pb.cc b/examples/benchmark/pb/benchmark_service.pb.cc new file mode 100644 index 0000000..c3b09f7 --- /dev/null +++ b/examples/benchmark/pb/benchmark_service.pb.cc @@ -0,0 +1,671 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: benchmark_service.proto + +#include "benchmark_service.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif +// @@protoc_insertion_point(includes) +namespace dodo { +namespace benchmark { +class EchoRequestDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _EchoRequest_default_instance_; +class EchoResponseDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _EchoResponse_default_instance_; +} // namespace benchmark +} // namespace dodo +namespace protobuf_benchmark_5fservice_2eproto { +void InitDefaultsEchoRequestImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::dodo::benchmark::_EchoRequest_default_instance_; + new (ptr) ::dodo::benchmark::EchoRequest(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::dodo::benchmark::EchoRequest::InitAsDefaultInstance(); +} + +void InitDefaultsEchoRequest() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsEchoRequestImpl); +} + +void InitDefaultsEchoResponseImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::dodo::benchmark::_EchoResponse_default_instance_; + new (ptr) ::dodo::benchmark::EchoResponse(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::dodo::benchmark::EchoResponse::InitAsDefaultInstance(); +} + +void InitDefaultsEchoResponse() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsEchoResponseImpl); +} + +::google::protobuf::Metadata file_level_metadata[2]; + +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::benchmark::EchoRequest, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::benchmark::EchoRequest, message_), + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::benchmark::EchoResponse, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::benchmark::EchoResponse, message_), +}; +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, sizeof(::dodo::benchmark::EchoRequest)}, + { 6, -1, sizeof(::dodo::benchmark::EchoResponse)}, +}; + +static ::google::protobuf::Message const * const file_default_instances[] = { + reinterpret_cast(&::dodo::benchmark::_EchoRequest_default_instance_), + reinterpret_cast(&::dodo::benchmark::_EchoResponse_default_instance_), +}; + +void protobuf_AssignDescriptors() { + AddDescriptors(); + ::google::protobuf::MessageFactory* factory = NULL; + AssignDescriptors( + "benchmark_service.proto", schemas, file_default_instances, TableStruct::offsets, factory, + file_level_metadata, NULL, NULL); +} + +void protobuf_AssignDescriptorsOnce() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors); +} + +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD; +void protobuf_RegisterTypes(const ::std::string&) { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 2); +} + +void AddDescriptorsImpl() { + InitDefaults(); + static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + "\n\027benchmark_service.proto\022\016dodo.benchmar" + "k\032\023gayrpc_option.proto\"\036\n\013EchoRequest\022\017\n" + "\007message\030\001 \001(\t\"\037\n\014EchoResponse\022\017\n\007messag" + "e\030\001 \001(\t2V\n\nEchoServer\022H\n\004Echo\022\033.dodo.ben" + "chmark.EchoRequest\032\034.dodo.benchmark.Echo" + "Response\"\005\320\363\030\235\022P\000b\006proto3" + }; + ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( + descriptor, 225); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( + "benchmark_service.proto", &protobuf_RegisterTypes); + ::protobuf_gayrpc_5foption_2eproto::AddDescriptors(); +} + +void AddDescriptors() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); +} +// Force AddDescriptors() to be called at dynamic initialization time. +struct StaticDescriptorInitializer { + StaticDescriptorInitializer() { + AddDescriptors(); + } +} static_descriptor_initializer; +} // namespace protobuf_benchmark_5fservice_2eproto +namespace dodo { +namespace benchmark { + +// =================================================================== + +void EchoRequest::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int EchoRequest::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +EchoRequest::EchoRequest() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_benchmark_5fservice_2eproto::InitDefaultsEchoRequest(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:dodo.benchmark.EchoRequest) +} +EchoRequest::EchoRequest(const EchoRequest& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.message().size() > 0) { + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } + // @@protoc_insertion_point(copy_constructor:dodo.benchmark.EchoRequest) +} + +void EchoRequest::SharedCtor() { + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; +} + +EchoRequest::~EchoRequest() { + // @@protoc_insertion_point(destructor:dodo.benchmark.EchoRequest) + SharedDtor(); +} + +void EchoRequest::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void EchoRequest::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* EchoRequest::descriptor() { + ::protobuf_benchmark_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_benchmark_5fservice_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const EchoRequest& EchoRequest::default_instance() { + ::protobuf_benchmark_5fservice_2eproto::InitDefaultsEchoRequest(); + return *internal_default_instance(); +} + +EchoRequest* EchoRequest::New(::google::protobuf::Arena* arena) const { + EchoRequest* n = new EchoRequest; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void EchoRequest::Clear() { +// @@protoc_insertion_point(message_clear_start:dodo.benchmark.EchoRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); +} + +bool EchoRequest::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:dodo.benchmark.EchoRequest) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // string message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "dodo.benchmark.EchoRequest.message")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:dodo.benchmark.EchoRequest) + return true; +failure: + // @@protoc_insertion_point(parse_failure:dodo.benchmark.EchoRequest) + return false; +#undef DO_ +} + +void EchoRequest::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:dodo.benchmark.EchoRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.benchmark.EchoRequest.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->message(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:dodo.benchmark.EchoRequest) +} + +::google::protobuf::uint8* EchoRequest::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:dodo.benchmark.EchoRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.benchmark.EchoRequest.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->message(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:dodo.benchmark.EchoRequest) + return target; +} + +size_t EchoRequest::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:dodo.benchmark.EchoRequest) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string message = 1; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void EchoRequest::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:dodo.benchmark.EchoRequest) + GOOGLE_DCHECK_NE(&from, this); + const EchoRequest* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:dodo.benchmark.EchoRequest) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:dodo.benchmark.EchoRequest) + MergeFrom(*source); + } +} + +void EchoRequest::MergeFrom(const EchoRequest& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:dodo.benchmark.EchoRequest) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void EchoRequest::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:dodo.benchmark.EchoRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void EchoRequest::CopyFrom(const EchoRequest& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:dodo.benchmark.EchoRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool EchoRequest::IsInitialized() const { + return true; +} + +void EchoRequest::Swap(EchoRequest* other) { + if (other == this) return; + InternalSwap(other); +} +void EchoRequest::InternalSwap(EchoRequest* other) { + using std::swap; + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata EchoRequest::GetMetadata() const { + protobuf_benchmark_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_benchmark_5fservice_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// =================================================================== + +void EchoResponse::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int EchoResponse::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +EchoResponse::EchoResponse() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_benchmark_5fservice_2eproto::InitDefaultsEchoResponse(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:dodo.benchmark.EchoResponse) +} +EchoResponse::EchoResponse(const EchoResponse& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.message().size() > 0) { + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } + // @@protoc_insertion_point(copy_constructor:dodo.benchmark.EchoResponse) +} + +void EchoResponse::SharedCtor() { + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; +} + +EchoResponse::~EchoResponse() { + // @@protoc_insertion_point(destructor:dodo.benchmark.EchoResponse) + SharedDtor(); +} + +void EchoResponse::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void EchoResponse::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* EchoResponse::descriptor() { + ::protobuf_benchmark_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_benchmark_5fservice_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const EchoResponse& EchoResponse::default_instance() { + ::protobuf_benchmark_5fservice_2eproto::InitDefaultsEchoResponse(); + return *internal_default_instance(); +} + +EchoResponse* EchoResponse::New(::google::protobuf::Arena* arena) const { + EchoResponse* n = new EchoResponse; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void EchoResponse::Clear() { +// @@protoc_insertion_point(message_clear_start:dodo.benchmark.EchoResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); +} + +bool EchoResponse::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:dodo.benchmark.EchoResponse) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // string message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "dodo.benchmark.EchoResponse.message")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:dodo.benchmark.EchoResponse) + return true; +failure: + // @@protoc_insertion_point(parse_failure:dodo.benchmark.EchoResponse) + return false; +#undef DO_ +} + +void EchoResponse::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:dodo.benchmark.EchoResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.benchmark.EchoResponse.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->message(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:dodo.benchmark.EchoResponse) +} + +::google::protobuf::uint8* EchoResponse::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:dodo.benchmark.EchoResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.benchmark.EchoResponse.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->message(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:dodo.benchmark.EchoResponse) + return target; +} + +size_t EchoResponse::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:dodo.benchmark.EchoResponse) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string message = 1; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void EchoResponse::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:dodo.benchmark.EchoResponse) + GOOGLE_DCHECK_NE(&from, this); + const EchoResponse* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:dodo.benchmark.EchoResponse) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:dodo.benchmark.EchoResponse) + MergeFrom(*source); + } +} + +void EchoResponse::MergeFrom(const EchoResponse& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:dodo.benchmark.EchoResponse) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void EchoResponse::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:dodo.benchmark.EchoResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void EchoResponse::CopyFrom(const EchoResponse& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:dodo.benchmark.EchoResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool EchoResponse::IsInitialized() const { + return true; +} + +void EchoResponse::Swap(EchoResponse* other) { + if (other == this) return; + InternalSwap(other); +} +void EchoResponse::InternalSwap(EchoResponse* other) { + using std::swap; + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata EchoResponse::GetMetadata() const { + protobuf_benchmark_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_benchmark_5fservice_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// @@protoc_insertion_point(namespace_scope) +} // namespace benchmark +} // namespace dodo + +// @@protoc_insertion_point(global_scope) diff --git a/examples/benchmark/pb/benchmark_service.pb.h b/examples/benchmark/pb/benchmark_service.pb.h new file mode 100644 index 0000000..171c3c8 --- /dev/null +++ b/examples/benchmark/pb/benchmark_service.pb.h @@ -0,0 +1,416 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: benchmark_service.proto + +#ifndef PROTOBUF_benchmark_5fservice_2eproto__INCLUDED +#define PROTOBUF_benchmark_5fservice_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 3005000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3005000 < GOOGLE_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 + +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include "gayrpc_option.pb.h" // IWYU pragma: export +// @@protoc_insertion_point(includes) + +namespace protobuf_benchmark_5fservice_2eproto { +// Internal implementation detail -- do not use these members. +struct TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[2]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; + static const ::google::protobuf::uint32 offsets[]; +}; +void AddDescriptors(); +void InitDefaultsEchoRequestImpl(); +void InitDefaultsEchoRequest(); +void InitDefaultsEchoResponseImpl(); +void InitDefaultsEchoResponse(); +inline void InitDefaults() { + InitDefaultsEchoRequest(); + InitDefaultsEchoResponse(); +} +} // namespace protobuf_benchmark_5fservice_2eproto +namespace dodo { +namespace benchmark { +class EchoRequest; +class EchoRequestDefaultTypeInternal; +extern EchoRequestDefaultTypeInternal _EchoRequest_default_instance_; +class EchoResponse; +class EchoResponseDefaultTypeInternal; +extern EchoResponseDefaultTypeInternal _EchoResponse_default_instance_; +} // namespace benchmark +} // namespace dodo +namespace dodo { +namespace benchmark { + +// =================================================================== + +class EchoRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:dodo.benchmark.EchoRequest) */ { + public: + EchoRequest(); + virtual ~EchoRequest(); + + EchoRequest(const EchoRequest& from); + + inline EchoRequest& operator=(const EchoRequest& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + EchoRequest(EchoRequest&& from) noexcept + : EchoRequest() { + *this = ::std::move(from); + } + + inline EchoRequest& operator=(EchoRequest&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const EchoRequest& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const EchoRequest* internal_default_instance() { + return reinterpret_cast( + &_EchoRequest_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; + + void Swap(EchoRequest* other); + friend void swap(EchoRequest& a, EchoRequest& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline EchoRequest* New() const PROTOBUF_FINAL { return New(NULL); } + + EchoRequest* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const EchoRequest& from); + void MergeFrom(const EchoRequest& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(EchoRequest* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string message = 1; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::std::string& message() const; + void set_message(const ::std::string& value); + #if LANG_CXX11 + void set_message(::std::string&& value); + #endif + void set_message(const char* value); + void set_message(const char* value, size_t size); + ::std::string* mutable_message(); + ::std::string* release_message(); + void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:dodo.benchmark.EchoRequest) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend struct ::protobuf_benchmark_5fservice_2eproto::TableStruct; + friend void ::protobuf_benchmark_5fservice_2eproto::InitDefaultsEchoRequestImpl(); +}; +// ------------------------------------------------------------------- + +class EchoResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:dodo.benchmark.EchoResponse) */ { + public: + EchoResponse(); + virtual ~EchoResponse(); + + EchoResponse(const EchoResponse& from); + + inline EchoResponse& operator=(const EchoResponse& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + EchoResponse(EchoResponse&& from) noexcept + : EchoResponse() { + *this = ::std::move(from); + } + + inline EchoResponse& operator=(EchoResponse&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const EchoResponse& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const EchoResponse* internal_default_instance() { + return reinterpret_cast( + &_EchoResponse_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; + + void Swap(EchoResponse* other); + friend void swap(EchoResponse& a, EchoResponse& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline EchoResponse* New() const PROTOBUF_FINAL { return New(NULL); } + + EchoResponse* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const EchoResponse& from); + void MergeFrom(const EchoResponse& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(EchoResponse* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string message = 1; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::std::string& message() const; + void set_message(const ::std::string& value); + #if LANG_CXX11 + void set_message(::std::string&& value); + #endif + void set_message(const char* value); + void set_message(const char* value, size_t size); + ::std::string* mutable_message(); + ::std::string* release_message(); + void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:dodo.benchmark.EchoResponse) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend struct ::protobuf_benchmark_5fservice_2eproto::TableStruct; + friend void ::protobuf_benchmark_5fservice_2eproto::InitDefaultsEchoResponseImpl(); +}; +// =================================================================== + + +// =================================================================== + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// EchoRequest + +// string message = 1; +inline void EchoRequest::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& EchoRequest::message() const { + // @@protoc_insertion_point(field_get:dodo.benchmark.EchoRequest.message) + return message_.GetNoArena(); +} +inline void EchoRequest::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:dodo.benchmark.EchoRequest.message) +} +#if LANG_CXX11 +inline void EchoRequest::set_message(::std::string&& value) { + + message_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:dodo.benchmark.EchoRequest.message) +} +#endif +inline void EchoRequest::set_message(const char* value) { + GOOGLE_DCHECK(value != NULL); + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:dodo.benchmark.EchoRequest.message) +} +inline void EchoRequest::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:dodo.benchmark.EchoRequest.message) +} +inline ::std::string* EchoRequest::mutable_message() { + + // @@protoc_insertion_point(field_mutable:dodo.benchmark.EchoRequest.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* EchoRequest::release_message() { + // @@protoc_insertion_point(field_release:dodo.benchmark.EchoRequest.message) + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void EchoRequest::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:dodo.benchmark.EchoRequest.message) +} + +// ------------------------------------------------------------------- + +// EchoResponse + +// string message = 1; +inline void EchoResponse::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& EchoResponse::message() const { + // @@protoc_insertion_point(field_get:dodo.benchmark.EchoResponse.message) + return message_.GetNoArena(); +} +inline void EchoResponse::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:dodo.benchmark.EchoResponse.message) +} +#if LANG_CXX11 +inline void EchoResponse::set_message(::std::string&& value) { + + message_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:dodo.benchmark.EchoResponse.message) +} +#endif +inline void EchoResponse::set_message(const char* value) { + GOOGLE_DCHECK(value != NULL); + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:dodo.benchmark.EchoResponse.message) +} +inline void EchoResponse::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:dodo.benchmark.EchoResponse.message) +} +inline ::std::string* EchoResponse::mutable_message() { + + // @@protoc_insertion_point(field_mutable:dodo.benchmark.EchoResponse.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* EchoResponse::release_message() { + // @@protoc_insertion_point(field_release:dodo.benchmark.EchoResponse.message) + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void EchoResponse::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:dodo.benchmark.EchoResponse.message) +} + +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ +// ------------------------------------------------------------------- + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace benchmark +} // namespace dodo + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_benchmark_5fservice_2eproto__INCLUDED diff --git a/examples/benchmark/pb/benchmark_service.proto b/examples/benchmark/pb/benchmark_service.proto new file mode 100644 index 0000000..22d92ff --- /dev/null +++ b/examples/benchmark/pb/benchmark_service.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dodo.benchmark; +import public "gayrpc_option.proto"; + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} + +service EchoServer { + rpc Echo(EchoRequest) returns(EchoResponse) { + option (message_id)= 2333; + }; +} \ No newline at end of file diff --git a/examples/echo/CMakeLists.txt b/examples/echo/CMakeLists.txt new file mode 100644 index 0000000..b43a66e --- /dev/null +++ b/examples/echo/CMakeLists.txt @@ -0,0 +1,15 @@ +add_executable(echoclient EchoClient.cpp ./pb/echo_service.pb.cc ../../include/gayrpc_option.pb.cc ../../include/meta.pb.cc) +if(WIN32) + target_link_libraries(echoclient ws2_32 brynet) +elseif(UNIX) + find_package(Threads REQUIRED) + target_link_libraries(echoclient pthread brynet protobuf) +endif() + +add_executable(echoserver EchoServer.cpp ./pb/echo_service.pb.cc ../../include/gayrpc_option.pb.cc ../../include/meta.pb.cc) +if(WIN32) + target_link_libraries(echoserver ws2_32 brynet) +elseif(UNIX) + find_package(Threads REQUIRED) + target_link_libraries(echoserver pthread brynet protobuf) +endif() diff --git a/examples/echo/EchoClient.cpp b/examples/echo/EchoClient.cpp new file mode 100644 index 0000000..c7571ea --- /dev/null +++ b/examples/echo/EchoClient.cpp @@ -0,0 +1,141 @@ +#include +#include + +#include +#include +#include +#include + +#include "OpPacket.h" +#include "GayRpcInterceptor.h" +#include "UtilsDataHandler.h" +#include "UtilsInterceptor.h" +#include "GayRpcClient.h" + +#include "./pb/echo_service.gayrpc.h" + +using namespace brynet; +using namespace brynet::net; +using namespace utils_interceptor; +using namespace dodo::test; + +class MyService : public echo_service::EchoServerService +{ +public: + MyService(const std::shared_ptr& client) + : + mClient(client) + { + } + + bool echo(const EchoRequest& request, + const echo_service::EchoReply::PTR& replyObj) override + { + EchoResponse response; + response.set_message("world"); + + replyObj->reply(response); // 重复reply或error将产生异常 + // 在收到请求后再调用对端 + mClient->echo(request, [](const EchoResponse& response, const gayrpc::core::RpcError& err) { + err.failed(); + }); + + return true; + } + + bool login(const LoginRequest& request, + const echo_service::LoginReply::PTR& replyObj) override + { + return true; + } + +private: + std::shared_ptr mClient; +}; + +static void onConnection(const TCPSession::PTR& session) +{ + auto rpcHandlerManager = std::make_shared(); + session->setDataCallback([rpcHandlerManager](const TCPSession::PTR& session, + const char* buffer, + size_t len) { + return dataHandle(rpcHandlerManager, buffer, len); + }); + + // 入站拦截器 + auto inboundInterceptor = gayrpc::utils::makeInterceptor(withProtectedCall()); + + // 出站拦截器 + auto outBoundInterceptor = gayrpc::utils::makeInterceptor(withSessionSender(std::weak_ptr(session))); + + // 注册RPC客户端 + auto client = echo_service::EchoServerClient::Create(rpcHandlerManager, outBoundInterceptor, inboundInterceptor); + + auto rpcServer = std::make_shared(client); + registerEchoServerService(rpcHandlerManager, rpcServer, inboundInterceptor, outBoundInterceptor); + + session->setDisConnectCallback([rpcServer](const TCPSession::PTR& session) { + std::cout << "close session" << std::endl; + rpcServer->onClose(); + }); + + // 发送RPC请求 + EchoRequest request; + request.set_message("hello"); + + client->echo(request, [](const EchoResponse& response, + const gayrpc::core::RpcError& error) { + if (error.failed()) + { + std::cout << "reason" << error.reason() << std::endl; + return; + } + //std::cout << "recv reply, data:" << response.message() << std::endl; + }); +} + +int main(int argc, char **argv) +{ + if (argc != 4) + { + fprintf(stderr, "Usage: \n"); + exit(-1); + } + + auto server = std::make_shared(); + server->startWorkThread(std::thread::hardware_concurrency()); + + auto connector = AsyncConnector::Create(); + connector->startWorkerThread(); + auto num = std::atoi(argv[3]); + + for (int i = 0; i < num; i++) + { + try + { + connector->asyncConnect( + argv[1], + atoi(argv[2]), + std::chrono::seconds(10), + [server](TcpSocket::PTR socket) { + std::cout << "connect success" << std::endl; + socket->SocketNodelay(); + server->addSession( + std::move(socket), + onConnection, + false, + nullptr, + 1024 * 1024); + }, []() { + std::cout << "connect failed" << std::endl; + }); + } + catch (std::runtime_error& e) + { + std::cout << "error:" << e.what() << std::endl; + } + } + + + std::cin.get(); +} diff --git a/examples/echo/EchoServer.cpp b/examples/echo/EchoServer.cpp new file mode 100644 index 0000000..90b65b6 --- /dev/null +++ b/examples/echo/EchoServer.cpp @@ -0,0 +1,136 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "meta.pb.h" +#include "GayRpcCore.h" +#include "OpPacket.h" +#include "UtilsDataHandler.h" +#include "GayRpcInterceptor.h" +#include "UtilsInterceptor.h" + +#include "./pb/echo_service.gayrpc.h" + +using namespace brynet; +using namespace brynet::net; +using namespace utils_interceptor; +using namespace gayrpc::core; +using namespace dodo::test; + +std::atomic count(0); + +class MyService : public echo_service::EchoServerService +{ +public: + MyService(const std::shared_ptr& client) + : + mClient(client) + { + } + + bool echo(const EchoRequest& request, + const echo_service::EchoReply::PTR& replyObj) override + { + EchoResponse response; + response.set_message("world"); + + replyObj->reply(response); + + EchoRequest r; + r.set_message("hello"); + mClient->echo(r, [](const EchoResponse& response, const gayrpc::core::RpcError& err) { + err.failed(); + }); + + return true; + } + + bool login(const LoginRequest& request, + const echo_service::LoginReply::PTR& replyObj) override + { + return true; + } + +private: + std::shared_ptr mClient; +}; + +static void counter(const RpcMeta& meta, const google::protobuf::Message& message, const UnaryHandler& next) +{ + count++; + next(meta, message); +} + +static void onConnection(const TCPSession::PTR& session) +{ + std::cout << "connection enter" << std::endl; + + auto rpcHandlerManager = std::make_shared(); + session->setDataCallback([rpcHandlerManager](const TCPSession::PTR& session, + const char* buffer, + size_t len) { + return dataHandle(rpcHandlerManager, buffer, len); + }); + + // 入站拦截器 + auto inboundInterceptor = gayrpc::utils::makeInterceptor(withProtectedCall(), counter); + + // 出站拦截器 + auto outBoundInterceptor = gayrpc::utils::makeInterceptor(withSessionSender(std::weak_ptr(session))); + + // 创建客户端 + auto client = echo_service::EchoServerClient::Create(rpcHandlerManager, outBoundInterceptor, inboundInterceptor); + + // 创建服务 + auto rpcServer = std::make_shared(client); + registerEchoServerService(rpcHandlerManager, rpcServer, inboundInterceptor, outBoundInterceptor); + + session->setDisConnectCallback([rpcServer](const TCPSession::PTR& session) { + std::cout << "close session" << std::endl; + rpcServer->onClose(); + }); +} + +int main(int argc, char **argv) +{ + if (argc != 2) + { + fprintf(stderr, "Usage: \n"); + exit(-1); + } + + auto server = std::make_shared(); + auto listenThread = ListenThread::Create(); + + listenThread->startListen( + false, + "0.0.0.0", + atoi(argv[1]), + [=](TcpSocket::PTR socket){ + socket->SocketNodelay(); + server->addSession(std::move(socket), + onConnection, + false, + nullptr, + 1024*1024); + }); + + server->startWorkThread(std::thread::hardware_concurrency()); + + EventLoop mainLoop; + std::atomic tmp(0); + while (true) + { + mainLoop.loop(1000); + std::cout << "count is:" << (count-tmp) << std::endl; + tmp.store(count); + } +} diff --git a/examples/echo/pb/echo_service.gayrpc.h b/examples/echo/pb/echo_service.gayrpc.h new file mode 100644 index 0000000..a8eb4cb --- /dev/null +++ b/examples/echo/pb/echo_service.gayrpc.h @@ -0,0 +1,214 @@ +// Generated by github.com/IronsDu/protoc-gen-gayrpc +// Coding by github.com/liuhan907 +// DO NOT EDIT!!! + +#ifndef _ECHO_SERVICE_H +#define _ECHO_SERVICE_H + +#include +#include +#include +#include + +#include + +#include "meta.pb.h" +#include "echo_service.pb.h" + +#include "GayRpcCore.h" +#include "GayRpcError.h" +#include "GayRpcTypeHandler.h" +#include "GayRpcClient.h" +#include "GayRpcService.h" +#include "GayRpcReply.h" + +namespace dodo { +namespace test { + +namespace echo_service +{ + using namespace gayrpc::core; + using namespace google::protobuf::util; + + + enum class EchoServerMsgID:uint64_t + { + echo = 2333, + login = 3333, + + }; + + class EchoServerClient : public BaseClient + { + public: + typedef std::shared_ptr PTR; + + typedef std::function EchoHandle; + typedef std::function LoginHandle; + + + public: + void echo(const dodo::test::EchoRequest& request, + const EchoHandle& handle = nullptr) + { + call(request, static_cast(EchoServerMsgID::echo), handle); + } + void login(const dodo::test::LoginRequest& request, + const LoginHandle& handle = nullptr) + { + call(request, static_cast(EchoServerMsgID::login), handle); + } + + + public: + static PTR Create(const RpcTypeHandleManager::PTR& rpcHandlerManager, + const UnaryServerInterceptor& outboundInterceptor, + const UnaryServerInterceptor& inboundInterceptor) + { + struct make_shared_enabler : public EchoServerClient + { + public: + make_shared_enabler(const UnaryServerInterceptor& outboundInterceptor, + const UnaryServerInterceptor& inboundInterceptor) + : + EchoServerClient(outboundInterceptor, inboundInterceptor) {} + }; + + auto client = PTR(new make_shared_enabler(outboundInterceptor, inboundInterceptor)); + client->installResponseStub(rpcHandlerManager); + + return client; + } + + private: + using BaseClient::BaseClient; + }; + + typedef TemplateReply EchoReply; + typedef TemplateReply LoginReply; + + + class EchoServerService : public BaseService + { + public: + typedef std::shared_ptr PTR; + virtual ~EchoServerService() + { + } + + virtual void onClose() {} + + private: + virtual bool echo(const dodo::test::EchoRequest& request, + const EchoReply::PTR& replyObj) = 0; + virtual bool login(const dodo::test::LoginRequest& request, + const LoginReply::PTR& replyObj) = 0; + + + private: + friend void registerEchoServerService(gayrpc::core::RpcTypeHandleManager::PTR rpcTypeHandleManager, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor); + + static bool echo_stub(const RpcMeta& meta, + const std::string& data, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor) + { + dodo::test::EchoRequest request; + if (!request.ParseFromString(data)) + { + std::cerr << "parse EchoRequst error " << std::endl; + return false; + } + + inboundInterceptor(meta, + request, + [service, + outboundInterceptor, + &request](const RpcMeta& meta, const google::protobuf::Message& message) { + auto replyObject = std::make_shared(meta, outboundInterceptor); + service->echo(request, replyObject); + }); + return true; + } + static bool login_stub(const RpcMeta& meta, + const std::string& data, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor) + { + dodo::test::LoginRequest request; + if (!request.ParseFromString(data)) + { + std::cerr << "parse LoginRequst error " << std::endl; + return false; + } + + inboundInterceptor(meta, + request, + [service, + outboundInterceptor, + &request](const RpcMeta& meta, const google::protobuf::Message& message) { + auto replyObject = std::make_shared(meta, outboundInterceptor); + service->login(request, replyObject); + }); + return true; + } + + }; + + inline void registerEchoServerService(gayrpc::core::RpcTypeHandleManager::PTR rpcTypeHandleManager, + const EchoServerService::PTR& service, + const UnaryServerInterceptor& inboundInterceptor, + const UnaryServerInterceptor& outboundInterceptor) + { + typedef std::function EchoServerServiceRequestHandler; + + typedef std::unordered_map EchoServerServiceHandlerMap; + + auto serviceHandlerMap = std::make_shared(); + + (*serviceHandlerMap)[static_cast(EchoServerMsgID::echo)] = EchoServerService::echo_stub; + (*serviceHandlerMap)[static_cast(EchoServerMsgID::login)] = EchoServerService::login_stub; + + + auto requestStub = [service, + serviceHandlerMap, + inboundInterceptor, + outboundInterceptor](const RpcMeta& meta, const std::string& data) { + if (meta.type() == RpcMeta::REQUEST) + { + auto it = serviceHandlerMap->find(meta.request_info().method()); + if (it == serviceHandlerMap->end()) + { + std::cerr << "not found handle, method:" << meta.request_info().method(); + return false; + } + + (*it).second(meta, + data, + service, + inboundInterceptor, + outboundInterceptor); + } + return true; + }; + rpcTypeHandleManager->registerTypeHandle(RpcMeta::REQUEST, requestStub); + } + +} + +} +} + +#endif + diff --git a/examples/echo/pb/echo_service.pb.cc b/examples/echo/pb/echo_service.pb.cc new file mode 100644 index 0000000..3e8dd1a --- /dev/null +++ b/examples/echo/pb/echo_service.pb.cc @@ -0,0 +1,1254 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: echo_service.proto + +#include "echo_service.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif +// @@protoc_insertion_point(includes) +namespace dodo { +namespace test { +class EchoRequestDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _EchoRequest_default_instance_; +class LoginRequestDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _LoginRequest_default_instance_; +class EchoResponseDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _EchoResponse_default_instance_; +class LoginResponseDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _LoginResponse_default_instance_; +} // namespace test +} // namespace dodo +namespace protobuf_echo_5fservice_2eproto { +void InitDefaultsEchoRequestImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::dodo::test::_EchoRequest_default_instance_; + new (ptr) ::dodo::test::EchoRequest(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::dodo::test::EchoRequest::InitAsDefaultInstance(); +} + +void InitDefaultsEchoRequest() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsEchoRequestImpl); +} + +void InitDefaultsLoginRequestImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::dodo::test::_LoginRequest_default_instance_; + new (ptr) ::dodo::test::LoginRequest(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::dodo::test::LoginRequest::InitAsDefaultInstance(); +} + +void InitDefaultsLoginRequest() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsLoginRequestImpl); +} + +void InitDefaultsEchoResponseImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::dodo::test::_EchoResponse_default_instance_; + new (ptr) ::dodo::test::EchoResponse(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::dodo::test::EchoResponse::InitAsDefaultInstance(); +} + +void InitDefaultsEchoResponse() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsEchoResponseImpl); +} + +void InitDefaultsLoginResponseImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::dodo::test::_LoginResponse_default_instance_; + new (ptr) ::dodo::test::LoginResponse(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::dodo::test::LoginResponse::InitAsDefaultInstance(); +} + +void InitDefaultsLoginResponse() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsLoginResponseImpl); +} + +::google::protobuf::Metadata file_level_metadata[4]; + +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::EchoRequest, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::EchoRequest, message_), + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::LoginRequest, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::LoginRequest, message_), + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::EchoResponse, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::EchoResponse, message_), + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::LoginResponse, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::dodo::test::LoginResponse, message_), +}; +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, sizeof(::dodo::test::EchoRequest)}, + { 6, -1, sizeof(::dodo::test::LoginRequest)}, + { 12, -1, sizeof(::dodo::test::EchoResponse)}, + { 18, -1, sizeof(::dodo::test::LoginResponse)}, +}; + +static ::google::protobuf::Message const * const file_default_instances[] = { + reinterpret_cast(&::dodo::test::_EchoRequest_default_instance_), + reinterpret_cast(&::dodo::test::_LoginRequest_default_instance_), + reinterpret_cast(&::dodo::test::_EchoResponse_default_instance_), + reinterpret_cast(&::dodo::test::_LoginResponse_default_instance_), +}; + +void protobuf_AssignDescriptors() { + AddDescriptors(); + ::google::protobuf::MessageFactory* factory = NULL; + AssignDescriptors( + "echo_service.proto", schemas, file_default_instances, TableStruct::offsets, factory, + file_level_metadata, NULL, NULL); +} + +void protobuf_AssignDescriptorsOnce() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors); +} + +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD; +void protobuf_RegisterTypes(const ::std::string&) { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4); +} + +void AddDescriptorsImpl() { + InitDefaults(); + static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + "\n\022echo_service.proto\022\tdodo.test\032\023gayrpc_" + "option.proto\"\036\n\013EchoRequest\022\017\n\007message\030\001" + " \001(\t\"\037\n\014LoginRequest\022\017\n\007message\030\001 \001(\t\"\037\n" + "\014EchoResponse\022\017\n\007message\030\001 \001(\t\" \n\rLoginR" + "esponse\022\017\n\007message\030\001 \001(\t2\217\001\n\nEchoServer\022" + ">\n\004Echo\022\026.dodo.test.EchoRequest\032\027.dodo.t" + "est.EchoResponse\"\005\320\363\030\235\022\022A\n\005Login\022\027.dodo." + "test.LoginRequest\032\030.dodo.test.LoginRespo" + "nse\"\005\320\363\030\205\032P\000b\006proto3" + }; + ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( + descriptor, 340); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( + "echo_service.proto", &protobuf_RegisterTypes); + ::protobuf_gayrpc_5foption_2eproto::AddDescriptors(); +} + +void AddDescriptors() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); +} +// Force AddDescriptors() to be called at dynamic initialization time. +struct StaticDescriptorInitializer { + StaticDescriptorInitializer() { + AddDescriptors(); + } +} static_descriptor_initializer; +} // namespace protobuf_echo_5fservice_2eproto +namespace dodo { +namespace test { + +// =================================================================== + +void EchoRequest::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int EchoRequest::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +EchoRequest::EchoRequest() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_echo_5fservice_2eproto::InitDefaultsEchoRequest(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:dodo.test.EchoRequest) +} +EchoRequest::EchoRequest(const EchoRequest& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.message().size() > 0) { + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } + // @@protoc_insertion_point(copy_constructor:dodo.test.EchoRequest) +} + +void EchoRequest::SharedCtor() { + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; +} + +EchoRequest::~EchoRequest() { + // @@protoc_insertion_point(destructor:dodo.test.EchoRequest) + SharedDtor(); +} + +void EchoRequest::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void EchoRequest::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* EchoRequest::descriptor() { + ::protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const EchoRequest& EchoRequest::default_instance() { + ::protobuf_echo_5fservice_2eproto::InitDefaultsEchoRequest(); + return *internal_default_instance(); +} + +EchoRequest* EchoRequest::New(::google::protobuf::Arena* arena) const { + EchoRequest* n = new EchoRequest; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void EchoRequest::Clear() { +// @@protoc_insertion_point(message_clear_start:dodo.test.EchoRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); +} + +bool EchoRequest::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:dodo.test.EchoRequest) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // string message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "dodo.test.EchoRequest.message")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:dodo.test.EchoRequest) + return true; +failure: + // @@protoc_insertion_point(parse_failure:dodo.test.EchoRequest) + return false; +#undef DO_ +} + +void EchoRequest::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:dodo.test.EchoRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.EchoRequest.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->message(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:dodo.test.EchoRequest) +} + +::google::protobuf::uint8* EchoRequest::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:dodo.test.EchoRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.EchoRequest.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->message(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:dodo.test.EchoRequest) + return target; +} + +size_t EchoRequest::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:dodo.test.EchoRequest) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string message = 1; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void EchoRequest::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:dodo.test.EchoRequest) + GOOGLE_DCHECK_NE(&from, this); + const EchoRequest* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:dodo.test.EchoRequest) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:dodo.test.EchoRequest) + MergeFrom(*source); + } +} + +void EchoRequest::MergeFrom(const EchoRequest& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:dodo.test.EchoRequest) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void EchoRequest::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:dodo.test.EchoRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void EchoRequest::CopyFrom(const EchoRequest& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:dodo.test.EchoRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool EchoRequest::IsInitialized() const { + return true; +} + +void EchoRequest::Swap(EchoRequest* other) { + if (other == this) return; + InternalSwap(other); +} +void EchoRequest::InternalSwap(EchoRequest* other) { + using std::swap; + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata EchoRequest::GetMetadata() const { + protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// =================================================================== + +void LoginRequest::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int LoginRequest::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +LoginRequest::LoginRequest() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_echo_5fservice_2eproto::InitDefaultsLoginRequest(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:dodo.test.LoginRequest) +} +LoginRequest::LoginRequest(const LoginRequest& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.message().size() > 0) { + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } + // @@protoc_insertion_point(copy_constructor:dodo.test.LoginRequest) +} + +void LoginRequest::SharedCtor() { + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; +} + +LoginRequest::~LoginRequest() { + // @@protoc_insertion_point(destructor:dodo.test.LoginRequest) + SharedDtor(); +} + +void LoginRequest::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void LoginRequest::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* LoginRequest::descriptor() { + ::protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const LoginRequest& LoginRequest::default_instance() { + ::protobuf_echo_5fservice_2eproto::InitDefaultsLoginRequest(); + return *internal_default_instance(); +} + +LoginRequest* LoginRequest::New(::google::protobuf::Arena* arena) const { + LoginRequest* n = new LoginRequest; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void LoginRequest::Clear() { +// @@protoc_insertion_point(message_clear_start:dodo.test.LoginRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); +} + +bool LoginRequest::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:dodo.test.LoginRequest) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // string message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "dodo.test.LoginRequest.message")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:dodo.test.LoginRequest) + return true; +failure: + // @@protoc_insertion_point(parse_failure:dodo.test.LoginRequest) + return false; +#undef DO_ +} + +void LoginRequest::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:dodo.test.LoginRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.LoginRequest.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->message(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:dodo.test.LoginRequest) +} + +::google::protobuf::uint8* LoginRequest::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:dodo.test.LoginRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.LoginRequest.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->message(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:dodo.test.LoginRequest) + return target; +} + +size_t LoginRequest::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:dodo.test.LoginRequest) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string message = 1; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void LoginRequest::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:dodo.test.LoginRequest) + GOOGLE_DCHECK_NE(&from, this); + const LoginRequest* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:dodo.test.LoginRequest) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:dodo.test.LoginRequest) + MergeFrom(*source); + } +} + +void LoginRequest::MergeFrom(const LoginRequest& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:dodo.test.LoginRequest) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void LoginRequest::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:dodo.test.LoginRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void LoginRequest::CopyFrom(const LoginRequest& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:dodo.test.LoginRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool LoginRequest::IsInitialized() const { + return true; +} + +void LoginRequest::Swap(LoginRequest* other) { + if (other == this) return; + InternalSwap(other); +} +void LoginRequest::InternalSwap(LoginRequest* other) { + using std::swap; + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata LoginRequest::GetMetadata() const { + protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// =================================================================== + +void EchoResponse::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int EchoResponse::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +EchoResponse::EchoResponse() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_echo_5fservice_2eproto::InitDefaultsEchoResponse(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:dodo.test.EchoResponse) +} +EchoResponse::EchoResponse(const EchoResponse& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.message().size() > 0) { + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } + // @@protoc_insertion_point(copy_constructor:dodo.test.EchoResponse) +} + +void EchoResponse::SharedCtor() { + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; +} + +EchoResponse::~EchoResponse() { + // @@protoc_insertion_point(destructor:dodo.test.EchoResponse) + SharedDtor(); +} + +void EchoResponse::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void EchoResponse::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* EchoResponse::descriptor() { + ::protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const EchoResponse& EchoResponse::default_instance() { + ::protobuf_echo_5fservice_2eproto::InitDefaultsEchoResponse(); + return *internal_default_instance(); +} + +EchoResponse* EchoResponse::New(::google::protobuf::Arena* arena) const { + EchoResponse* n = new EchoResponse; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void EchoResponse::Clear() { +// @@protoc_insertion_point(message_clear_start:dodo.test.EchoResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); +} + +bool EchoResponse::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:dodo.test.EchoResponse) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // string message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "dodo.test.EchoResponse.message")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:dodo.test.EchoResponse) + return true; +failure: + // @@protoc_insertion_point(parse_failure:dodo.test.EchoResponse) + return false; +#undef DO_ +} + +void EchoResponse::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:dodo.test.EchoResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.EchoResponse.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->message(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:dodo.test.EchoResponse) +} + +::google::protobuf::uint8* EchoResponse::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:dodo.test.EchoResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.EchoResponse.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->message(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:dodo.test.EchoResponse) + return target; +} + +size_t EchoResponse::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:dodo.test.EchoResponse) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string message = 1; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void EchoResponse::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:dodo.test.EchoResponse) + GOOGLE_DCHECK_NE(&from, this); + const EchoResponse* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:dodo.test.EchoResponse) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:dodo.test.EchoResponse) + MergeFrom(*source); + } +} + +void EchoResponse::MergeFrom(const EchoResponse& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:dodo.test.EchoResponse) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void EchoResponse::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:dodo.test.EchoResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void EchoResponse::CopyFrom(const EchoResponse& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:dodo.test.EchoResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool EchoResponse::IsInitialized() const { + return true; +} + +void EchoResponse::Swap(EchoResponse* other) { + if (other == this) return; + InternalSwap(other); +} +void EchoResponse::InternalSwap(EchoResponse* other) { + using std::swap; + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata EchoResponse::GetMetadata() const { + protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// =================================================================== + +void LoginResponse::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int LoginResponse::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +LoginResponse::LoginResponse() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_echo_5fservice_2eproto::InitDefaultsLoginResponse(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:dodo.test.LoginResponse) +} +LoginResponse::LoginResponse(const LoginResponse& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.message().size() > 0) { + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } + // @@protoc_insertion_point(copy_constructor:dodo.test.LoginResponse) +} + +void LoginResponse::SharedCtor() { + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; +} + +LoginResponse::~LoginResponse() { + // @@protoc_insertion_point(destructor:dodo.test.LoginResponse) + SharedDtor(); +} + +void LoginResponse::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void LoginResponse::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* LoginResponse::descriptor() { + ::protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const LoginResponse& LoginResponse::default_instance() { + ::protobuf_echo_5fservice_2eproto::InitDefaultsLoginResponse(); + return *internal_default_instance(); +} + +LoginResponse* LoginResponse::New(::google::protobuf::Arena* arena) const { + LoginResponse* n = new LoginResponse; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void LoginResponse::Clear() { +// @@protoc_insertion_point(message_clear_start:dodo.test.LoginResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); +} + +bool LoginResponse::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:dodo.test.LoginResponse) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // string message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "dodo.test.LoginResponse.message")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:dodo.test.LoginResponse) + return true; +failure: + // @@protoc_insertion_point(parse_failure:dodo.test.LoginResponse) + return false; +#undef DO_ +} + +void LoginResponse::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:dodo.test.LoginResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.LoginResponse.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->message(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:dodo.test.LoginResponse) +} + +::google::protobuf::uint8* LoginResponse::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:dodo.test.LoginResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string message = 1; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->message().data(), static_cast(this->message().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "dodo.test.LoginResponse.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->message(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:dodo.test.LoginResponse) + return target; +} + +size_t LoginResponse::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:dodo.test.LoginResponse) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string message = 1; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void LoginResponse::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:dodo.test.LoginResponse) + GOOGLE_DCHECK_NE(&from, this); + const LoginResponse* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:dodo.test.LoginResponse) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:dodo.test.LoginResponse) + MergeFrom(*source); + } +} + +void LoginResponse::MergeFrom(const LoginResponse& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:dodo.test.LoginResponse) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void LoginResponse::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:dodo.test.LoginResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void LoginResponse::CopyFrom(const LoginResponse& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:dodo.test.LoginResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool LoginResponse::IsInitialized() const { + return true; +} + +void LoginResponse::Swap(LoginResponse* other) { + if (other == this) return; + InternalSwap(other); +} +void LoginResponse::InternalSwap(LoginResponse* other) { + using std::swap; + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata LoginResponse::GetMetadata() const { + protobuf_echo_5fservice_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_echo_5fservice_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// @@protoc_insertion_point(namespace_scope) +} // namespace test +} // namespace dodo + +// @@protoc_insertion_point(global_scope) diff --git a/examples/echo/pb/echo_service.pb.h b/examples/echo/pb/echo_service.pb.h new file mode 100644 index 0000000..86fccbc --- /dev/null +++ b/examples/echo/pb/echo_service.pb.h @@ -0,0 +1,760 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: echo_service.proto + +#ifndef PROTOBUF_echo_5fservice_2eproto__INCLUDED +#define PROTOBUF_echo_5fservice_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 3005000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3005000 < GOOGLE_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 + +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include "gayrpc_option.pb.h" // IWYU pragma: export +// @@protoc_insertion_point(includes) + +namespace protobuf_echo_5fservice_2eproto { +// Internal implementation detail -- do not use these members. +struct TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[4]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; + static const ::google::protobuf::uint32 offsets[]; +}; +void AddDescriptors(); +void InitDefaultsEchoRequestImpl(); +void InitDefaultsEchoRequest(); +void InitDefaultsLoginRequestImpl(); +void InitDefaultsLoginRequest(); +void InitDefaultsEchoResponseImpl(); +void InitDefaultsEchoResponse(); +void InitDefaultsLoginResponseImpl(); +void InitDefaultsLoginResponse(); +inline void InitDefaults() { + InitDefaultsEchoRequest(); + InitDefaultsLoginRequest(); + InitDefaultsEchoResponse(); + InitDefaultsLoginResponse(); +} +} // namespace protobuf_echo_5fservice_2eproto +namespace dodo { +namespace test { +class EchoRequest; +class EchoRequestDefaultTypeInternal; +extern EchoRequestDefaultTypeInternal _EchoRequest_default_instance_; +class EchoResponse; +class EchoResponseDefaultTypeInternal; +extern EchoResponseDefaultTypeInternal _EchoResponse_default_instance_; +class LoginRequest; +class LoginRequestDefaultTypeInternal; +extern LoginRequestDefaultTypeInternal _LoginRequest_default_instance_; +class LoginResponse; +class LoginResponseDefaultTypeInternal; +extern LoginResponseDefaultTypeInternal _LoginResponse_default_instance_; +} // namespace test +} // namespace dodo +namespace dodo { +namespace test { + +// =================================================================== + +class EchoRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:dodo.test.EchoRequest) */ { + public: + EchoRequest(); + virtual ~EchoRequest(); + + EchoRequest(const EchoRequest& from); + + inline EchoRequest& operator=(const EchoRequest& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + EchoRequest(EchoRequest&& from) noexcept + : EchoRequest() { + *this = ::std::move(from); + } + + inline EchoRequest& operator=(EchoRequest&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const EchoRequest& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const EchoRequest* internal_default_instance() { + return reinterpret_cast( + &_EchoRequest_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; + + void Swap(EchoRequest* other); + friend void swap(EchoRequest& a, EchoRequest& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline EchoRequest* New() const PROTOBUF_FINAL { return New(NULL); } + + EchoRequest* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const EchoRequest& from); + void MergeFrom(const EchoRequest& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(EchoRequest* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string message = 1; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::std::string& message() const; + void set_message(const ::std::string& value); + #if LANG_CXX11 + void set_message(::std::string&& value); + #endif + void set_message(const char* value); + void set_message(const char* value, size_t size); + ::std::string* mutable_message(); + ::std::string* release_message(); + void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:dodo.test.EchoRequest) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend struct ::protobuf_echo_5fservice_2eproto::TableStruct; + friend void ::protobuf_echo_5fservice_2eproto::InitDefaultsEchoRequestImpl(); +}; +// ------------------------------------------------------------------- + +class LoginRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:dodo.test.LoginRequest) */ { + public: + LoginRequest(); + virtual ~LoginRequest(); + + LoginRequest(const LoginRequest& from); + + inline LoginRequest& operator=(const LoginRequest& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + LoginRequest(LoginRequest&& from) noexcept + : LoginRequest() { + *this = ::std::move(from); + } + + inline LoginRequest& operator=(LoginRequest&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const LoginRequest& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const LoginRequest* internal_default_instance() { + return reinterpret_cast( + &_LoginRequest_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; + + void Swap(LoginRequest* other); + friend void swap(LoginRequest& a, LoginRequest& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline LoginRequest* New() const PROTOBUF_FINAL { return New(NULL); } + + LoginRequest* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const LoginRequest& from); + void MergeFrom(const LoginRequest& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(LoginRequest* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string message = 1; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::std::string& message() const; + void set_message(const ::std::string& value); + #if LANG_CXX11 + void set_message(::std::string&& value); + #endif + void set_message(const char* value); + void set_message(const char* value, size_t size); + ::std::string* mutable_message(); + ::std::string* release_message(); + void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:dodo.test.LoginRequest) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend struct ::protobuf_echo_5fservice_2eproto::TableStruct; + friend void ::protobuf_echo_5fservice_2eproto::InitDefaultsLoginRequestImpl(); +}; +// ------------------------------------------------------------------- + +class EchoResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:dodo.test.EchoResponse) */ { + public: + EchoResponse(); + virtual ~EchoResponse(); + + EchoResponse(const EchoResponse& from); + + inline EchoResponse& operator=(const EchoResponse& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + EchoResponse(EchoResponse&& from) noexcept + : EchoResponse() { + *this = ::std::move(from); + } + + inline EchoResponse& operator=(EchoResponse&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const EchoResponse& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const EchoResponse* internal_default_instance() { + return reinterpret_cast( + &_EchoResponse_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; + + void Swap(EchoResponse* other); + friend void swap(EchoResponse& a, EchoResponse& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline EchoResponse* New() const PROTOBUF_FINAL { return New(NULL); } + + EchoResponse* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const EchoResponse& from); + void MergeFrom(const EchoResponse& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(EchoResponse* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string message = 1; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::std::string& message() const; + void set_message(const ::std::string& value); + #if LANG_CXX11 + void set_message(::std::string&& value); + #endif + void set_message(const char* value); + void set_message(const char* value, size_t size); + ::std::string* mutable_message(); + ::std::string* release_message(); + void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:dodo.test.EchoResponse) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend struct ::protobuf_echo_5fservice_2eproto::TableStruct; + friend void ::protobuf_echo_5fservice_2eproto::InitDefaultsEchoResponseImpl(); +}; +// ------------------------------------------------------------------- + +class LoginResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:dodo.test.LoginResponse) */ { + public: + LoginResponse(); + virtual ~LoginResponse(); + + LoginResponse(const LoginResponse& from); + + inline LoginResponse& operator=(const LoginResponse& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + LoginResponse(LoginResponse&& from) noexcept + : LoginResponse() { + *this = ::std::move(from); + } + + inline LoginResponse& operator=(LoginResponse&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const LoginResponse& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const LoginResponse* internal_default_instance() { + return reinterpret_cast( + &_LoginResponse_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 3; + + void Swap(LoginResponse* other); + friend void swap(LoginResponse& a, LoginResponse& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline LoginResponse* New() const PROTOBUF_FINAL { return New(NULL); } + + LoginResponse* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const LoginResponse& from); + void MergeFrom(const LoginResponse& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(LoginResponse* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string message = 1; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::std::string& message() const; + void set_message(const ::std::string& value); + #if LANG_CXX11 + void set_message(::std::string&& value); + #endif + void set_message(const char* value); + void set_message(const char* value, size_t size); + ::std::string* mutable_message(); + ::std::string* release_message(); + void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:dodo.test.LoginResponse) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend struct ::protobuf_echo_5fservice_2eproto::TableStruct; + friend void ::protobuf_echo_5fservice_2eproto::InitDefaultsLoginResponseImpl(); +}; +// =================================================================== + + +// =================================================================== + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// EchoRequest + +// string message = 1; +inline void EchoRequest::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& EchoRequest::message() const { + // @@protoc_insertion_point(field_get:dodo.test.EchoRequest.message) + return message_.GetNoArena(); +} +inline void EchoRequest::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:dodo.test.EchoRequest.message) +} +#if LANG_CXX11 +inline void EchoRequest::set_message(::std::string&& value) { + + message_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:dodo.test.EchoRequest.message) +} +#endif +inline void EchoRequest::set_message(const char* value) { + GOOGLE_DCHECK(value != NULL); + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:dodo.test.EchoRequest.message) +} +inline void EchoRequest::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:dodo.test.EchoRequest.message) +} +inline ::std::string* EchoRequest::mutable_message() { + + // @@protoc_insertion_point(field_mutable:dodo.test.EchoRequest.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* EchoRequest::release_message() { + // @@protoc_insertion_point(field_release:dodo.test.EchoRequest.message) + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void EchoRequest::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:dodo.test.EchoRequest.message) +} + +// ------------------------------------------------------------------- + +// LoginRequest + +// string message = 1; +inline void LoginRequest::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& LoginRequest::message() const { + // @@protoc_insertion_point(field_get:dodo.test.LoginRequest.message) + return message_.GetNoArena(); +} +inline void LoginRequest::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:dodo.test.LoginRequest.message) +} +#if LANG_CXX11 +inline void LoginRequest::set_message(::std::string&& value) { + + message_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:dodo.test.LoginRequest.message) +} +#endif +inline void LoginRequest::set_message(const char* value) { + GOOGLE_DCHECK(value != NULL); + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:dodo.test.LoginRequest.message) +} +inline void LoginRequest::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:dodo.test.LoginRequest.message) +} +inline ::std::string* LoginRequest::mutable_message() { + + // @@protoc_insertion_point(field_mutable:dodo.test.LoginRequest.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* LoginRequest::release_message() { + // @@protoc_insertion_point(field_release:dodo.test.LoginRequest.message) + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void LoginRequest::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:dodo.test.LoginRequest.message) +} + +// ------------------------------------------------------------------- + +// EchoResponse + +// string message = 1; +inline void EchoResponse::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& EchoResponse::message() const { + // @@protoc_insertion_point(field_get:dodo.test.EchoResponse.message) + return message_.GetNoArena(); +} +inline void EchoResponse::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:dodo.test.EchoResponse.message) +} +#if LANG_CXX11 +inline void EchoResponse::set_message(::std::string&& value) { + + message_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:dodo.test.EchoResponse.message) +} +#endif +inline void EchoResponse::set_message(const char* value) { + GOOGLE_DCHECK(value != NULL); + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:dodo.test.EchoResponse.message) +} +inline void EchoResponse::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:dodo.test.EchoResponse.message) +} +inline ::std::string* EchoResponse::mutable_message() { + + // @@protoc_insertion_point(field_mutable:dodo.test.EchoResponse.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* EchoResponse::release_message() { + // @@protoc_insertion_point(field_release:dodo.test.EchoResponse.message) + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void EchoResponse::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:dodo.test.EchoResponse.message) +} + +// ------------------------------------------------------------------- + +// LoginResponse + +// string message = 1; +inline void LoginResponse::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& LoginResponse::message() const { + // @@protoc_insertion_point(field_get:dodo.test.LoginResponse.message) + return message_.GetNoArena(); +} +inline void LoginResponse::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:dodo.test.LoginResponse.message) +} +#if LANG_CXX11 +inline void LoginResponse::set_message(::std::string&& value) { + + message_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:dodo.test.LoginResponse.message) +} +#endif +inline void LoginResponse::set_message(const char* value) { + GOOGLE_DCHECK(value != NULL); + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:dodo.test.LoginResponse.message) +} +inline void LoginResponse::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:dodo.test.LoginResponse.message) +} +inline ::std::string* LoginResponse::mutable_message() { + + // @@protoc_insertion_point(field_mutable:dodo.test.LoginResponse.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* LoginResponse::release_message() { + // @@protoc_insertion_point(field_release:dodo.test.LoginResponse.message) + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void LoginResponse::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:dodo.test.LoginResponse.message) +} + +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace test +} // namespace dodo + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_echo_5fservice_2eproto__INCLUDED diff --git a/examples/echo/pb/echo_service.proto b/examples/echo/pb/echo_service.proto new file mode 100644 index 0000000..a000b0d --- /dev/null +++ b/examples/echo/pb/echo_service.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package dodo.test; +import public "gayrpc_option.proto"; + +message EchoRequest { + string message = 1; +} + +message LoginRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} + +message LoginResponse { + string message = 1; +} + +service EchoServer { + rpc Echo(EchoRequest) returns(EchoResponse) { + option (message_id)= 2333; + }; + rpc Login(LoginRequest) returns(LoginResponse) { + option (message_id)= 3333; + }; +} \ No newline at end of file diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..0cd289c --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required (VERSION 2.6) +project(gayrpc) + +include_directories("${PROJECT_SOURCE_DIR}/include/") +include_directories("${PROJECT_SOURCE_DIR}/utils/") +include_directories("${PROJECT_SOURCE_DIR}/../brynet/src/") + +if(WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest") +elseif(UNIX) + if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + endif() +endif() + +add_subdirectory(examples/echo) +add_subdirectory(examples/benchmark) diff --git a/include/GayRpcClient.h b/include/GayRpcClient.h new file mode 100644 index 0000000..7ec261c --- /dev/null +++ b/include/GayRpcClient.h @@ -0,0 +1,120 @@ +#ifndef _GAY_RPC_CLIENT_H +#define _GAY_RPC_CLIENT_H + +#include +#include +#include +#include +#include +#include + +#include "meta.pb.h" +#include "GayRpcTypeHandler.h" +#include "GayRpcHelper.h" + +namespace gayrpc +{ + namespace core + { + class BaseClient : public std::enable_shared_from_this + { + public: + typedef std::shared_ptr PTR; + + protected: + BaseClient(UnaryServerInterceptor outboundInterceptor, + UnaryServerInterceptor inboundInterceptor) + : + mSequenceID(0), + mOutboundInterceptor(std::move(outboundInterceptor)), + mInboundInterceptor(std::move(inboundInterceptor)) + {} + + template + void call(const Request& request, + uint64_t msgID, + const Handle& handle = nullptr) + { + const auto sequenceID = mSequenceID++; + const auto expectResponse = (handle != nullptr); + + RpcMeta meta = makeRequestRpcMeta(sequenceID, + msgID, + RpcMeta_DataEncodingType_BINARY, + handle != nullptr); + mOutboundInterceptor(meta, request, [](const RpcMeta&, const google::protobuf::Message&) { + }); + + if (!expectResponse) + { + return; + } + + { + std::lock_guard lck(mStubMapGruad); + auto sharedThis = shared_from_this(); + mStubHandleMap[sequenceID] = [handle, sharedThis](const RpcMeta& meta, + const std::string& data, + const UnaryServerInterceptor& inboundInterceptor) { + return parseWrapper(handle, + meta, + data, + inboundInterceptor); + }; + } + } + + void installResponseStub(const gayrpc::core::RpcTypeHandleManager::PTR& rpcTypeHandleManager) + { + auto sharedThis = shared_from_this(); + auto responseStub = [sharedThis](const RpcMeta& meta, + const std::string& data) { + sharedThis->processRpcResponse(meta, data); + return true; + }; + rpcTypeHandleManager->registerTypeHandle(RpcMeta::RESPONSE, responseStub); + } + + private: + void processRpcResponse(const RpcMeta& meta, const std::string& data) + { + assert(meta.type() == RpcMeta::RESPONSE); + if (meta.type() != RpcMeta::RESPONSE) + { + throw std::runtime_error("type :" + std::to_string(meta.type()) + " not Response"); + } + + ResponseStubHandle handle; + { + std::lock_guard lck(mStubMapGruad); + auto it = mStubHandleMap.find(meta.response_info().sequence_id()); + if (it == mStubHandleMap.end()) + { + throw std::runtime_error("not found response seq id:" + + std::to_string(meta.response_info().sequence_id())); + } + handle = (*it).second; + mStubHandleMap.erase(it); + } + handle(meta, data, mInboundInterceptor); + } + + private: + typedef std::function< + void( + const RpcMeta&, + const std::string& data, + const UnaryServerInterceptor&)> ResponseStubHandle; + typedef std::unordered_map ResponseStubHandleMap; + + UnaryServerInterceptor mInboundInterceptor; + UnaryServerInterceptor mOutboundInterceptor; + + std::atomic mSequenceID; + std::mutex mStubMapGruad; + ResponseStubHandleMap mStubHandleMap; + }; + } +} + +#endif diff --git a/include/GayRpcCore.h b/include/GayRpcCore.h new file mode 100644 index 0000000..fa9c7e7 --- /dev/null +++ b/include/GayRpcCore.h @@ -0,0 +1,17 @@ +#ifndef _GAY_RPC_CORE_H +#define _GAY_RPC_CORE_H + +#include + +#include "meta.pb.h" + +namespace gayrpc +{ + namespace core + { + typedef std::function UnaryHandler; + typedef std::function UnaryServerInterceptor; + } +} + +#endif \ No newline at end of file diff --git a/include/GayRpcError.h b/include/GayRpcError.h new file mode 100644 index 0000000..93486e4 --- /dev/null +++ b/include/GayRpcError.h @@ -0,0 +1,59 @@ +#ifndef _GAY_RPC_ERROR_H +#define _GAY_RPC_ERROR_H + +#include +#include + +#include "meta.pb.h" + +namespace gayrpc +{ + namespace core + { + typedef int32_t ErrorCode; + + // 封装RPC 远端返回的错误类型,rpc.call 本身的错误则由异常提供 + class RpcError + { + public: + RpcError() + : + mFailed(false) + {} + + RpcError(bool failed, + ErrorCode errorCode, + const std::string& reason) + : + mFailed(failed), + mErrorCode(errorCode), + mReason(reason) + {} + + virtual ~RpcError() + {} + + bool failed() const + { + return mFailed; + } + + ErrorCode code() const + { + return mErrorCode; + } + + const std::string& reason() const + { + return mReason; + } + + private: + bool mFailed; + ErrorCode mErrorCode; + std::string mReason; + }; + } +} + +#endif \ No newline at end of file diff --git a/include/GayRpcHelper.h b/include/GayRpcHelper.h new file mode 100644 index 0000000..9e908e4 --- /dev/null +++ b/include/GayRpcHelper.h @@ -0,0 +1,81 @@ +#ifndef _GAY_RPC_HELPER_H +#define _GAY_RPC_HELPER_H + +#include +#include + +#include +#include "meta.pb.h" +#include "GayRpcCore.h" +#include "GayRpcError.h" + +namespace gayrpc +{ + namespace core + { + using namespace google::protobuf::util; + // 构造用于RPC请求的Meta对象 + inline RpcMeta makeRequestRpcMeta(uint64_t sequenceID, + uint64_t msgID, + RpcMeta_DataEncodingType type, + bool expectResponse) + { + RpcMeta meta; + meta.set_type(RpcMeta::REQUEST); + meta.set_encoding(type); + meta.mutable_request_info()->set_method(msgID); + meta.mutable_request_info()->set_sequence_id(sequenceID); + meta.mutable_request_info()->set_expect_response(expectResponse); + + return meta; + } + + // 解析Response然后(通过拦截器)调用回调 + template + inline void parseWrapper(const Hanele& handle, + const RpcMeta& meta, + const std::string& data, + const UnaryServerInterceptor& inboundInterceptor) + { + Response response; + switch (meta.encoding()) + { + case RpcMeta_DataEncodingType_BINARY: + if (!response.ParseFromString(data)) + { + throw std::runtime_error("parse binary echo response failed"); + } + break; + case RpcMeta_DataEncodingType_JSON: + { + auto s = JsonStringToMessage(data, &response); + if (!s.ok()) + { + throw std::runtime_error("parse json echo response failed:" + + s.error_message().as_string()); + } + break; + } + default: + throw std::runtime_error("unknow encoding" + meta.encoding()); + } + + gayrpc::core::RpcError error; + if (meta.response_info().failed()) + { + error = gayrpc::core::RpcError(meta.response_info().failed(), + meta.response_info().error_code(), + meta.response_info().reason()); + } + + inboundInterceptor( + meta, + response, + [&response, &error, &handle](const RpcMeta&, const google::protobuf::Message&) { + handle(response, error); + }); + } + } +} + +#endif diff --git a/include/GayRpcReply.h b/include/GayRpcReply.h new file mode 100644 index 0000000..bedcd2f --- /dev/null +++ b/include/GayRpcReply.h @@ -0,0 +1,110 @@ +#ifndef _GAY_RPC_REPLY_H +#define _GAY_RPC_REPLY_H + +#include +#include +#include +#include + +#include "meta.pb.h" +#include "GayRpcCore.h" + +namespace gayrpc +{ + namespace core + { + class BaseReply + { + public: + BaseReply(RpcMeta meta, + UnaryServerInterceptor outboundInterceptor) + : + mRequestMeta(std::move(meta)), + mOutboundInterceptor(std::move(outboundInterceptor)) + { + } + + virtual ~BaseReply() + {} + + protected: + void reply(const google::protobuf::Message& response) + { + if (mReplyFlag.test_and_set()) + { + throw std::runtime_error("already reply"); + } + + if (!mRequestMeta.request_info().expect_response()) + { + //TODO::是否直接忽略不必抛出异常 + throw std::runtime_error("server not expect response"); + } + + RpcMeta meta; + meta.set_type(RpcMeta::RESPONSE); + meta.mutable_response_info()->set_sequence_id(mRequestMeta.request_info().sequence_id()); + meta.mutable_response_info()->set_failed(false); + + mOutboundInterceptor(meta, response, [](const RpcMeta&, const google::protobuf::Message&) { + }); + } + + template + void error(int32_t errorCode, const std::string& reason) + { + if (mReplyFlag.test_and_set()) + { + throw std::runtime_error("already reply"); + } + + if (!mRequestMeta.request_info().expect_response()) + { + return; + } + + RpcMeta meta; + meta.set_type(RpcMeta::RESPONSE); + meta.set_encoding(RpcMeta_DataEncodingType_BINARY); + meta.mutable_response_info()->set_sequence_id(mRequestMeta.request_info().sequence_id()); + meta.mutable_response_info()->set_failed(true); + meta.mutable_response_info()->set_error_code(errorCode); + meta.mutable_response_info()->set_reason(reason); + + Response response; + mOutboundInterceptor(meta, response); + } + + private: + std::atomic_flag mReplyFlag = ATOMIC_FLAG_INIT; + RpcMeta mRequestMeta; + UnaryServerInterceptor mOutboundInterceptor; + }; + + template + class TemplateReply : public BaseReply + { + public: + typedef std::shared_ptr> PTR; + + TemplateReply(RpcMeta meta, + UnaryServerInterceptor outboundInterceptor) + : + BaseReply(std::move(meta), std::move(outboundInterceptor)) + { + } + + void reply(const T& response) + { + BaseReply::reply(response); + } + + void error(int32_t errorCode, const std::string& reason) + { + BaseReply::error(errorCode, reason); + } + }; + } +} + +#endif \ No newline at end of file diff --git a/include/GayRpcService.h b/include/GayRpcService.h new file mode 100644 index 0000000..91d61c3 --- /dev/null +++ b/include/GayRpcService.h @@ -0,0 +1,16 @@ +#ifndef _GAY_RPC_SERVICE_H +#define _GAY_RPC_SERVICE_H + +#include + +namespace gayrpc +{ + namespace core + { + class BaseService : public std::enable_shared_from_this + { + }; + } +} + +#endif \ No newline at end of file diff --git a/include/GayRpcTypeHandler.h b/include/GayRpcTypeHandler.h new file mode 100644 index 0000000..80194eb --- /dev/null +++ b/include/GayRpcTypeHandler.h @@ -0,0 +1,66 @@ +#ifndef _GAY_RPC_TYPE_HANDLER_H +#define _GAY_RPC_TYPE_HANDLER_H + +#include +#include +#include +#include +#include + +#include "meta.pb.h" + +namespace gayrpc +{ + namespace core + { + // 管理不同类型RPC消息(REQUEST和Response)的处理器 + class RpcTypeHandleManager : public std::enable_shared_from_this + { + public: + typedef std::shared_ptr PTR; + typedef std::function TypeHandler; + + public: + void registerTypeHandle(RpcMeta::Type type, TypeHandler handle) + { + std::lock_guard lock(mMutex); + mTypeHandlers[type] = std::move(handle); + } + + virtual ~RpcTypeHandleManager() + { + } + + bool handleRpcMsg(const RpcMeta& meta, + const std::string& data) + { + TypeHandler handler; + { + std::lock_guard lock(mMutex); + auto it = mTypeHandlers.find(meta.type()); + if (it == mTypeHandlers.end()) + { + return false; + } + handler = (*it).second; + } + + try + { + handler(meta, data); + } + catch (const std::exception& e) + { + std::cout << e.what() << std::endl; + } + return true; + } + + private: + std::unordered_map mTypeHandlers; + std::mutex mMutex; + }; + } +} + +#endif diff --git a/include/gayrpc_option.pb.cc b/include/gayrpc_option.pb.cc new file mode 100644 index 0000000..94e2d2a --- /dev/null +++ b/include/gayrpc_option.pb.cc @@ -0,0 +1,81 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: gayrpc_option.proto + +#include "gayrpc_option.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif +// @@protoc_insertion_point(includes) +namespace protobuf_gayrpc_5foption_2eproto { +const ::google::protobuf::uint32 TableStruct::offsets[1] = {}; +static const ::google::protobuf::internal::MigrationSchema* schemas = NULL; +static const ::google::protobuf::Message* const* file_default_instances = NULL; + +void protobuf_AssignDescriptors() { + AddDescriptors(); + ::google::protobuf::MessageFactory* factory = NULL; + AssignDescriptors( + "gayrpc_option.proto", schemas, file_default_instances, TableStruct::offsets, factory, + NULL, NULL, NULL); +} + +void protobuf_AssignDescriptorsOnce() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors); +} + +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD; +void protobuf_RegisterTypes(const ::std::string&) { + protobuf_AssignDescriptorsOnce(); +} + +void AddDescriptorsImpl() { + InitDefaults(); + static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + "\n\023gayrpc_option.proto\032 google/protobuf/d" + "escriptor.proto:4\n\nmessage_id\022\036.google.p" + "rotobuf.MethodOptions\030\272\216\003 \001(\005:.\n\004flag\022\036." + "google.protobuf.MethodOptions\030\273\216\003 \001(\005b\006p" + "roto3" + }; + ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( + descriptor, 165); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( + "gayrpc_option.proto", &protobuf_RegisterTypes); + ::protobuf_google_2fprotobuf_2fdescriptor_2eproto::AddDescriptors(); +} + +void AddDescriptors() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); +} +// Force AddDescriptors() to be called at dynamic initialization time. +struct StaticDescriptorInitializer { + StaticDescriptorInitializer() { + AddDescriptors(); + } +} static_descriptor_initializer; +} // namespace protobuf_gayrpc_5foption_2eproto +::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + message_id(kMessageIdFieldNumber, 0); +::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + flag(kFlagFieldNumber, 0); + +// @@protoc_insertion_point(namespace_scope) + +// @@protoc_insertion_point(global_scope) diff --git a/include/gayrpc_option.pb.h b/include/gayrpc_option.pb.h new file mode 100644 index 0000000..821c0da --- /dev/null +++ b/include/gayrpc_option.pb.h @@ -0,0 +1,77 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: gayrpc_option.proto + +#ifndef PROTOBUF_gayrpc_5foption_2eproto__INCLUDED +#define PROTOBUF_gayrpc_5foption_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 3005000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3005000 < GOOGLE_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 + +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +// @@protoc_insertion_point(includes) + +namespace protobuf_gayrpc_5foption_2eproto { +// Internal implementation detail -- do not use these members. +struct TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[1]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; + static const ::google::protobuf::uint32 offsets[]; +}; +void AddDescriptors(); +inline void InitDefaults() { +} +} // namespace protobuf_gayrpc_5foption_2eproto + +// =================================================================== + + +// =================================================================== + +static const int kMessageIdFieldNumber = 51002; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + message_id; +static const int kFlagFieldNumber = 51003; +extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, + ::google::protobuf::internal::PrimitiveTypeTraits< ::google::protobuf::int32 >, 5, false > + flag; + +// =================================================================== + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ + +// @@protoc_insertion_point(namespace_scope) + + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_gayrpc_5foption_2eproto__INCLUDED diff --git a/include/meta.pb.cc b/include/meta.pb.cc new file mode 100644 index 0000000..9d8ada8 --- /dev/null +++ b/include/meta.pb.cc @@ -0,0 +1,1319 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: meta.proto + +#include "meta.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif +// @@protoc_insertion_point(includes) +namespace gayrpc { +namespace core { +class RpcMeta_RequestDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _RpcMeta_Request_default_instance_; +class RpcMeta_ResponseDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _RpcMeta_Response_default_instance_; +class RpcMetaDefaultTypeInternal { + public: + ::google::protobuf::internal::ExplicitlyConstructed + _instance; +} _RpcMeta_default_instance_; +} // namespace core +} // namespace gayrpc +namespace protobuf_meta_2eproto { +void InitDefaultsRpcMeta_RequestImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::gayrpc::core::_RpcMeta_Request_default_instance_; + new (ptr) ::gayrpc::core::RpcMeta_Request(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::gayrpc::core::RpcMeta_Request::InitAsDefaultInstance(); +} + +void InitDefaultsRpcMeta_Request() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsRpcMeta_RequestImpl); +} + +void InitDefaultsRpcMeta_ResponseImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + { + void* ptr = &::gayrpc::core::_RpcMeta_Response_default_instance_; + new (ptr) ::gayrpc::core::RpcMeta_Response(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::gayrpc::core::RpcMeta_Response::InitAsDefaultInstance(); +} + +void InitDefaultsRpcMeta_Response() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsRpcMeta_ResponseImpl); +} + +void InitDefaultsRpcMetaImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else + ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + protobuf_meta_2eproto::InitDefaultsRpcMeta_Request(); + protobuf_meta_2eproto::InitDefaultsRpcMeta_Response(); + { + void* ptr = &::gayrpc::core::_RpcMeta_default_instance_; + new (ptr) ::gayrpc::core::RpcMeta(); + ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); + } + ::gayrpc::core::RpcMeta::InitAsDefaultInstance(); +} + +void InitDefaultsRpcMeta() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsRpcMetaImpl); +} + +::google::protobuf::Metadata file_level_metadata[3]; +const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[2]; + +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Request, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Request, method_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Request, expect_response_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Request, sequence_id_), + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Response, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Response, sequence_id_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Response, failed_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Response, error_code_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta_Response, reason_), + ~0u, // no _has_bits_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta, type_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta, encoding_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta, request_info_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::gayrpc::core::RpcMeta, response_info_), +}; +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, sizeof(::gayrpc::core::RpcMeta_Request)}, + { 8, -1, sizeof(::gayrpc::core::RpcMeta_Response)}, + { 17, -1, sizeof(::gayrpc::core::RpcMeta)}, +}; + +static ::google::protobuf::Message const * const file_default_instances[] = { + reinterpret_cast(&::gayrpc::core::_RpcMeta_Request_default_instance_), + reinterpret_cast(&::gayrpc::core::_RpcMeta_Response_default_instance_), + reinterpret_cast(&::gayrpc::core::_RpcMeta_default_instance_), +}; + +void protobuf_AssignDescriptors() { + AddDescriptors(); + ::google::protobuf::MessageFactory* factory = NULL; + AssignDescriptors( + "meta.proto", schemas, file_default_instances, TableStruct::offsets, factory, + file_level_metadata, file_level_enum_descriptors, NULL); +} + +void protobuf_AssignDescriptorsOnce() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors); +} + +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD; +void protobuf_RegisterTypes(const ::std::string&) { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 3); +} + +void AddDescriptorsImpl() { + InitDefaults(); + static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + "\n\nmeta.proto\022\013gayrpc.core\"\300\003\n\007RpcMeta\022\'\n" + "\004type\030\001 \001(\0162\031.gayrpc.core.RpcMeta.Type\0227" + "\n\010encoding\030\002 \001(\0162%.gayrpc.core.RpcMeta.D" + "ataEncodingType\0222\n\014request_info\030\003 \001(\0132\034." + "gayrpc.core.RpcMeta.Request\0224\n\rresponse_" + "info\030\004 \001(\0132\035.gayrpc.core.RpcMeta.Respons" + "e\032G\n\007Request\022\016\n\006method\030\001 \001(\004\022\027\n\017expect_r" + "esponse\030\002 \001(\010\022\023\n\013sequence_id\030\003 \001(\004\032S\n\010Re" + "sponse\022\023\n\013sequence_id\030\001 \001(\004\022\016\n\006failed\030\002 " + "\001(\010\022\022\n\nerror_code\030\003 \001(\005\022\016\n\006reason\030\004 \001(\t\"" + "!\n\004Type\022\013\n\007REQUEST\020\000\022\014\n\010RESPONSE\020\001\"(\n\020Da" + "taEncodingType\022\n\n\006BINARY\020\000\022\010\n\004JSON\020\001b\006pr" + "oto3" + }; + ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( + descriptor, 484); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( + "meta.proto", &protobuf_RegisterTypes); +} + +void AddDescriptors() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); +} +// Force AddDescriptors() to be called at dynamic initialization time. +struct StaticDescriptorInitializer { + StaticDescriptorInitializer() { + AddDescriptors(); + } +} static_descriptor_initializer; +} // namespace protobuf_meta_2eproto +namespace gayrpc { +namespace core { +const ::google::protobuf::EnumDescriptor* RpcMeta_Type_descriptor() { + protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_meta_2eproto::file_level_enum_descriptors[0]; +} +bool RpcMeta_Type_IsValid(int value) { + switch (value) { + case 0: + case 1: + return true; + default: + return false; + } +} + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const RpcMeta_Type RpcMeta::REQUEST; +const RpcMeta_Type RpcMeta::RESPONSE; +const RpcMeta_Type RpcMeta::Type_MIN; +const RpcMeta_Type RpcMeta::Type_MAX; +const int RpcMeta::Type_ARRAYSIZE; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 +const ::google::protobuf::EnumDescriptor* RpcMeta_DataEncodingType_descriptor() { + protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_meta_2eproto::file_level_enum_descriptors[1]; +} +bool RpcMeta_DataEncodingType_IsValid(int value) { + switch (value) { + case 0: + case 1: + return true; + default: + return false; + } +} + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const RpcMeta_DataEncodingType RpcMeta::BINARY; +const RpcMeta_DataEncodingType RpcMeta::JSON; +const RpcMeta_DataEncodingType RpcMeta::DataEncodingType_MIN; +const RpcMeta_DataEncodingType RpcMeta::DataEncodingType_MAX; +const int RpcMeta::DataEncodingType_ARRAYSIZE; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +// =================================================================== + +void RpcMeta_Request::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int RpcMeta_Request::kMethodFieldNumber; +const int RpcMeta_Request::kExpectResponseFieldNumber; +const int RpcMeta_Request::kSequenceIdFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +RpcMeta_Request::RpcMeta_Request() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_meta_2eproto::InitDefaultsRpcMeta_Request(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:gayrpc.core.RpcMeta.Request) +} +RpcMeta_Request::RpcMeta_Request(const RpcMeta_Request& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::memcpy(&method_, &from.method_, + static_cast(reinterpret_cast(&expect_response_) - + reinterpret_cast(&method_)) + sizeof(expect_response_)); + // @@protoc_insertion_point(copy_constructor:gayrpc.core.RpcMeta.Request) +} + +void RpcMeta_Request::SharedCtor() { + ::memset(&method_, 0, static_cast( + reinterpret_cast(&expect_response_) - + reinterpret_cast(&method_)) + sizeof(expect_response_)); + _cached_size_ = 0; +} + +RpcMeta_Request::~RpcMeta_Request() { + // @@protoc_insertion_point(destructor:gayrpc.core.RpcMeta.Request) + SharedDtor(); +} + +void RpcMeta_Request::SharedDtor() { +} + +void RpcMeta_Request::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* RpcMeta_Request::descriptor() { + ::protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_meta_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const RpcMeta_Request& RpcMeta_Request::default_instance() { + ::protobuf_meta_2eproto::InitDefaultsRpcMeta_Request(); + return *internal_default_instance(); +} + +RpcMeta_Request* RpcMeta_Request::New(::google::protobuf::Arena* arena) const { + RpcMeta_Request* n = new RpcMeta_Request; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void RpcMeta_Request::Clear() { +// @@protoc_insertion_point(message_clear_start:gayrpc.core.RpcMeta.Request) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + ::memset(&method_, 0, static_cast( + reinterpret_cast(&expect_response_) - + reinterpret_cast(&method_)) + sizeof(expect_response_)); + _internal_metadata_.Clear(); +} + +bool RpcMeta_Request::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:gayrpc.core.RpcMeta.Request) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // uint64 method = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &method_))); + } else { + goto handle_unusual; + } + break; + } + + // bool expect_response = 2; + case 2: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( + input, &expect_response_))); + } else { + goto handle_unusual; + } + break; + } + + // uint64 sequence_id = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &sequence_id_))); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:gayrpc.core.RpcMeta.Request) + return true; +failure: + // @@protoc_insertion_point(parse_failure:gayrpc.core.RpcMeta.Request) + return false; +#undef DO_ +} + +void RpcMeta_Request::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:gayrpc.core.RpcMeta.Request) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // uint64 method = 1; + if (this->method() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->method(), output); + } + + // bool expect_response = 2; + if (this->expect_response() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteBool(2, this->expect_response(), output); + } + + // uint64 sequence_id = 3; + if (this->sequence_id() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(3, this->sequence_id(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:gayrpc.core.RpcMeta.Request) +} + +::google::protobuf::uint8* RpcMeta_Request::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:gayrpc.core.RpcMeta.Request) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // uint64 method = 1; + if (this->method() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(1, this->method(), target); + } + + // bool expect_response = 2; + if (this->expect_response() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(2, this->expect_response(), target); + } + + // uint64 sequence_id = 3; + if (this->sequence_id() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(3, this->sequence_id(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:gayrpc.core.RpcMeta.Request) + return target; +} + +size_t RpcMeta_Request::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:gayrpc.core.RpcMeta.Request) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // uint64 method = 1; + if (this->method() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->method()); + } + + // uint64 sequence_id = 3; + if (this->sequence_id() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->sequence_id()); + } + + // bool expect_response = 2; + if (this->expect_response() != 0) { + total_size += 1 + 1; + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void RpcMeta_Request::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:gayrpc.core.RpcMeta.Request) + GOOGLE_DCHECK_NE(&from, this); + const RpcMeta_Request* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:gayrpc.core.RpcMeta.Request) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:gayrpc.core.RpcMeta.Request) + MergeFrom(*source); + } +} + +void RpcMeta_Request::MergeFrom(const RpcMeta_Request& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:gayrpc.core.RpcMeta.Request) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.method() != 0) { + set_method(from.method()); + } + if (from.sequence_id() != 0) { + set_sequence_id(from.sequence_id()); + } + if (from.expect_response() != 0) { + set_expect_response(from.expect_response()); + } +} + +void RpcMeta_Request::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:gayrpc.core.RpcMeta.Request) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void RpcMeta_Request::CopyFrom(const RpcMeta_Request& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:gayrpc.core.RpcMeta.Request) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool RpcMeta_Request::IsInitialized() const { + return true; +} + +void RpcMeta_Request::Swap(RpcMeta_Request* other) { + if (other == this) return; + InternalSwap(other); +} +void RpcMeta_Request::InternalSwap(RpcMeta_Request* other) { + using std::swap; + swap(method_, other->method_); + swap(sequence_id_, other->sequence_id_); + swap(expect_response_, other->expect_response_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata RpcMeta_Request::GetMetadata() const { + protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_meta_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// =================================================================== + +void RpcMeta_Response::InitAsDefaultInstance() { +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int RpcMeta_Response::kSequenceIdFieldNumber; +const int RpcMeta_Response::kFailedFieldNumber; +const int RpcMeta_Response::kErrorCodeFieldNumber; +const int RpcMeta_Response::kReasonFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +RpcMeta_Response::RpcMeta_Response() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_meta_2eproto::InitDefaultsRpcMeta_Response(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:gayrpc.core.RpcMeta.Response) +} +RpcMeta_Response::RpcMeta_Response(const RpcMeta_Response& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + reason_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.reason().size() > 0) { + reason_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.reason_); + } + ::memcpy(&sequence_id_, &from.sequence_id_, + static_cast(reinterpret_cast(&error_code_) - + reinterpret_cast(&sequence_id_)) + sizeof(error_code_)); + // @@protoc_insertion_point(copy_constructor:gayrpc.core.RpcMeta.Response) +} + +void RpcMeta_Response::SharedCtor() { + reason_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + ::memset(&sequence_id_, 0, static_cast( + reinterpret_cast(&error_code_) - + reinterpret_cast(&sequence_id_)) + sizeof(error_code_)); + _cached_size_ = 0; +} + +RpcMeta_Response::~RpcMeta_Response() { + // @@protoc_insertion_point(destructor:gayrpc.core.RpcMeta.Response) + SharedDtor(); +} + +void RpcMeta_Response::SharedDtor() { + reason_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void RpcMeta_Response::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* RpcMeta_Response::descriptor() { + ::protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_meta_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const RpcMeta_Response& RpcMeta_Response::default_instance() { + ::protobuf_meta_2eproto::InitDefaultsRpcMeta_Response(); + return *internal_default_instance(); +} + +RpcMeta_Response* RpcMeta_Response::New(::google::protobuf::Arena* arena) const { + RpcMeta_Response* n = new RpcMeta_Response; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void RpcMeta_Response::Clear() { +// @@protoc_insertion_point(message_clear_start:gayrpc.core.RpcMeta.Response) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + reason_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + ::memset(&sequence_id_, 0, static_cast( + reinterpret_cast(&error_code_) - + reinterpret_cast(&sequence_id_)) + sizeof(error_code_)); + _internal_metadata_.Clear(); +} + +bool RpcMeta_Response::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:gayrpc.core.RpcMeta.Response) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // uint64 sequence_id = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &sequence_id_))); + } else { + goto handle_unusual; + } + break; + } + + // bool failed = 2; + case 2: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( + input, &failed_))); + } else { + goto handle_unusual; + } + break; + } + + // int32 error_code = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &error_code_))); + } else { + goto handle_unusual; + } + break; + } + + // string reason = 4; + case 4: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_reason())); + DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->reason().data(), static_cast(this->reason().length()), + ::google::protobuf::internal::WireFormatLite::PARSE, + "gayrpc.core.RpcMeta.Response.reason")); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:gayrpc.core.RpcMeta.Response) + return true; +failure: + // @@protoc_insertion_point(parse_failure:gayrpc.core.RpcMeta.Response) + return false; +#undef DO_ +} + +void RpcMeta_Response::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:gayrpc.core.RpcMeta.Response) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // uint64 sequence_id = 1; + if (this->sequence_id() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->sequence_id(), output); + } + + // bool failed = 2; + if (this->failed() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteBool(2, this->failed(), output); + } + + // int32 error_code = 3; + if (this->error_code() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->error_code(), output); + } + + // string reason = 4; + if (this->reason().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->reason().data(), static_cast(this->reason().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "gayrpc.core.RpcMeta.Response.reason"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 4, this->reason(), output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:gayrpc.core.RpcMeta.Response) +} + +::google::protobuf::uint8* RpcMeta_Response::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:gayrpc.core.RpcMeta.Response) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // uint64 sequence_id = 1; + if (this->sequence_id() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(1, this->sequence_id(), target); + } + + // bool failed = 2; + if (this->failed() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(2, this->failed(), target); + } + + // int32 error_code = 3; + if (this->error_code() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->error_code(), target); + } + + // string reason = 4; + if (this->reason().size() > 0) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + this->reason().data(), static_cast(this->reason().length()), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "gayrpc.core.RpcMeta.Response.reason"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 4, this->reason(), target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:gayrpc.core.RpcMeta.Response) + return target; +} + +size_t RpcMeta_Response::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:gayrpc.core.RpcMeta.Response) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // string reason = 4; + if (this->reason().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->reason()); + } + + // uint64 sequence_id = 1; + if (this->sequence_id() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->sequence_id()); + } + + // bool failed = 2; + if (this->failed() != 0) { + total_size += 1 + 1; + } + + // int32 error_code = 3; + if (this->error_code() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->error_code()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void RpcMeta_Response::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:gayrpc.core.RpcMeta.Response) + GOOGLE_DCHECK_NE(&from, this); + const RpcMeta_Response* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:gayrpc.core.RpcMeta.Response) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:gayrpc.core.RpcMeta.Response) + MergeFrom(*source); + } +} + +void RpcMeta_Response::MergeFrom(const RpcMeta_Response& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:gayrpc.core.RpcMeta.Response) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.reason().size() > 0) { + + reason_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.reason_); + } + if (from.sequence_id() != 0) { + set_sequence_id(from.sequence_id()); + } + if (from.failed() != 0) { + set_failed(from.failed()); + } + if (from.error_code() != 0) { + set_error_code(from.error_code()); + } +} + +void RpcMeta_Response::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:gayrpc.core.RpcMeta.Response) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void RpcMeta_Response::CopyFrom(const RpcMeta_Response& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:gayrpc.core.RpcMeta.Response) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool RpcMeta_Response::IsInitialized() const { + return true; +} + +void RpcMeta_Response::Swap(RpcMeta_Response* other) { + if (other == this) return; + InternalSwap(other); +} +void RpcMeta_Response::InternalSwap(RpcMeta_Response* other) { + using std::swap; + reason_.Swap(&other->reason_); + swap(sequence_id_, other->sequence_id_); + swap(failed_, other->failed_); + swap(error_code_, other->error_code_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata RpcMeta_Response::GetMetadata() const { + protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_meta_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// =================================================================== + +void RpcMeta::InitAsDefaultInstance() { + ::gayrpc::core::_RpcMeta_default_instance_._instance.get_mutable()->request_info_ = const_cast< ::gayrpc::core::RpcMeta_Request*>( + ::gayrpc::core::RpcMeta_Request::internal_default_instance()); + ::gayrpc::core::_RpcMeta_default_instance_._instance.get_mutable()->response_info_ = const_cast< ::gayrpc::core::RpcMeta_Response*>( + ::gayrpc::core::RpcMeta_Response::internal_default_instance()); +} +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int RpcMeta::kTypeFieldNumber; +const int RpcMeta::kEncodingFieldNumber; +const int RpcMeta::kRequestInfoFieldNumber; +const int RpcMeta::kResponseInfoFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +RpcMeta::RpcMeta() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + ::protobuf_meta_2eproto::InitDefaultsRpcMeta(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:gayrpc.core.RpcMeta) +} +RpcMeta::RpcMeta(const RpcMeta& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + if (from.has_request_info()) { + request_info_ = new ::gayrpc::core::RpcMeta_Request(*from.request_info_); + } else { + request_info_ = NULL; + } + if (from.has_response_info()) { + response_info_ = new ::gayrpc::core::RpcMeta_Response(*from.response_info_); + } else { + response_info_ = NULL; + } + ::memcpy(&type_, &from.type_, + static_cast(reinterpret_cast(&encoding_) - + reinterpret_cast(&type_)) + sizeof(encoding_)); + // @@protoc_insertion_point(copy_constructor:gayrpc.core.RpcMeta) +} + +void RpcMeta::SharedCtor() { + ::memset(&request_info_, 0, static_cast( + reinterpret_cast(&encoding_) - + reinterpret_cast(&request_info_)) + sizeof(encoding_)); + _cached_size_ = 0; +} + +RpcMeta::~RpcMeta() { + // @@protoc_insertion_point(destructor:gayrpc.core.RpcMeta) + SharedDtor(); +} + +void RpcMeta::SharedDtor() { + if (this != internal_default_instance()) delete request_info_; + if (this != internal_default_instance()) delete response_info_; +} + +void RpcMeta::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* RpcMeta::descriptor() { + ::protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_meta_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const RpcMeta& RpcMeta::default_instance() { + ::protobuf_meta_2eproto::InitDefaultsRpcMeta(); + return *internal_default_instance(); +} + +RpcMeta* RpcMeta::New(::google::protobuf::Arena* arena) const { + RpcMeta* n = new RpcMeta; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void RpcMeta::Clear() { +// @@protoc_insertion_point(message_clear_start:gayrpc.core.RpcMeta) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + if (GetArenaNoVirtual() == NULL && request_info_ != NULL) { + delete request_info_; + } + request_info_ = NULL; + if (GetArenaNoVirtual() == NULL && response_info_ != NULL) { + delete response_info_; + } + response_info_ = NULL; + ::memset(&type_, 0, static_cast( + reinterpret_cast(&encoding_) - + reinterpret_cast(&type_)) + sizeof(encoding_)); + _internal_metadata_.Clear(); +} + +bool RpcMeta::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:gayrpc.core.RpcMeta) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // .gayrpc.core.RpcMeta.Type type = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { + int value; + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( + input, &value))); + set_type(static_cast< ::gayrpc::core::RpcMeta_Type >(value)); + } else { + goto handle_unusual; + } + break; + } + + // .gayrpc.core.RpcMeta.DataEncodingType encoding = 2; + case 2: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { + int value; + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( + input, &value))); + set_encoding(static_cast< ::gayrpc::core::RpcMeta_DataEncodingType >(value)); + } else { + goto handle_unusual; + } + break; + } + + // .gayrpc.core.RpcMeta.Request request_info = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( + input, mutable_request_info())); + } else { + goto handle_unusual; + } + break; + } + + // .gayrpc.core.RpcMeta.Response response_info = 4; + case 4: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( + input, mutable_response_info())); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:gayrpc.core.RpcMeta) + return true; +failure: + // @@protoc_insertion_point(parse_failure:gayrpc.core.RpcMeta) + return false; +#undef DO_ +} + +void RpcMeta::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:gayrpc.core.RpcMeta) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // .gayrpc.core.RpcMeta.Type type = 1; + if (this->type() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteEnum( + 1, this->type(), output); + } + + // .gayrpc.core.RpcMeta.DataEncodingType encoding = 2; + if (this->encoding() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteEnum( + 2, this->encoding(), output); + } + + // .gayrpc.core.RpcMeta.Request request_info = 3; + if (this->has_request_info()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 3, *this->request_info_, output); + } + + // .gayrpc.core.RpcMeta.Response response_info = 4; + if (this->has_response_info()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 4, *this->response_info_, output); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } + // @@protoc_insertion_point(serialize_end:gayrpc.core.RpcMeta) +} + +::google::protobuf::uint8* RpcMeta::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:gayrpc.core.RpcMeta) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // .gayrpc.core.RpcMeta.Type type = 1; + if (this->type() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( + 1, this->type(), target); + } + + // .gayrpc.core.RpcMeta.DataEncodingType encoding = 2; + if (this->encoding() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( + 2, this->encoding(), target); + } + + // .gayrpc.core.RpcMeta.Request request_info = 3; + if (this->has_request_info()) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageToArray( + 3, *this->request_info_, deterministic, target); + } + + // .gayrpc.core.RpcMeta.Response response_info = 4; + if (this->has_response_info()) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageToArray( + 4, *this->response_info_, deterministic, target); + } + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:gayrpc.core.RpcMeta) + return target; +} + +size_t RpcMeta::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:gayrpc.core.RpcMeta) + size_t total_size = 0; + + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } + // .gayrpc.core.RpcMeta.Request request_info = 3; + if (this->has_request_info()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSize( + *this->request_info_); + } + + // .gayrpc.core.RpcMeta.Response response_info = 4; + if (this->has_response_info()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSize( + *this->response_info_); + } + + // .gayrpc.core.RpcMeta.Type type = 1; + if (this->type() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->type()); + } + + // .gayrpc.core.RpcMeta.DataEncodingType encoding = 2; + if (this->encoding() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->encoding()); + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void RpcMeta::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:gayrpc.core.RpcMeta) + GOOGLE_DCHECK_NE(&from, this); + const RpcMeta* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:gayrpc.core.RpcMeta) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:gayrpc.core.RpcMeta) + MergeFrom(*source); + } +} + +void RpcMeta::MergeFrom(const RpcMeta& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:gayrpc.core.RpcMeta) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.has_request_info()) { + mutable_request_info()->::gayrpc::core::RpcMeta_Request::MergeFrom(from.request_info()); + } + if (from.has_response_info()) { + mutable_response_info()->::gayrpc::core::RpcMeta_Response::MergeFrom(from.response_info()); + } + if (from.type() != 0) { + set_type(from.type()); + } + if (from.encoding() != 0) { + set_encoding(from.encoding()); + } +} + +void RpcMeta::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:gayrpc.core.RpcMeta) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void RpcMeta::CopyFrom(const RpcMeta& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:gayrpc.core.RpcMeta) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool RpcMeta::IsInitialized() const { + return true; +} + +void RpcMeta::Swap(RpcMeta* other) { + if (other == this) return; + InternalSwap(other); +} +void RpcMeta::InternalSwap(RpcMeta* other) { + using std::swap; + swap(request_info_, other->request_info_); + swap(response_info_, other->response_info_); + swap(type_, other->type_); + swap(encoding_, other->encoding_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata RpcMeta::GetMetadata() const { + protobuf_meta_2eproto::protobuf_AssignDescriptorsOnce(); + return ::protobuf_meta_2eproto::file_level_metadata[kIndexInFileMessages]; +} + + +// @@protoc_insertion_point(namespace_scope) +} // namespace core +} // namespace gayrpc + +// @@protoc_insertion_point(global_scope) diff --git a/include/meta.pb.h b/include/meta.pb.h new file mode 100644 index 0000000..d3b1335 --- /dev/null +++ b/include/meta.pb.h @@ -0,0 +1,854 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: meta.proto + +#ifndef PROTOBUF_meta_2eproto__INCLUDED +#define PROTOBUF_meta_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 3005000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3005000 < GOOGLE_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 + +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include +// @@protoc_insertion_point(includes) + +namespace protobuf_meta_2eproto { +// Internal implementation detail -- do not use these members. +struct TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[3]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; + static const ::google::protobuf::uint32 offsets[]; +}; +void AddDescriptors(); +void InitDefaultsRpcMeta_RequestImpl(); +void InitDefaultsRpcMeta_Request(); +void InitDefaultsRpcMeta_ResponseImpl(); +void InitDefaultsRpcMeta_Response(); +void InitDefaultsRpcMetaImpl(); +void InitDefaultsRpcMeta(); +inline void InitDefaults() { + InitDefaultsRpcMeta_Request(); + InitDefaultsRpcMeta_Response(); + InitDefaultsRpcMeta(); +} +} // namespace protobuf_meta_2eproto +namespace gayrpc { +namespace core { +class RpcMeta; +class RpcMetaDefaultTypeInternal; +extern RpcMetaDefaultTypeInternal _RpcMeta_default_instance_; +class RpcMeta_Request; +class RpcMeta_RequestDefaultTypeInternal; +extern RpcMeta_RequestDefaultTypeInternal _RpcMeta_Request_default_instance_; +class RpcMeta_Response; +class RpcMeta_ResponseDefaultTypeInternal; +extern RpcMeta_ResponseDefaultTypeInternal _RpcMeta_Response_default_instance_; +} // namespace core +} // namespace gayrpc +namespace gayrpc { +namespace core { + +enum RpcMeta_Type { + RpcMeta_Type_REQUEST = 0, + RpcMeta_Type_RESPONSE = 1, + RpcMeta_Type_RpcMeta_Type_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min, + RpcMeta_Type_RpcMeta_Type_INT_MAX_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max +}; +bool RpcMeta_Type_IsValid(int value); +const RpcMeta_Type RpcMeta_Type_Type_MIN = RpcMeta_Type_REQUEST; +const RpcMeta_Type RpcMeta_Type_Type_MAX = RpcMeta_Type_RESPONSE; +const int RpcMeta_Type_Type_ARRAYSIZE = RpcMeta_Type_Type_MAX + 1; + +const ::google::protobuf::EnumDescriptor* RpcMeta_Type_descriptor(); +inline const ::std::string& RpcMeta_Type_Name(RpcMeta_Type value) { + return ::google::protobuf::internal::NameOfEnum( + RpcMeta_Type_descriptor(), value); +} +inline bool RpcMeta_Type_Parse( + const ::std::string& name, RpcMeta_Type* value) { + return ::google::protobuf::internal::ParseNamedEnum( + RpcMeta_Type_descriptor(), name, value); +} +enum RpcMeta_DataEncodingType { + RpcMeta_DataEncodingType_BINARY = 0, + RpcMeta_DataEncodingType_JSON = 1, + RpcMeta_DataEncodingType_RpcMeta_DataEncodingType_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min, + RpcMeta_DataEncodingType_RpcMeta_DataEncodingType_INT_MAX_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max +}; +bool RpcMeta_DataEncodingType_IsValid(int value); +const RpcMeta_DataEncodingType RpcMeta_DataEncodingType_DataEncodingType_MIN = RpcMeta_DataEncodingType_BINARY; +const RpcMeta_DataEncodingType RpcMeta_DataEncodingType_DataEncodingType_MAX = RpcMeta_DataEncodingType_JSON; +const int RpcMeta_DataEncodingType_DataEncodingType_ARRAYSIZE = RpcMeta_DataEncodingType_DataEncodingType_MAX + 1; + +const ::google::protobuf::EnumDescriptor* RpcMeta_DataEncodingType_descriptor(); +inline const ::std::string& RpcMeta_DataEncodingType_Name(RpcMeta_DataEncodingType value) { + return ::google::protobuf::internal::NameOfEnum( + RpcMeta_DataEncodingType_descriptor(), value); +} +inline bool RpcMeta_DataEncodingType_Parse( + const ::std::string& name, RpcMeta_DataEncodingType* value) { + return ::google::protobuf::internal::ParseNamedEnum( + RpcMeta_DataEncodingType_descriptor(), name, value); +} +// =================================================================== + +class RpcMeta_Request : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:gayrpc.core.RpcMeta.Request) */ { + public: + RpcMeta_Request(); + virtual ~RpcMeta_Request(); + + RpcMeta_Request(const RpcMeta_Request& from); + + inline RpcMeta_Request& operator=(const RpcMeta_Request& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + RpcMeta_Request(RpcMeta_Request&& from) noexcept + : RpcMeta_Request() { + *this = ::std::move(from); + } + + inline RpcMeta_Request& operator=(RpcMeta_Request&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const RpcMeta_Request& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const RpcMeta_Request* internal_default_instance() { + return reinterpret_cast( + &_RpcMeta_Request_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; + + void Swap(RpcMeta_Request* other); + friend void swap(RpcMeta_Request& a, RpcMeta_Request& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline RpcMeta_Request* New() const PROTOBUF_FINAL { return New(NULL); } + + RpcMeta_Request* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const RpcMeta_Request& from); + void MergeFrom(const RpcMeta_Request& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(RpcMeta_Request* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // uint64 method = 1; + void clear_method(); + static const int kMethodFieldNumber = 1; + ::google::protobuf::uint64 method() const; + void set_method(::google::protobuf::uint64 value); + + // uint64 sequence_id = 3; + void clear_sequence_id(); + static const int kSequenceIdFieldNumber = 3; + ::google::protobuf::uint64 sequence_id() const; + void set_sequence_id(::google::protobuf::uint64 value); + + // bool expect_response = 2; + void clear_expect_response(); + static const int kExpectResponseFieldNumber = 2; + bool expect_response() const; + void set_expect_response(bool value); + + // @@protoc_insertion_point(class_scope:gayrpc.core.RpcMeta.Request) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::uint64 method_; + ::google::protobuf::uint64 sequence_id_; + bool expect_response_; + mutable int _cached_size_; + friend struct ::protobuf_meta_2eproto::TableStruct; + friend void ::protobuf_meta_2eproto::InitDefaultsRpcMeta_RequestImpl(); +}; +// ------------------------------------------------------------------- + +class RpcMeta_Response : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:gayrpc.core.RpcMeta.Response) */ { + public: + RpcMeta_Response(); + virtual ~RpcMeta_Response(); + + RpcMeta_Response(const RpcMeta_Response& from); + + inline RpcMeta_Response& operator=(const RpcMeta_Response& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + RpcMeta_Response(RpcMeta_Response&& from) noexcept + : RpcMeta_Response() { + *this = ::std::move(from); + } + + inline RpcMeta_Response& operator=(RpcMeta_Response&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const RpcMeta_Response& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const RpcMeta_Response* internal_default_instance() { + return reinterpret_cast( + &_RpcMeta_Response_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; + + void Swap(RpcMeta_Response* other); + friend void swap(RpcMeta_Response& a, RpcMeta_Response& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline RpcMeta_Response* New() const PROTOBUF_FINAL { return New(NULL); } + + RpcMeta_Response* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const RpcMeta_Response& from); + void MergeFrom(const RpcMeta_Response& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(RpcMeta_Response* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // string reason = 4; + void clear_reason(); + static const int kReasonFieldNumber = 4; + const ::std::string& reason() const; + void set_reason(const ::std::string& value); + #if LANG_CXX11 + void set_reason(::std::string&& value); + #endif + void set_reason(const char* value); + void set_reason(const char* value, size_t size); + ::std::string* mutable_reason(); + ::std::string* release_reason(); + void set_allocated_reason(::std::string* reason); + + // uint64 sequence_id = 1; + void clear_sequence_id(); + static const int kSequenceIdFieldNumber = 1; + ::google::protobuf::uint64 sequence_id() const; + void set_sequence_id(::google::protobuf::uint64 value); + + // bool failed = 2; + void clear_failed(); + static const int kFailedFieldNumber = 2; + bool failed() const; + void set_failed(bool value); + + // int32 error_code = 3; + void clear_error_code(); + static const int kErrorCodeFieldNumber = 3; + ::google::protobuf::int32 error_code() const; + void set_error_code(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:gayrpc.core.RpcMeta.Response) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::ArenaStringPtr reason_; + ::google::protobuf::uint64 sequence_id_; + bool failed_; + ::google::protobuf::int32 error_code_; + mutable int _cached_size_; + friend struct ::protobuf_meta_2eproto::TableStruct; + friend void ::protobuf_meta_2eproto::InitDefaultsRpcMeta_ResponseImpl(); +}; +// ------------------------------------------------------------------- + +class RpcMeta : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:gayrpc.core.RpcMeta) */ { + public: + RpcMeta(); + virtual ~RpcMeta(); + + RpcMeta(const RpcMeta& from); + + inline RpcMeta& operator=(const RpcMeta& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + RpcMeta(RpcMeta&& from) noexcept + : RpcMeta() { + *this = ::std::move(from); + } + + inline RpcMeta& operator=(RpcMeta&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + static const ::google::protobuf::Descriptor* descriptor(); + static const RpcMeta& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const RpcMeta* internal_default_instance() { + return reinterpret_cast( + &_RpcMeta_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; + + void Swap(RpcMeta* other); + friend void swap(RpcMeta& a, RpcMeta& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline RpcMeta* New() const PROTOBUF_FINAL { return New(NULL); } + + RpcMeta* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const RpcMeta& from); + void MergeFrom(const RpcMeta& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(RpcMeta* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + typedef RpcMeta_Request Request; + typedef RpcMeta_Response Response; + + typedef RpcMeta_Type Type; + static const Type REQUEST = + RpcMeta_Type_REQUEST; + static const Type RESPONSE = + RpcMeta_Type_RESPONSE; + static inline bool Type_IsValid(int value) { + return RpcMeta_Type_IsValid(value); + } + static const Type Type_MIN = + RpcMeta_Type_Type_MIN; + static const Type Type_MAX = + RpcMeta_Type_Type_MAX; + static const int Type_ARRAYSIZE = + RpcMeta_Type_Type_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + Type_descriptor() { + return RpcMeta_Type_descriptor(); + } + static inline const ::std::string& Type_Name(Type value) { + return RpcMeta_Type_Name(value); + } + static inline bool Type_Parse(const ::std::string& name, + Type* value) { + return RpcMeta_Type_Parse(name, value); + } + + typedef RpcMeta_DataEncodingType DataEncodingType; + static const DataEncodingType BINARY = + RpcMeta_DataEncodingType_BINARY; + static const DataEncodingType JSON = + RpcMeta_DataEncodingType_JSON; + static inline bool DataEncodingType_IsValid(int value) { + return RpcMeta_DataEncodingType_IsValid(value); + } + static const DataEncodingType DataEncodingType_MIN = + RpcMeta_DataEncodingType_DataEncodingType_MIN; + static const DataEncodingType DataEncodingType_MAX = + RpcMeta_DataEncodingType_DataEncodingType_MAX; + static const int DataEncodingType_ARRAYSIZE = + RpcMeta_DataEncodingType_DataEncodingType_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + DataEncodingType_descriptor() { + return RpcMeta_DataEncodingType_descriptor(); + } + static inline const ::std::string& DataEncodingType_Name(DataEncodingType value) { + return RpcMeta_DataEncodingType_Name(value); + } + static inline bool DataEncodingType_Parse(const ::std::string& name, + DataEncodingType* value) { + return RpcMeta_DataEncodingType_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // .gayrpc.core.RpcMeta.Request request_info = 3; + bool has_request_info() const; + void clear_request_info(); + static const int kRequestInfoFieldNumber = 3; + const ::gayrpc::core::RpcMeta_Request& request_info() const; + ::gayrpc::core::RpcMeta_Request* release_request_info(); + ::gayrpc::core::RpcMeta_Request* mutable_request_info(); + void set_allocated_request_info(::gayrpc::core::RpcMeta_Request* request_info); + + // .gayrpc.core.RpcMeta.Response response_info = 4; + bool has_response_info() const; + void clear_response_info(); + static const int kResponseInfoFieldNumber = 4; + const ::gayrpc::core::RpcMeta_Response& response_info() const; + ::gayrpc::core::RpcMeta_Response* release_response_info(); + ::gayrpc::core::RpcMeta_Response* mutable_response_info(); + void set_allocated_response_info(::gayrpc::core::RpcMeta_Response* response_info); + + // .gayrpc.core.RpcMeta.Type type = 1; + void clear_type(); + static const int kTypeFieldNumber = 1; + ::gayrpc::core::RpcMeta_Type type() const; + void set_type(::gayrpc::core::RpcMeta_Type value); + + // .gayrpc.core.RpcMeta.DataEncodingType encoding = 2; + void clear_encoding(); + static const int kEncodingFieldNumber = 2; + ::gayrpc::core::RpcMeta_DataEncodingType encoding() const; + void set_encoding(::gayrpc::core::RpcMeta_DataEncodingType value); + + // @@protoc_insertion_point(class_scope:gayrpc.core.RpcMeta) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::gayrpc::core::RpcMeta_Request* request_info_; + ::gayrpc::core::RpcMeta_Response* response_info_; + int type_; + int encoding_; + mutable int _cached_size_; + friend struct ::protobuf_meta_2eproto::TableStruct; + friend void ::protobuf_meta_2eproto::InitDefaultsRpcMetaImpl(); +}; +// =================================================================== + + +// =================================================================== + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// RpcMeta_Request + +// uint64 method = 1; +inline void RpcMeta_Request::clear_method() { + method_ = GOOGLE_ULONGLONG(0); +} +inline ::google::protobuf::uint64 RpcMeta_Request::method() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Request.method) + return method_; +} +inline void RpcMeta_Request::set_method(::google::protobuf::uint64 value) { + + method_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Request.method) +} + +// bool expect_response = 2; +inline void RpcMeta_Request::clear_expect_response() { + expect_response_ = false; +} +inline bool RpcMeta_Request::expect_response() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Request.expect_response) + return expect_response_; +} +inline void RpcMeta_Request::set_expect_response(bool value) { + + expect_response_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Request.expect_response) +} + +// uint64 sequence_id = 3; +inline void RpcMeta_Request::clear_sequence_id() { + sequence_id_ = GOOGLE_ULONGLONG(0); +} +inline ::google::protobuf::uint64 RpcMeta_Request::sequence_id() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Request.sequence_id) + return sequence_id_; +} +inline void RpcMeta_Request::set_sequence_id(::google::protobuf::uint64 value) { + + sequence_id_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Request.sequence_id) +} + +// ------------------------------------------------------------------- + +// RpcMeta_Response + +// uint64 sequence_id = 1; +inline void RpcMeta_Response::clear_sequence_id() { + sequence_id_ = GOOGLE_ULONGLONG(0); +} +inline ::google::protobuf::uint64 RpcMeta_Response::sequence_id() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Response.sequence_id) + return sequence_id_; +} +inline void RpcMeta_Response::set_sequence_id(::google::protobuf::uint64 value) { + + sequence_id_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Response.sequence_id) +} + +// bool failed = 2; +inline void RpcMeta_Response::clear_failed() { + failed_ = false; +} +inline bool RpcMeta_Response::failed() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Response.failed) + return failed_; +} +inline void RpcMeta_Response::set_failed(bool value) { + + failed_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Response.failed) +} + +// int32 error_code = 3; +inline void RpcMeta_Response::clear_error_code() { + error_code_ = 0; +} +inline ::google::protobuf::int32 RpcMeta_Response::error_code() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Response.error_code) + return error_code_; +} +inline void RpcMeta_Response::set_error_code(::google::protobuf::int32 value) { + + error_code_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Response.error_code) +} + +// string reason = 4; +inline void RpcMeta_Response::clear_reason() { + reason_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& RpcMeta_Response::reason() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.Response.reason) + return reason_.GetNoArena(); +} +inline void RpcMeta_Response::set_reason(const ::std::string& value) { + + reason_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.Response.reason) +} +#if LANG_CXX11 +inline void RpcMeta_Response::set_reason(::std::string&& value) { + + reason_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:gayrpc.core.RpcMeta.Response.reason) +} +#endif +inline void RpcMeta_Response::set_reason(const char* value) { + GOOGLE_DCHECK(value != NULL); + + reason_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:gayrpc.core.RpcMeta.Response.reason) +} +inline void RpcMeta_Response::set_reason(const char* value, size_t size) { + + reason_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:gayrpc.core.RpcMeta.Response.reason) +} +inline ::std::string* RpcMeta_Response::mutable_reason() { + + // @@protoc_insertion_point(field_mutable:gayrpc.core.RpcMeta.Response.reason) + return reason_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* RpcMeta_Response::release_reason() { + // @@protoc_insertion_point(field_release:gayrpc.core.RpcMeta.Response.reason) + + return reason_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void RpcMeta_Response::set_allocated_reason(::std::string* reason) { + if (reason != NULL) { + + } else { + + } + reason_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), reason); + // @@protoc_insertion_point(field_set_allocated:gayrpc.core.RpcMeta.Response.reason) +} + +// ------------------------------------------------------------------- + +// RpcMeta + +// .gayrpc.core.RpcMeta.Type type = 1; +inline void RpcMeta::clear_type() { + type_ = 0; +} +inline ::gayrpc::core::RpcMeta_Type RpcMeta::type() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.type) + return static_cast< ::gayrpc::core::RpcMeta_Type >(type_); +} +inline void RpcMeta::set_type(::gayrpc::core::RpcMeta_Type value) { + + type_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.type) +} + +// .gayrpc.core.RpcMeta.DataEncodingType encoding = 2; +inline void RpcMeta::clear_encoding() { + encoding_ = 0; +} +inline ::gayrpc::core::RpcMeta_DataEncodingType RpcMeta::encoding() const { + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.encoding) + return static_cast< ::gayrpc::core::RpcMeta_DataEncodingType >(encoding_); +} +inline void RpcMeta::set_encoding(::gayrpc::core::RpcMeta_DataEncodingType value) { + + encoding_ = value; + // @@protoc_insertion_point(field_set:gayrpc.core.RpcMeta.encoding) +} + +// .gayrpc.core.RpcMeta.Request request_info = 3; +inline bool RpcMeta::has_request_info() const { + return this != internal_default_instance() && request_info_ != NULL; +} +inline void RpcMeta::clear_request_info() { + if (GetArenaNoVirtual() == NULL && request_info_ != NULL) { + delete request_info_; + } + request_info_ = NULL; +} +inline const ::gayrpc::core::RpcMeta_Request& RpcMeta::request_info() const { + const ::gayrpc::core::RpcMeta_Request* p = request_info_; + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.request_info) + return p != NULL ? *p : *reinterpret_cast( + &::gayrpc::core::_RpcMeta_Request_default_instance_); +} +inline ::gayrpc::core::RpcMeta_Request* RpcMeta::release_request_info() { + // @@protoc_insertion_point(field_release:gayrpc.core.RpcMeta.request_info) + + ::gayrpc::core::RpcMeta_Request* temp = request_info_; + request_info_ = NULL; + return temp; +} +inline ::gayrpc::core::RpcMeta_Request* RpcMeta::mutable_request_info() { + + if (request_info_ == NULL) { + request_info_ = new ::gayrpc::core::RpcMeta_Request; + } + // @@protoc_insertion_point(field_mutable:gayrpc.core.RpcMeta.request_info) + return request_info_; +} +inline void RpcMeta::set_allocated_request_info(::gayrpc::core::RpcMeta_Request* request_info) { + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + if (message_arena == NULL) { + delete request_info_; + } + if (request_info) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + request_info = ::google::protobuf::internal::GetOwnedMessage( + message_arena, request_info, submessage_arena); + } + + } else { + + } + request_info_ = request_info; + // @@protoc_insertion_point(field_set_allocated:gayrpc.core.RpcMeta.request_info) +} + +// .gayrpc.core.RpcMeta.Response response_info = 4; +inline bool RpcMeta::has_response_info() const { + return this != internal_default_instance() && response_info_ != NULL; +} +inline void RpcMeta::clear_response_info() { + if (GetArenaNoVirtual() == NULL && response_info_ != NULL) { + delete response_info_; + } + response_info_ = NULL; +} +inline const ::gayrpc::core::RpcMeta_Response& RpcMeta::response_info() const { + const ::gayrpc::core::RpcMeta_Response* p = response_info_; + // @@protoc_insertion_point(field_get:gayrpc.core.RpcMeta.response_info) + return p != NULL ? *p : *reinterpret_cast( + &::gayrpc::core::_RpcMeta_Response_default_instance_); +} +inline ::gayrpc::core::RpcMeta_Response* RpcMeta::release_response_info() { + // @@protoc_insertion_point(field_release:gayrpc.core.RpcMeta.response_info) + + ::gayrpc::core::RpcMeta_Response* temp = response_info_; + response_info_ = NULL; + return temp; +} +inline ::gayrpc::core::RpcMeta_Response* RpcMeta::mutable_response_info() { + + if (response_info_ == NULL) { + response_info_ = new ::gayrpc::core::RpcMeta_Response; + } + // @@protoc_insertion_point(field_mutable:gayrpc.core.RpcMeta.response_info) + return response_info_; +} +inline void RpcMeta::set_allocated_response_info(::gayrpc::core::RpcMeta_Response* response_info) { + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + if (message_arena == NULL) { + delete response_info_; + } + if (response_info) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + response_info = ::google::protobuf::internal::GetOwnedMessage( + message_arena, response_info, submessage_arena); + } + + } else { + + } + response_info_ = response_info; + // @@protoc_insertion_point(field_set_allocated:gayrpc.core.RpcMeta.response_info) +} + +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace core +} // namespace gayrpc + +namespace google { +namespace protobuf { + +template <> struct is_proto_enum< ::gayrpc::core::RpcMeta_Type> : ::google::protobuf::internal::true_type {}; +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::gayrpc::core::RpcMeta_Type>() { + return ::gayrpc::core::RpcMeta_Type_descriptor(); +} +template <> struct is_proto_enum< ::gayrpc::core::RpcMeta_DataEncodingType> : ::google::protobuf::internal::true_type {}; +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::gayrpc::core::RpcMeta_DataEncodingType>() { + return ::gayrpc::core::RpcMeta_DataEncodingType_descriptor(); +} + +} // namespace protobuf +} // namespace google + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_meta_2eproto__INCLUDED diff --git a/utils/GayRpcInterceptor.h b/utils/GayRpcInterceptor.h new file mode 100644 index 0000000..31cfb3b --- /dev/null +++ b/utils/GayRpcInterceptor.h @@ -0,0 +1,76 @@ +#ifndef _GAY_RPC_INTERCEPTOR_H +#define _GAY_RPC_INTERCEPTOR_H + +#include +#include +#include +#include + +#include "meta.pb.h" +#include "GayRpcCore.h" + +namespace gayrpc +{ + namespace utils + { + // 实现拦截器 + + template + auto togetherInterceptor(std::vector& interceptorArray, T handler) + { + interceptorArray.push_back(std::forward(handler)); + } + + template + auto togetherInterceptor(std::vector& interceptorArray, T headHandler, Args... leftHandlers) + { + interceptorArray.push_back(std::forward(headHandler)); + togetherInterceptor(interceptorArray, std::forward(leftHandlers)...); + } + + template + core::UnaryServerInterceptor makeInterceptor(Args... args) + { + std::vector interceptors; + togetherInterceptor(interceptors, args...); + + auto n = interceptors.size(); + if (n > 1) + { + auto lastIndex = n - 1; + return [interceptors, lastIndex](const gayrpc::core::RpcMeta& meta, + const google::protobuf::Message& message, + const core::UnaryHandler& next) { + int curI = 0; + core::UnaryHandler fuck; + fuck = [lastIndex, &curI, &interceptors, &next, &fuck](const gayrpc::core::RpcMeta& meta, + const google::protobuf::Message& message) { + if (curI == lastIndex) + { + return next(meta, message); + } + curI++; + return interceptors[curI](meta, message, fuck); + }; + + return interceptors[0](meta, message, fuck); + }; + + } + else if (n == 1) + { + return interceptors[0]; + } + else + { + return [](const gayrpc::core::RpcMeta& meta, + const google::protobuf::Message& message, + const core::UnaryHandler& next) { + next(meta, message); + }; + } + } + } +} + +#endif diff --git a/utils/OpPacket.h b/utils/OpPacket.h new file mode 100644 index 0000000..848d0ab --- /dev/null +++ b/utils/OpPacket.h @@ -0,0 +1,162 @@ +#ifndef _OP_PACKET_H +#define _OP_PACKET_H + +#include + +#include + +// 实现协议解析和序列化 + +namespace gayrpc +{ + namespace oppacket + { + typedef uint32_t OpCodeType; + enum OpCode : OpCodeType + { + OpCodeProtobuf = 1, + }; + + // 基于[len, op] 的消息包格式 + struct OpPacket + { + // header部分 + struct + { + // data部分的长度 + uint64_t data_len; + // opcode + OpCodeType op; + }head; + + // data部分 + const char* data; + }; + + // protobuf RPC 消息包格式 + struct ProtobufPacket + { + // header部分 + struct + { + uint32_t meta_size; // 4 bytes + uint64_t data_size; // 8 bytes + }head; + + std::string meta; + std::string data; + }; + + typedef std::function ProtobufPacketHandler; + + typedef std::function + OpPacketHandler; + + // 解析网络消息中的OpPacket + size_t parseOpPacket(const char* buffer, + size_t len, + const OpPacketHandler& handler) + { + size_t processLen = 0; + + while (len > processLen) + { + BasePacketReader bpr(buffer + processLen, len - processLen); + OpPacket opPacket; + + constexpr auto HEAD_LEN = + sizeof(opPacket.head.data_len) + + sizeof(opPacket.head.op); + + if (bpr.getLeft() < HEAD_LEN) + { + break; + } + + opPacket.head.data_len = bpr.readUINT64(); + opPacket.head.op = bpr.readUINT32(); + + if (bpr.getLeft() < opPacket.head.data_len) + { + break; + } + + opPacket.data = bpr.getBuffer() + bpr.getPos(); + handler(opPacket); + bpr.addPos(opPacket.head.data_len); + + processLen += (HEAD_LEN + opPacket.head.data_len); + } + + return processLen; + } + + + // 解析OpPacket中的protobuf packet + bool parseProtobufPacket(const OpPacket& opPacket, + const ProtobufPacketHandler& handler) + { + BasePacketReader bpr(opPacket.data, opPacket.head.data_len); + + ProtobufPacket protobufPacket; + + constexpr auto HEAD_LEN = + sizeof(protobufPacket.head.meta_size) + + sizeof(protobufPacket.head.data_size); + + if (bpr.getLeft() < HEAD_LEN) + { + return false; + } + + protobufPacket.head.meta_size = bpr.readUINT32(); + protobufPacket.head.data_size = bpr.readUINT64(); + + if (bpr.getLeft() != + (protobufPacket.head.meta_size + + protobufPacket.head.data_size)) + { + return false; + } + + protobufPacket.meta = std::string(bpr.getBuffer() + bpr.getPos(), + protobufPacket.head.meta_size); + bpr.addPos(protobufPacket.head.meta_size); + + protobufPacket.data = std::string(bpr.getBuffer() + bpr.getPos(), + protobufPacket.head.data_size); + bpr.addPos(protobufPacket.head.data_size); + + handler(protobufPacket); + + return true; + } + + void serializeProtobufPacket(BasePacketWriter& bpw, + const std::string& meta, + const std::string& data) + { + ProtobufPacket protobufPacket; + protobufPacket.head.meta_size = meta.size(); + protobufPacket.head.data_size = data.size(); + + OpPacket opPacket; + opPacket.head.op = OpCodeProtobuf; + opPacket.head.data_len = sizeof(protobufPacket.head.meta_size) + + sizeof(protobufPacket.head.data_size) + + protobufPacket.head.meta_size + + protobufPacket.head.data_size; + + bpw.writeUINT64(opPacket.head.data_len); + bpw.writeUINT32(opPacket.head.op); + + bpw.writeUINT32(protobufPacket.head.meta_size); + bpw.writeUINT64(protobufPacket.head.data_size); + + bpw.writeBinary(meta); + bpw.writeBinary(data); + } + } +} + +#endif \ No newline at end of file diff --git a/utils/UtilsDataHandler.h b/utils/UtilsDataHandler.h new file mode 100644 index 0000000..ee51b06 --- /dev/null +++ b/utils/UtilsDataHandler.h @@ -0,0 +1,64 @@ +#ifndef _UTILS_RPC_DATA_HANDLER_H +#define _UTILS_RPC_DATA_HANDLER_H + +#include +#include "OpPacket.h" +#include "GayRpcCore.h" +#include "GayRpcTypeHandler.h" + +static size_t dataHandle(const gayrpc::core::RpcTypeHandleManager::PTR& rpcHandlerManager, + const char* buffer, + size_t len) +{ + auto opHandle = [rpcHandlerManager](const gayrpc::oppacket::OpPacket& opPacket) { + if (opPacket.head.op != gayrpc::oppacket::OpCode::OpCodeProtobuf) + { + return false; + } + + auto pbPacketHandle = [rpcHandlerManager](const gayrpc::oppacket::ProtobufPacket& msg) { + gayrpc::core::RpcMeta meta; + if (!meta.ParseFromString(msg.meta)) + { + std::cerr << "parse RpcMeta protobuf failed" << std::endl; + return false; + } + return rpcHandlerManager->handleRpcMsg(meta, msg.data); + }; + + if (!parseProtobufPacket(opPacket, pbPacketHandle)) + { + std::cout << "parse protobuf packet failed" << std::endl; + return false; + } + + return true; + }; + + return gayrpc::oppacket::parseOpPacket(buffer, len, opHandle); +} + +static void sender(const gayrpc::core::RpcMeta& meta, + const google::protobuf::Message& message, + const gayrpc::core::UnaryHandler& next, + const std::weak_ptr& weakSession) +{ + // 实际的发送 + BigPacket bpw(true, true); + gayrpc::oppacket::serializeProtobufPacket(bpw, + meta.SerializeAsString(), + message.SerializeAsString()); + + auto session = weakSession.lock(); + if (session != nullptr) + { + session->send(bpw.getData(), bpw.getPos()); + } + else + { + // throw ConnectionClose exception + } + next(meta, message); +} + +#endif \ No newline at end of file diff --git a/utils/UtilsInterceptor.h b/utils/UtilsInterceptor.h new file mode 100644 index 0000000..53b85e0 --- /dev/null +++ b/utils/UtilsInterceptor.h @@ -0,0 +1,47 @@ +#ifndef _GAY_RPC_UTILS_INTERCEPTOR_H +#define _GAY_RPC_UTILS_INTERCEPTOR_H + +#include +#include +#include + +#include "meta.pb.h" +#include "GayRpcCore.h" +#include "GayRpcInterceptor.h" +#include "UtilsDataHandler.h" + +namespace utils_interceptor +{ + // 一些辅助型拦截器 + + auto withProtectedCall() + { + return [](const gayrpc::core::RpcMeta& meta, + const google::protobuf::Message& message, + const gayrpc::core::UnaryHandler& next) { + try + { + next(meta, message); + } + catch (const std::exception& e) + { + std::cout << e.what() << std::endl; + } + catch (...) + { + std::cout << "unknow exception" << std::endl; + } + }; + } + + auto withSessionSender(std::weak_ptr weakSession) + { + return [weakSession](const gayrpc::core::RpcMeta& meta, + const google::protobuf::Message& message, + const gayrpc::core::UnaryHandler& next) { + sender(meta, message, next, weakSession); + }; + } +} + +#endif \ No newline at end of file