├── autobuild.sh ├── main ├── bin ├── comsumer ├── provider ├── test.conf ├── 123-4-20 └── 2023-5-20 ├── example ├── CMakeLists.txt ├── callee │ ├── CMakeLists.txt │ └── userservice.cpp ├── caller │ ├── CMakeLists.txt │ └── callerservice.cpp ├── user.proto ├── readme.md └── user.pb.h ├── lib └── libmrpc.a ├── test ├── protobuf │ ├── test │ ├── test.proto │ ├── main.cpp │ └── readme.md └── muduo │ ├── muduo_test │ └── muduo_test.cpp ├── image └── readme │ ├── 1683203012139.png │ ├── 1683515297035.png │ ├── 1683532996522.png │ ├── 1683533058591.png │ ├── 1683533468488.png │ ├── 1684062797668.png │ ├── 1684069267046.png │ ├── image-20230504110022486.png │ ├── image-20230504110054259.png │ ├── image-20230504110857220.png │ ├── image-20230504111950425.png │ ├── image-20230504142329365.png │ ├── image-20230504144227395.png │ ├── image-20230504144250652.png │ ├── image-20230504144658261.png │ ├── image-20230524132913590.png │ ├── image-20230530205710357.png │ ├── image-20230531103000019.png │ ├── image-20230531104449274.png │ ├── image-20230531104953708.png │ ├── image-20230531105559663.png │ └── image-20230606171203397.png ├── main.cpp ├── src ├── rpc_header.proto ├── include │ ├── Zookeeperutil.h │ ├── MrpcChannel.h │ ├── MrpcConfig.h │ ├── MrpcLog.h │ ├── MrpcController.h │ ├── MrpcApplication.h │ ├── Lockqueue.h │ ├── RpcProvider.h │ └── rpc_header.pb.h ├── CMakeLists.txt ├── Lockqueue.cpp ├── MrpcController.cpp ├── MrpcLog.cpp ├── MrpcApplication.cpp ├── MrpcConfig.cpp ├── Zookeeperutil.cpp ├── MrpcChannel.cpp ├── RpcProvider.cpp └── rpc_header.pb.cc ├── .vscode ├── c_cpp_properties.json ├── tasks.json ├── launch.json └── settings.json ├── CMakeLists.txt └── readme.md /autobuild.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/main -------------------------------------------------------------------------------- /bin/comsumer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/bin/comsumer -------------------------------------------------------------------------------- /bin/provider: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/bin/provider -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(callee) 2 | add_subdirectory(caller) -------------------------------------------------------------------------------- /lib/libmrpc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/lib/libmrpc.a -------------------------------------------------------------------------------- /test/protobuf/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/test/protobuf/test -------------------------------------------------------------------------------- /test/muduo/muduo_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/test/muduo/muduo_test -------------------------------------------------------------------------------- /image/readme/1683203012139.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1683203012139.png -------------------------------------------------------------------------------- /image/readme/1683515297035.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1683515297035.png -------------------------------------------------------------------------------- /image/readme/1683532996522.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1683532996522.png -------------------------------------------------------------------------------- /image/readme/1683533058591.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1683533058591.png -------------------------------------------------------------------------------- /image/readme/1683533468488.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1683533468488.png -------------------------------------------------------------------------------- /image/readme/1684062797668.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1684062797668.png -------------------------------------------------------------------------------- /image/readme/1684069267046.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stolendance/mrpc/HEAD/image/readme/1684069267046.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | cout<<"hello world"< 2 | #include 3 | class Zookeeperutil 4 | { 5 | public: 6 | Zookeeperutil(); 7 | ~Zookeeperutil(); 8 | void start(); 9 | void create(std::string path, std::string data, int state); 10 | std::string getData(std::string path); 11 | private: 12 | zhandle_t *m_handle; 13 | }; -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 当前文件夹所有文件的名字 放入SRC_LIST 2 | #aux_source_directory(. SRC_LIST) 3 | set(SRC_LIST rpc_header.pb.cc RpcProvider.cpp MrpcApplication.cpp MrpcConfig.cpp MrpcChannel.cpp MrpcController.cpp MrpcLog.cpp Zookeeperutil.cpp) 4 | # 生成动态库 头文件 在顶层的cmakelist中 已经找到 5 | add_library(mrpc ${SRC_LIST}) 6 | target_link_libraries(mrpc muduo_net muduo_base pthread zookeeper_mt) -------------------------------------------------------------------------------- /src/Lockqueue.cpp: -------------------------------------------------------------------------------- 1 | #include"Lockqueue.h" 2 | template 3 | void Lockqueue::push(T data) 4 | { 5 | std::lock_guard(mt); 6 | line.push(data); 7 | cont.notify_one(); 8 | } 9 | template 10 | T Lockqueue::pop() 11 | { 12 | std::unique_lock(mt); 13 | while(line.size()==0) 14 | { 15 | cont.wait(mt); 16 | } 17 | T data=line.front(); 18 | line.pop(); 19 | return data; 20 | } -------------------------------------------------------------------------------- /src/include/MrpcChannel.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | class MrpcChannel:public google::protobuf::RpcChannel 4 | { 5 | public: 6 | void CallMethod(const google::protobuf::MethodDescriptor* method, 7 | google::protobuf::RpcController* controller, const google::protobuf::Message* request, 8 | google::protobuf::Message* response, google::protobuf::Closure* done); 9 | 10 | }; -------------------------------------------------------------------------------- /src/include/MrpcConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | // 框架读取配置文件类 5 | // rpcip 6 | // rpcport 7 | // zookeeper ip 8 | // zookeeper port 9 | class MrpcConfig 10 | { 11 | public: 12 | // 负责解析加载配置文件 13 | void LoadConfigFile(const char* config_file); 14 | std::string Load(const std::string &key); 15 | std::string Trim(std::string src_buf); 16 | 17 | private: 18 | std::unordered_map m_configure; 19 | 20 | }; -------------------------------------------------------------------------------- /src/include/MrpcLog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include"Lockqueue.h" 6 | class MrpcLog 7 | { 8 | public: 9 | static MrpcLog & getInstance(); 10 | std::string read_log(); 11 | void log(std::string data); 12 | private: 13 | Lockqueue line; 14 | MrpcLog(); 15 | MrpcLog(const MrpcLog &&)=delete; 16 | MrpcLog(MrpcLog &)=delete; 17 | MrpcLog& operator=(const MrpcLog &)=delete; 18 | }; -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "${workspaceFolder}/src/include" 8 | ], 9 | "defines": [], 10 | "compilerPath": "/usr/bin/gcc", 11 | "cStandard": "c11", 12 | "cppStandard": "gnu++14", 13 | "intelliSenseMode": "linux-gcc-x64", 14 | "configurationProvider": "ms-vscode.cmake-tools" 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /src/include/MrpcController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | class MrpcController : public google::protobuf::RpcController 6 | { 7 | public: 8 | void Reset(); 9 | bool Failed() const; 10 | std::string ErrorText() const; 11 | void SetFailed(const std::string& reason); 12 | 13 | // 以下三个方法先不实现 14 | void StartCancel(); 15 | bool IsCanceled() const; 16 | void NotifyOnCancel(google::protobuf::Closure* callback); 17 | private: 18 | bool isfail=false; 19 | std::string failtext; 20 | }; -------------------------------------------------------------------------------- /src/include/MrpcApplication.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"MrpcConfig.h" 3 | // mrpc 框架的初始化类 4 | // 框架只需要一个 因此用单例模式进行设计 5 | 6 | class MrpcApplication 7 | { 8 | public: 9 | static void Init(int argc, char ** argv); 10 | static MrpcApplication& GetInstance(); 11 | static MrpcConfig& getConfig(); 12 | private: 13 | static MrpcConfig m_config; 14 | MrpcApplication(){}; 15 | MrpcApplication(const MrpcApplication & other)=delete; 16 | MrpcApplication(MrpcApplication && other)=delete; 17 | MrpcApplication& operator =(const MrpcApplication& other)=delete; 18 | 19 | }; -------------------------------------------------------------------------------- /example/user.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3"; 2 | package fixbug; 3 | option cc_generic_services = true; 4 | message ResultCode 5 | { 6 | int32 errcode=1; 7 | bytes errmsg=2; 8 | } 9 | message LoginRequest 10 | { 11 | bytes name=1; 12 | bytes pwd=2; 13 | } 14 | message LoginResponse 15 | { 16 | ResultCode result=1; 17 | bool success=2; 18 | } 19 | message HelloRequest 20 | { 21 | bytes name=1; 22 | } 23 | message HelloReponse 24 | { 25 | bytes hello=2; 26 | } 27 | service UserServiceRpc 28 | { 29 | rpc Login(LoginRequest) returns(LoginResponse); 30 | rpc Hello(HelloRequest) returns(HelloReponse); 31 | } -------------------------------------------------------------------------------- /src/MrpcController.cpp: -------------------------------------------------------------------------------- 1 | #include"MrpcController.h" 2 | void MrpcController::SetFailed(const std::string& reason) 3 | { 4 | isfail=true; 5 | failtext=reason; 6 | } 7 | bool MrpcController::Failed() const 8 | { 9 | return isfail; 10 | } 11 | void MrpcController::Reset() 12 | { 13 | isfail=false; 14 | failtext=""; 15 | } 16 | std::string MrpcController::ErrorText() const 17 | { 18 | return failtext; 19 | } 20 | void MrpcController::StartCancel() 21 | { 22 | ; 23 | } 24 | bool MrpcController::IsCanceled() const 25 | { 26 | return true; 27 | } 28 | void MrpcController::NotifyOnCancel(google::protobuf::Closure* callback) 29 | { 30 | return; 31 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 设置cmake 最低版本和项目名称 2 | cmake_minimum_required(VERSION 3.0) 3 | project(mrpc) 4 | 5 | # 生成debug版本,可以进行gdb调试 6 | set(CMAKE_BUILD_TYPE "Debug") 7 | # ·作用是在生成目录,产生一个compile_commands.json文件 8 | set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) 9 | 10 | # 设置项目可执行文件输出的路径 11 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 12 | # 设置项目库文件输出的路径 13 | set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) 14 | 15 | # 设置项目编译头文件搜索路径 16 | include_directories(${PROJECT_SOURCE_DIR}/src/include) 17 | include_directories(${PROJECT_SOURCE_DIR}/example) 18 | # 设置项目库文件搜索路径 19 | link_directories(${PROJECT_SOURCE_DIR}/lib) 20 | 21 | add_subdirectory(src) 22 | # 继续去example 中找cmakelist 23 | add_subdirectory(example) -------------------------------------------------------------------------------- /src/include/Lockqueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | template 6 | class Lockqueue 7 | { 8 | public: 9 | T pop() 10 | { 11 | std::unique_lock lock(mt); 12 | while(line.size()==0) 13 | { 14 | cont.wait(lock); 15 | } 16 | T data=line.front(); 17 | line.pop(); 18 | return data; 19 | } 20 | void push(T data) 21 | { 22 | std::lock_guard lock(mt); 23 | line.push(data); 24 | cont.notify_one(); 25 | } 26 | private: 27 | std::queue line; 28 | std::mutex mt; 29 | std::condition_variable cont; 30 | }; 31 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++ 生成活动文件", 6 | "command": "/usr/bin/g++", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}/${fileBasenameNoExtension}" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "调试器生成的任务。" 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "(gdb) 启动", 5 | "type": "cppdbg", 6 | "request": "launch", 7 | "program": "输入程序名称,例如 ${workspaceFolder}/a.out", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "cwd": "${fileDirname}", 11 | "environment": [], 12 | "externalConsole": false, 13 | "MIMode": "gdb", 14 | "setupCommands": [ 15 | { 16 | "description": "为 gdb 启用整齐打印", 17 | "text": "-enable-pretty-printing", 18 | "ignoreFailures": true 19 | }, 20 | { 21 | "description": "将反汇编风格设置为 Intel", 22 | "text": "-gdb-set disassembly-flavor intel", 23 | "ignoreFailures": true 24 | } 25 | ] 26 | } 27 | ], 28 | "version": "2.0.0" 29 | } -------------------------------------------------------------------------------- /bin/2023-5-20: -------------------------------------------------------------------------------- 1 | 11::31::47 2 | hello world1 3 | 11::31::47 4 | hello world2 5 | 11::31::47 6 | hello world3 7 | Sat May 20 10:33:05 2023 8 | 9 | hello world1 10 | Sat May 20 10:33:05 2023 11 | 12 | hello world2 13 | Sat May 20 10:33:05 2023 14 | 15 | hello world3 16 | Sat May 20 10:33:52 2023 17 | hello world1 18 | Sat May 20 10:33:52 2023 19 | hello world2 20 | Sat May 20 10:33:52 2023 21 | hello world3 22 | Sat May 20 11:30:22 2023 23 | hello world1 24 | Sat May 20 11:30:22 2023 25 | hello world2 26 | Sat May 20 11:30:22 2023 27 | hello world3 28 | Sat May 20 11:30:50 2023 29 | hello world1 30 | Sat May 20 11:30:50 2023 31 | hello world2 32 | Sat May 20 11:30:50 2023 33 | hello world3 34 | Sat May 20 11:31:59 2023 35 | hello world1 36 | Sat May 20 11:31:59 2023 37 | hello world2 38 | Sat May 20 11:31:59 2023 39 | hello world3 40 | Sat May 20 11:32:37 2023 41 | hello world1 42 | Sat May 20 11:32:37 2023 43 | hello world2 44 | Sat May 20 11:32:37 2023 45 | hello world3 46 | -------------------------------------------------------------------------------- /src/MrpcLog.cpp: -------------------------------------------------------------------------------- 1 | #include"MrpcLog.h" 2 | #include 3 | #include 4 | #include 5 | MrpcLog& MrpcLog::getInstance() 6 | { 7 | static MrpcLog instance; 8 | return instance; 9 | } 10 | MrpcLog::MrpcLog() 11 | { 12 | std::thread read_task([&](){ 13 | for(;;) 14 | { 15 | std::string data=read_log(); 16 | time_t t; 17 | time(&t); 18 | tm* tt=localtime(&t); 19 | char filename[100]; 20 | sprintf(filename,"%d-%d-%d",tt->tm_year+1900,tt->tm_mon+1,tt->tm_mday); 21 | FILE* fp=fopen(filename,"a"); 22 | char tmt[100]; 23 | sprintf(tmt,"%d::%d::%d",tt->tm_hour+1,tt->tm_min+1,tt->tm_sec); 24 | fprintf(fp, "%s %s\n",ctime(&t),data.c_str()); 25 | fclose(fp); 26 | } 27 | }); 28 | read_task.detach(); 29 | } 30 | std::string MrpcLog::read_log() 31 | { 32 | std::string data=line.pop(); 33 | return data; 34 | } 35 | 36 | void MrpcLog::log(std::string data) 37 | { 38 | line.push(data); 39 | } -------------------------------------------------------------------------------- /test/protobuf/test.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3";// 声明proto版本 2 | 3 | package fixbug;// 声明代码所在的包(对c++来说就是namespace) 4 | 5 | // 定义下列选项, 表明rpc服务定义方法需要生成 6 | option cc_generic_services=true; 7 | 8 | message ResultCode 9 | { 10 | int32 errcode=1; 11 | bytes errmsg=2; 12 | } 13 | // 定义登陆请求消息类型 14 | message LoginRequest 15 | { 16 | bytes name=1; // 表明第一个字段 17 | bytes pwd=2; // 定义第二个字段 18 | } 19 | // 定义登陆响应消息类型 20 | message LoginResponse 21 | { 22 | ResultCode result=1; 23 | bool success=2; 24 | } 25 | 26 | message User 27 | { 28 | bytes name=1; 29 | uint32 age=2; 30 | enum Sex 31 | { 32 | MAN=0; 33 | WOMAN=1; 34 | } 35 | Sex sex=3; 36 | } 37 | message GetFriendListsRequest 38 | { 39 | uint32 userid=1; 40 | } 41 | message GetFriendListsResponse 42 | { 43 | ResultCode result=1; 44 | repeated User friend_lists=2; 45 | } 46 | 47 | // 在proto中定义rpc方法类型 必须定义option 才能生成该代码 48 | service UserServiceRpc 49 | { 50 | rpc Login(LoginRequest) returns(LoginResponse); 51 | rpc GetFriendLists(GetFriendListsRequest) returns(GetFriendListsResponse); 52 | } -------------------------------------------------------------------------------- /test/muduo/muduo_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | void OnConnection(const muduo::net::TcpConnectionPtr &conn) 8 | { 9 | 10 | } 11 | void OnMessage(const muduo::net::TcpConnectionPtr &conn,muduo::net::Buffer* buffer,muduo::Timestamp timestamp) 12 | { 13 | conn->send("received\n"); 14 | conn->send(buffer); 15 | } 16 | int main() 17 | { 18 | // 绑定地址及端口 19 | std::string ip="127.0.0.1"; 20 | uint16_t port=8032; 21 | muduo::net::InetAddress address(ip,port); 22 | // 创建event_loop 相当于 reactor模型中的事件分发器 23 | muduo::net::EventLoop event_loop; 24 | // 创建服务器,相当于reactor 25 | muduo::net::TcpServer server(&event_loop,address,"reactor"); 26 | server.setThreadNum(4); 27 | // 绑定相关函数 28 | server.setConnectionCallback(std::bind(&OnConnection,std::placeholders::_1)); 29 | server.setMessageCallback(std::bind(&OnMessage,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3)); 30 | server.start(); 31 | event_loop.loop(); 32 | } -------------------------------------------------------------------------------- /src/include/RpcProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "google/protobuf/service.h" 3 | // 框架提供的专门服务发布rpc的网络对象类 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class RpcProvider 14 | { 15 | public: 16 | // 这里是框架提供的外部进行注册 17 | // void NotifyServise(UserService* service) 不能依赖于某个具体业务! 18 | void NotifyService(google::protobuf::Service * service); 19 | 20 | // 启动网络调用函数 21 | void Run(); 22 | 23 | void OnConnection(const muduo::net::TcpConnectionPtr &conn); 24 | 25 | void OnMessage(const muduo::net::TcpConnectionPtr&,muduo::net::Buffer*,muduo::Timestamp); 26 | 27 | void callmeback(const muduo::net::TcpConnectionPtr& conn,google::protobuf::Message* response); 28 | private: 29 | struct ServiceInfo 30 | { 31 | google::protobuf::Service* service_ptr; 32 | std::map method_dic; 33 | }; 34 | std::map service_dic; 35 | // 组合了evenetloop 36 | muduo::net::EventLoop m_eventLoop; 37 | }; -------------------------------------------------------------------------------- /test/protobuf/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "test.pb.h" 4 | using namespace fixbug; 5 | using namespace std; 6 | int main() 7 | { 8 | 9 | // 封装了login请求对象的数据 10 | LoginRequest req; 11 | req.set_name("zhang san"); 12 | req.set_pwd("123456"); 13 | 14 | // 对象数据序列化-》char* 15 | string send_str; 16 | if(req.SerializeToString(&send_str)) 17 | { 18 | cout<set_errcode(1); 33 | rc->set_errmsg("登陆处理失败"); 34 | 35 | GetFriendListsResponse rlist; 36 | ResultCode* rc2=rlist.mutable_result(); 37 | rc2->set_errcode(0); 38 | 39 | User *user1=rlist.add_friend_lists(); 40 | user1->set_name("zhang san"); 41 | user1->set_age(20); 42 | user1->set_sex(User::MAN); 43 | 44 | User *user2=rlist.add_friend_lists(); 45 | user2->set_name("zhang san"); 46 | user2->set_age(20); 47 | user2->set_sex(User::MAN); 48 | 49 | cout< 2 | #include"MrpcApplication.h" 3 | #include"MrpcChannel.h" 4 | #include"MrpcController.h" 5 | #include"user.pb.h" 6 | int main(int argc, char** argv) 7 | { 8 | // 要是想调用的话, 需要传入相关参数 ,进行配置,全局只会初始化一次 9 | MrpcApplication::Init(argc,argv); 10 | 11 | // 12 | fixbug::UserServiceRpc_Stub stub(new MrpcChannel()); 13 | // 初始化相关参数 14 | 15 | fixbug::LoginRequest request; 16 | request.set_name("云霞川"); 17 | request.set_pwd("hch12345"); 18 | fixbug::LoginResponse response; 19 | MrpcController controller; 20 | 21 | stub.Login(&controller,&request,&response,nullptr); 22 | // 会自动调rpcchannel 用callmethod 23 | 24 | if(!controller.Failed()) 25 | { 26 | // 得到执行后的response 27 | if(!response.success()) 28 | { 29 | std::cout<<"远程rpc函数执行失败"< 2 | #include 3 | #include "MrpcApplication.h" 4 | MrpcConfig MrpcApplication::m_config; 5 | void ShowArgsHelp() 6 | { 7 | std::cout<<"format: command -i " <" < 3 | #include 4 | #include 5 | #include 6 | void MrpcConfig::LoadConfigFile(const char* config_file) 7 | { 8 | FILE *pf=fopen(config_file,"r"); 9 | if(pf==nullptr) 10 | { 11 | std::cout< 48 | #include 49 | #include"user.pb.h" 50 | /* 51 | #include "../user.pb.h" 不需要 因为外层的cmakelist已经设定好搜寻头文件的地址 52 | userservice 原本是一个本地服务,提供了两个进程内的本地方法,login和getfriendlists 53 | */ 54 | // 55 | class UserService:public fixbug::UserServiceRpc 56 | { 57 | public: 58 | bool Login(std::string name, std::string pwd) 59 | { 60 | std::cout<<"doing local service: Login"<login(loginrequest)-> 69 | 70 | */ 71 | void Login(::google::protobuf::RpcController* controller, 72 | const ::fixbug::LoginRequest* request, 73 | ::fixbug::LoginResponse* response, 74 | ::google::protobuf::Closure* done) 75 | { 76 | // 框架给业务上爆了请求参数LoginRequest,业务获取相应数据做本地业务 77 | std::string name=request->name(); 78 | std::string pwd=request->pwd(); 79 | // 做本地业务 80 | bool login_result=Login(name,pwd); 81 | // 把响应写入 82 | fixbug::ResultCode * code=response->mutable_result(); 83 | code->set_errcode(0); 84 | code->set_errmsg(""); 85 | response->set_success(login_result); 86 | // 执行回调操作 执行响应对象数据的序列化和网络发送(都是由框架来完成的) 87 | done->Run(); 88 | 89 | } 90 | 91 | 92 | }; 93 | int main(int argc,char **argv) 94 | { 95 | // 调用框架的初始化操作 96 | MrpcApplication::Init(argc,argv); 97 | 98 | // 把UserService对象发布到rpc节点上 99 | RpcProvider provider; // 网络发布对象 100 | provider.NotifyService(new UserService()); 101 | provider.NotifyService(new ProductService()); 102 | 103 | //启动rpc 104 | provider.run() 105 | 106 | return 0; 107 | } 108 | ``` 109 | -------------------------------------------------------------------------------- /example/callee/userservice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"user.pb.h" 4 | #include"MrpcApplication.h" 5 | #include"MrpcLog.h" 6 | #include"RpcProvider.h" 7 | #include 8 | /* 9 | #include "../user.pb.h" 不需要 因为外层的cmakelist已经设定好搜寻头文件的地址 10 | userservice 原本是一个本地服务,提供了两个进程内的本地方法,login和getfriendlists 11 | */ 12 | 13 | // 14 | std::string HelloQ(std::string name) 15 | { 16 | std::string s="hello "+ name +"!"; 17 | return s; 18 | } 19 | class UserService:public fixbug::UserServiceRpc 20 | { 21 | public: 22 | void Hello(::google::protobuf::RpcController* controller, 23 | const ::fixbug::HelloRequest* request, 24 | ::fixbug::HelloReponse* response, 25 | ::google::protobuf::Closure* done) 26 | { 27 | std::string name=request->name(); 28 | std::string rs=HelloQ(name); 29 | response->set_hello(rs); 30 | done->Run(); 31 | } 32 | 33 | bool Login(std::string name, std::string pwd) 34 | { 35 | std::cout<<"doing local service: Login"<login(loginrequest)-> 44 | 45 | */ 46 | void Login(::google::protobuf::RpcController* controller, 47 | const ::fixbug::LoginRequest* request, 48 | ::fixbug::LoginResponse* response, 49 | ::google::protobuf::Closure* done) 50 | { 51 | // 框架给业务上爆了请求参数LoginRequest,业务获取相应数据做本地业务 52 | std::string name=request->name(); 53 | std::string pwd=request->pwd(); 54 | 55 | std::cout<<"rpc_login name: "<mutable_result(); 61 | code->set_errcode(0); 62 | code->set_errmsg(""); 63 | response->set_success(login_result); 64 | // 执行回调操作 执行响应对象数据的序列化和网络发送(都是由框架来完成的) 65 | done->Run(); 66 | } 67 | 68 | 69 | }; 70 | int main(int argc,char **argv) 71 | { 72 | // 调用框架的初始化操作 73 | MrpcApplication::Init(argc,argv); 74 | // 把UserService对象发布到rpc节点上 75 | RpcProvider provider; // 网络发布对象 76 | provider.NotifyService(new UserService()); 77 | //启动rpc 78 | provider.Run(); 79 | 80 | return 0; 81 | // MrpcLog& Log= MrpcLog::getInstance(); 82 | // Log.log("hello world1"); 83 | // Log.log("hello world2"); 84 | // Log.log("hello world3"); 85 | // std::this_thread::sleep_for(std::chrono::milliseconds(500)); 86 | 87 | } -------------------------------------------------------------------------------- /src/Zookeeperutil.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"Zookeeperutil.h" 3 | #include"MrpcApplication.h" 4 | #include 5 | #include 6 | // 全局的watcher观察器, zkserver给zkclient的通知 7 | void global_watcher(zhandle_t* zh,int type,int state,const char *path, void* wwatcherCtx) 8 | { 9 | if(type==ZOO_SESSION_EVENT) 10 | { 11 | if(state==ZOO_CONNECTED_STATE) 12 | { 13 | 14 | sem_t* sem=(sem_t*)zoo_get_context(zh); 15 | sem_post(sem); 16 | } 17 | } 18 | } 19 | Zookeeperutil::Zookeeperutil() 20 | { 21 | ; 22 | } 23 | void Zookeeperutil::start() 24 | { 25 | std::string host=MrpcApplication::GetInstance().getConfig().Load("zookeeperip"); 26 | std::string port=MrpcApplication::GetInstance().getConfig().Load("zookeeperport"); 27 | std::string connstr=host+":"+port; 28 | 29 | /* 30 | zookeeper_mt:多线程版本 31 | zookeeper的API客户端程序提供了三个线程 32 | API调用线程 33 | 网络I/O线程 pthread_create poll 34 | watcher回调线程 pthread_create 35 | */ 36 | m_handle=zookeeper_init(connstr.c_str(),global_watcher, 30000, nullptr, nullptr, 0); 37 | if(m_handle==nullptr) 38 | { 39 | std::cout<<"zookeeper_init error"< 4 | #include /* See NOTES */ 5 | #include 6 | #include 7 | #include 8 | #include "MrpcApplication.h" 9 | #include "Zookeeperutil.h" 10 | void MrpcChannel::CallMethod(const google::protobuf::MethodDescriptor* method, 11 | google::protobuf::RpcController* controller, const google::protobuf::Message* request, 12 | google::protobuf::Message* response, google::protobuf::Closure* done) 13 | { 14 | //需要 得到 序列化后的字节流 15 | // 4字节代表rpc_header长度 rpc_header args 16 | // 先得到rpc_header 17 | src::RpcHeader header; 18 | // rpc_header 包含 service_name,method_name,args_len 19 | const google::protobuf::ServiceDescriptor* service=method->service(); 20 | std::string service_name=service->name(); 21 | std::string method_name=method->name(); 22 | //args序列化 并得到长度 23 | std::string args_str; 24 | request->SerializeToString(&args_str); 25 | uint32_t args_len=args_str.size(); 26 | header.set_args_len(args_len); 27 | header.set_method_name(method_name); 28 | header.set_service_name(service_name); 29 | //rpc_header 序列化 30 | std::string rpc_header_str; 31 | header.SerializeToString(&rpc_header_str); 32 | std::string rpc_header_len_str; 33 | uint32_t rpc_header_len=rpc_header_str.size(); 34 | rpc_header_len_str.insert(0,std::string((char*)&rpc_header_len,4)); 35 | 36 | // 字符串都已经准备好 37 | std::string send_str; 38 | send_str+=rpc_header_len_str; 39 | send_str+=rpc_header_str; 40 | send_str+=args_str; 41 | 42 | std::string zoo_ip=MrpcApplication::getConfig().Load("zookeeperip"); 43 | uint16_t zoo_port=stoi(MrpcApplication::getConfig().Load("zookeeperport")); 44 | 45 | 46 | std::string zoo_str="/"+service_name+"/"+method_name; 47 | Zookeeperutil zk=Zookeeperutil(); 48 | zk.start(); 49 | std::string ip_port=zk.getData(zoo_str); 50 | if(ip_port.size()==0) 51 | { 52 | std::cout<<"未找到zookeeper"<SetFailed("client_sock申请失败"); 68 | return; 69 | } 70 | struct sockaddr_in sock_addr; 71 | sock_addr.sin_family=AF_INET; 72 | sock_addr.sin_port=htons(port); 73 | sock_addr.sin_addr.s_addr=inet_addr(ip.c_str()); 74 | if(connect(client_sock,(sockaddr*)&sock_addr,sizeof(sock_addr))<0) 75 | { 76 | controller->SetFailed("连接失败"); 77 | return; 78 | } 79 | // 发送信息 80 | int len=0; 81 | if(len=send(client_sock,send_str.c_str(),send_str.size(),0)<0) 82 | { 83 | controller->SetFailed("发送失败"); 84 | return; 85 | } 86 | char buf[1024]={0}; 87 | int len2=0; 88 | if((len2=recv(client_sock,buf,1024,0))<0) 89 | { 90 | controller->SetFailed("接受失败"); 91 | return; 92 | } 93 | std::string response_str=buf; 94 | response->ParseFromArray(buf,len2); 95 | //std::cout<<"success: "<ParseFromString(response_str); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /src/RpcProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "RpcProvider.h" 2 | #include "MrpcApplication.h" 3 | #include "rpc_header.pb.h" 4 | #include 5 | #include 6 | #include "Zookeeperutil.h" 7 | void RpcProvider::NotifyService(google::protobuf::Service * service){ 8 | const google::protobuf::ServiceDescriptor* service_ptr =service->GetDescriptor(); 9 | // 得到method的数量 10 | const std::string service_name=service_ptr->name(); 11 | int n= service_ptr->method_count(); 12 | std::map method_dic; 13 | // 遍历方法 ,进行存储 14 | for(int i=0;imethod(i); 17 | const std::string method_name=method_ptr->name(); 18 | method_dic[method_name]=method_ptr; 19 | } 20 | ServiceInfo sinfo; 21 | sinfo.service_ptr=service; 22 | sinfo.method_dic=method_dic; 23 | service_dic[service_name]=sinfo; 24 | 25 | // for(auto item:service_dic) 26 | // { 27 | // std::cout<<"服务名:"<retrieveAllAsString(); 89 | // 截取前四个字节 90 | uint32_t len=0; 91 | buffer_str.copy((char*)&len,4,0); 92 | // 解析rpc_header对象 93 | std::string rpc_header_str=buffer_str.substr(4,len); 94 | src::RpcHeader rpcheader=src::RpcHeader(); 95 | if(!rpcheader.ParseFromString(rpc_header_str)) 96 | { 97 | // 解析失败 98 | std::cout<<"rpcheader解析失败"<GetRequestPrototype(method_des).New(); 124 | google::protobuf::Message* response=service->GetResponsePrototype(method_des).New(); 125 | if(!request->ParseFromString(args_str)) 126 | { 127 | std::cout<<"解析参数失败"< (callmeback,conn,response); 132 | auto done=google::protobuf::NewCallback< RpcProvider,const muduo::net::TcpConnectionPtr& ,google::protobuf::Message* > (this,&RpcProvider::callmeback,conn,response); 133 | 134 | // 调用该函数 135 | service->CallMethod(method_des,nullptr,request,response,done); 136 | } 137 | // 需要连接, response 138 | void RpcProvider::callmeback(const muduo::net::TcpConnectionPtr& conn,google::protobuf::Message* response) 139 | { 140 | // 序列化 141 | std::string response_str; 142 | if(!response->SerializeToString(&response_str)) 143 | { 144 | std::cout<<"response序列化失败"<send(response_str); 148 | // 模仿http的短连接 149 | conn->shutdown(); 150 | 151 | } -------------------------------------------------------------------------------- /test/protobuf/readme.md: -------------------------------------------------------------------------------- 1 | ### 基本使用 2 | 3 | ### proto库 4 | 5 | #### protobuf 它能够将 一个对象 编码成二进制,作为传输的中间文件 ,并能够将中间文件解析回原数据创建.proto文件 ,定义好相应的数据类型 6 | 7 | 编写 xxx.proto文件 8 | 9 | protoc test.proto --cpp_out="./" // 生成相应的代码,包含数据类型的编码 10 | 11 | // main.cpp 为调用proto的代码, 链接动态库进行编译 12 | 13 | g++ test.pb.cc main.cpp -o test `pkg-config --cflags --libs protobuf` -lpthread 14 | 15 | #### 文件头 16 | 17 | test.proto 18 | 19 | ``` 20 | // 指明版本及包名 21 | syntax="proto3";// 声明proto版本 22 | 23 | package fixbug;// 声明代码所在的包(对c++来说就是namespace) 24 | 25 | ``` 26 | 27 | #### 基本对象的定义 28 | 29 | test.proto 30 | 31 | string 定义成byte会更好 32 | 33 | ``` 34 | 35 | // 定义登陆请求消息类型 36 | message LoginRequest 37 | { 38 | string name=1; // 表明第一个字段 39 | string pwd=2; // 定义第二个字段 40 | } 41 | // 定义登陆响应消息类型 42 | message LoginResponse 43 | { 44 | int32 errcode=1; 45 | string errmsg=2; 46 | bool success=3; 47 | } 48 | ``` 49 | 50 | #### 基本对象的初始化与赋值 51 | 52 | main.cpp 53 | 54 | ``` 55 | LoginRequest req; 56 | req.set_name("zhang san"); 57 | req.set_pwd("123456"); 58 | ``` 59 | 60 | #### 基本对象的编码与解码 61 | 62 | ``` 63 | 64 | // 编码 65 | string send_str; 66 | if(req.SerializeToString(&send_str)) 67 | { 68 | cout<set_errcode(1); 108 | rc->set_errmsg("登陆处理失败"); 109 | ``` 110 | 111 | #### 列表定义 112 | 113 | ``` 114 | message User 115 | { 116 | bytes name; 117 | uint32 age=2; 118 | enum Sex 119 | { 120 | MAN=0; 121 | WOMAN=1; 122 | } 123 | Sex sex=3; 124 | } 125 | message GetFriendListsResponse 126 | { 127 | ResultCode result=1; 128 | repeated User users=2; 129 | } 130 | ``` 131 | 132 | #### 列表的初始化 133 | 134 | test.proto 135 | 136 | ``` 137 | GetFriendListsResponse rlist; 138 | ResultCode* rc2=rlist.mutable_result(); 139 | rc2->set_errcode(0); 140 | 141 | User *user1=rlist.add_friend_lists(); 142 | user1->set_name("zhang san"); 143 | user1->set_age(20); 144 | user1->set_sex(User::MAN); 145 | 146 | User *user2=rlist.add_friend_lists(); 147 | user2->set_name("zhang san"); 148 | user2->set_age(20); 149 | user2->set_sex(User::MAN); 150 | ``` 151 | 152 | #### 遍历列表 153 | 154 | main.cpp 155 | 156 | ``` 157 | cout< stub -> 网络 -> stub -> 服务器执行函数 236 | 237 | 无默认构造函数,需要传入channel 238 | 239 | ``` 240 | class UserServiceRpc_Stub : public UserServiceRpc { 241 | public: 242 | UserServiceRpc_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel); 243 | UserServiceRpc_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, 244 | ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership); 245 | ~UserServiceRpc_Stub(); 246 | 247 | inline ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel() { return channel_; } 248 | 249 | // implements UserServiceRpc ------------------------------------------ 250 | 251 | void Login(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 252 | const ::fixbug::LoginRequest* request, 253 | ::fixbug::LoginResponse* response, 254 | ::google::protobuf::Closure* done); 255 | void GetFriendLists(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 256 | const ::fixbug::GetFriendListsRequest* request, 257 | ::fixbug::GetFriendListsResponse* response, 258 | ::google::protobuf::Closure* done); 259 | private: 260 | ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel_; 261 | bool owns_channel_; 262 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UserServiceRpc_Stub); 263 | }; 264 | ``` 265 | 266 | 去看该方法实现的时候 会发现 267 | 268 | ``` 269 | void UserServiceRpc_Stub::Login(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 270 | const ::fixbug::LoginRequest* request, 271 | ::fixbug::LoginResponse* response, 272 | ::google::protobuf::Closure* done) { 273 | channel_->CallMethod(descriptor()->method(0), 274 | controller, request, response, done); 275 | } 276 | void UserServiceRpc_Stub::GetFriendLists(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 277 | const ::fixbug::GetFriendListsRequest* request, 278 | ::fixbug::GetFriendListsResponse* response, 279 | ::google::protobuf::Closure* done) { 280 | channel_->CallMethod(descriptor()->method(1), 281 | controller, request, response, done); 282 | } 283 | ``` 284 | 285 | 调用函数的时候 , 会自动 调用 channel_->CalllMethod() 286 | 287 | 我们去看下 channel 是什么类 288 | 289 | ``` 290 | class PROTOBUF_EXPORT RpcChannel { 291 | public: 292 | inline RpcChannel() {} 293 | virtual ~RpcChannel(); 294 | 295 | // Call the given method of the remote service. The signature of this 296 | // procedure looks the same as Service::CallMethod(), but the requirements 297 | // are less strict in one important way: the request and response objects 298 | // need not be of any specific class as long as their descriptors are 299 | // method->input_type() and method->output_type(). 300 | virtual void CallMethod(const MethodDescriptor* method, 301 | RpcController* controller, const Message* request, 302 | Message* response, Closure* done) = 0; 303 | 304 | private: 305 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel); 306 | }; 307 | ``` 308 | 309 | 会发现 channel 是一个抽象类 我们必须 继承实现该类 310 | 311 | 在方法中实现对象的序列化 及网络传输等等 312 | 313 | method 为方法 314 | 315 | controller 316 | 317 | request 参数对象 318 | 319 | response 响应对象 320 | 321 | ``` 322 | class mychannel:public RpcChannel 323 | { 324 | void callmeMethod(const MethodDescriptor* method, 325 | RpcController* controller, const Message* request, 326 | Message* response, Closure* done) 327 | { 328 | 329 | 330 | 331 | } 332 | } 333 | ``` 334 | 335 | protobuf 它能够将 一个对象 编码成二进制,作为传输的中间文件 ,并能够将中间文件解析回原数据创建.proto文件 ,定义好相应的数据类型 336 | 337 | 得到 xxx.proto文件 338 | 339 | protoc test.proto --cpp_out="./" // 生成相应的代码,包含数据类型的编码 340 | 341 | // main.cpp 为调用proto的代码, 链接动态库进行编译 342 | 343 | g++ test.pb.cc main.cpp -o test `pkg-config --cflags --libs protobuf` -lpthread 344 | 345 | #### 文件头 346 | 347 | test.proto 348 | 349 | ``` 350 | // 指明版本及包名 351 | syntax="proto3";// 声明proto版本 352 | 353 | package fixbug;// 声明代码所在的包(对c++来说就是namespace) 354 | 355 | ``` 356 | 357 | #### 基本对象的定义 358 | 359 | test.proto 360 | 361 | string 定义成byte会更好 362 | 363 | ``` 364 | 365 | // 定义登陆请求消息类型 366 | message LoginRequest 367 | { 368 | string name=1; // 表明第一个字段 369 | string pwd=2; // 定义第二个字段 370 | } 371 | // 定义登陆响应消息类型 372 | message LoginResponse 373 | { 374 | int32 errcode=1; 375 | string errmsg=2; 376 | bool success=3; 377 | } 378 | ``` 379 | 380 | #### 基本对象的初始化与赋值 381 | 382 | main.cpp 383 | 384 | ``` 385 | LoginRequest req; 386 | req.set_name("zhang san"); 387 | req.set_pwd("123456"); 388 | ``` 389 | 390 | #### 基本对象的编码与解码 391 | 392 | ``` 393 | 394 | // 编码 395 | string send_str; 396 | if(req.SerializeToString(&send_str)) 397 | { 398 | cout<set_errcode(1); 438 | rc->set_errmsg("登陆处理失败"); 439 | ``` 440 | 441 | #### 列表定义 442 | 443 | ``` 444 | message User 445 | { 446 | bytes name; 447 | uint32 age=2; 448 | enum Sex 449 | { 450 | MAN=0; 451 | WOMAN=1; 452 | } 453 | Sex sex=3; 454 | } 455 | message GetFriendListsResponse 456 | { 457 | ResultCode result=1; 458 | repeated User users=2; 459 | } 460 | ``` 461 | 462 | #### 列表的初始化 463 | 464 | test.proto 465 | 466 | ``` 467 | GetFriendListsResponse rlist; 468 | ResultCode* rc2=rlist.mutable_result(); 469 | rc2->set_errcode(0); 470 | 471 | User *user1=rlist.add_friend_lists(); 472 | user1->set_name("zhang san"); 473 | user1->set_age(20); 474 | user1->set_sex(User::MAN); 475 | 476 | User *user2=rlist.add_friend_lists(); 477 | user2->set_name("zhang san"); 478 | user2->set_age(20); 479 | user2->set_sex(User::MAN); 480 | ``` 481 | 482 | #### 遍历列表 483 | 484 | main.cpp 485 | 486 | ``` 487 | cout< 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | // @@protoc_insertion_point(includes) 16 | #include 17 | namespace src { 18 | class RpcHeaderDefaultTypeInternal { 19 | public: 20 | ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; 21 | } _RpcHeader_default_instance_; 22 | } // namespace src 23 | static void InitDefaultsscc_info_RpcHeader_rpc_5fheader_2eproto() { 24 | GOOGLE_PROTOBUF_VERIFY_VERSION; 25 | 26 | { 27 | void* ptr = &::src::_RpcHeader_default_instance_; 28 | new (ptr) ::src::RpcHeader(); 29 | ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); 30 | } 31 | ::src::RpcHeader::InitAsDefaultInstance(); 32 | } 33 | 34 | ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_RpcHeader_rpc_5fheader_2eproto = 35 | {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_RpcHeader_rpc_5fheader_2eproto}, {}}; 36 | 37 | static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_rpc_5fheader_2eproto[1]; 38 | static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_rpc_5fheader_2eproto = nullptr; 39 | static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_rpc_5fheader_2eproto = nullptr; 40 | 41 | const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_rpc_5fheader_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { 42 | ~0u, // no _has_bits_ 43 | PROTOBUF_FIELD_OFFSET(::src::RpcHeader, _internal_metadata_), 44 | ~0u, // no _extensions_ 45 | ~0u, // no _oneof_case_ 46 | ~0u, // no _weak_field_map_ 47 | PROTOBUF_FIELD_OFFSET(::src::RpcHeader, service_name_), 48 | PROTOBUF_FIELD_OFFSET(::src::RpcHeader, method_name_), 49 | PROTOBUF_FIELD_OFFSET(::src::RpcHeader, args_len_), 50 | }; 51 | static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { 52 | { 0, -1, sizeof(::src::RpcHeader)}, 53 | }; 54 | 55 | static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = { 56 | reinterpret_cast(&::src::_RpcHeader_default_instance_), 57 | }; 58 | 59 | const char descriptor_table_protodef_rpc_5fheader_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = 60 | "\n\020rpc_header.proto\022\003src\"H\n\tRpcHeader\022\024\n\014" 61 | "service_name\030\001 \001(\t\022\023\n\013method_name\030\002 \001(\t\022" 62 | "\020\n\010args_len\030\003 \001(\rb\006proto3" 63 | ; 64 | static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_rpc_5fheader_2eproto_deps[1] = { 65 | }; 66 | static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_rpc_5fheader_2eproto_sccs[1] = { 67 | &scc_info_RpcHeader_rpc_5fheader_2eproto.base, 68 | }; 69 | static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_rpc_5fheader_2eproto_once; 70 | static bool descriptor_table_rpc_5fheader_2eproto_initialized = false; 71 | const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_rpc_5fheader_2eproto = { 72 | &descriptor_table_rpc_5fheader_2eproto_initialized, descriptor_table_protodef_rpc_5fheader_2eproto, "rpc_header.proto", 105, 73 | &descriptor_table_rpc_5fheader_2eproto_once, descriptor_table_rpc_5fheader_2eproto_sccs, descriptor_table_rpc_5fheader_2eproto_deps, 1, 0, 74 | schemas, file_default_instances, TableStruct_rpc_5fheader_2eproto::offsets, 75 | file_level_metadata_rpc_5fheader_2eproto, 1, file_level_enum_descriptors_rpc_5fheader_2eproto, file_level_service_descriptors_rpc_5fheader_2eproto, 76 | }; 77 | 78 | // Force running AddDescriptors() at dynamic initialization time. 79 | static bool dynamic_init_dummy_rpc_5fheader_2eproto = ( ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_rpc_5fheader_2eproto), true); 80 | namespace src { 81 | 82 | // =================================================================== 83 | 84 | void RpcHeader::InitAsDefaultInstance() { 85 | } 86 | class RpcHeader::_Internal { 87 | public: 88 | }; 89 | 90 | RpcHeader::RpcHeader() 91 | : ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) { 92 | SharedCtor(); 93 | // @@protoc_insertion_point(constructor:src.RpcHeader) 94 | } 95 | RpcHeader::RpcHeader(const RpcHeader& from) 96 | : ::PROTOBUF_NAMESPACE_ID::Message(), 97 | _internal_metadata_(nullptr) { 98 | _internal_metadata_.MergeFrom(from._internal_metadata_); 99 | service_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 100 | if (!from._internal_service_name().empty()) { 101 | service_name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.service_name_); 102 | } 103 | method_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 104 | if (!from._internal_method_name().empty()) { 105 | method_name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.method_name_); 106 | } 107 | args_len_ = from.args_len_; 108 | // @@protoc_insertion_point(copy_constructor:src.RpcHeader) 109 | } 110 | 111 | void RpcHeader::SharedCtor() { 112 | ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_RpcHeader_rpc_5fheader_2eproto.base); 113 | service_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 114 | method_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 115 | args_len_ = 0u; 116 | } 117 | 118 | RpcHeader::~RpcHeader() { 119 | // @@protoc_insertion_point(destructor:src.RpcHeader) 120 | SharedDtor(); 121 | } 122 | 123 | void RpcHeader::SharedDtor() { 124 | service_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 125 | method_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 126 | } 127 | 128 | void RpcHeader::SetCachedSize(int size) const { 129 | _cached_size_.Set(size); 130 | } 131 | const RpcHeader& RpcHeader::default_instance() { 132 | ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_RpcHeader_rpc_5fheader_2eproto.base); 133 | return *internal_default_instance(); 134 | } 135 | 136 | 137 | void RpcHeader::Clear() { 138 | // @@protoc_insertion_point(message_clear_start:src.RpcHeader) 139 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 140 | // Prevent compiler warnings about cached_has_bits being unused 141 | (void) cached_has_bits; 142 | 143 | service_name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 144 | method_name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 145 | args_len_ = 0u; 146 | _internal_metadata_.Clear(); 147 | } 148 | 149 | const char* RpcHeader::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { 150 | #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure 151 | while (!ctx->Done(&ptr)) { 152 | ::PROTOBUF_NAMESPACE_ID::uint32 tag; 153 | ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); 154 | CHK_(ptr); 155 | switch (tag >> 3) { 156 | // string service_name = 1; 157 | case 1: 158 | if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { 159 | auto str = _internal_mutable_service_name(); 160 | ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); 161 | CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "src.RpcHeader.service_name")); 162 | CHK_(ptr); 163 | } else goto handle_unusual; 164 | continue; 165 | // string method_name = 2; 166 | case 2: 167 | if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { 168 | auto str = _internal_mutable_method_name(); 169 | ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); 170 | CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "src.RpcHeader.method_name")); 171 | CHK_(ptr); 172 | } else goto handle_unusual; 173 | continue; 174 | // uint32 args_len = 3; 175 | case 3: 176 | if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 24)) { 177 | args_len_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); 178 | CHK_(ptr); 179 | } else goto handle_unusual; 180 | continue; 181 | default: { 182 | handle_unusual: 183 | if ((tag & 7) == 4 || tag == 0) { 184 | ctx->SetLastTag(tag); 185 | goto success; 186 | } 187 | ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx); 188 | CHK_(ptr != nullptr); 189 | continue; 190 | } 191 | } // switch 192 | } // while 193 | success: 194 | return ptr; 195 | failure: 196 | ptr = nullptr; 197 | goto success; 198 | #undef CHK_ 199 | } 200 | 201 | ::PROTOBUF_NAMESPACE_ID::uint8* RpcHeader::_InternalSerialize( 202 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { 203 | // @@protoc_insertion_point(serialize_to_array_start:src.RpcHeader) 204 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 205 | (void) cached_has_bits; 206 | 207 | // string service_name = 1; 208 | if (this->service_name().size() > 0) { 209 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( 210 | this->_internal_service_name().data(), static_cast(this->_internal_service_name().length()), 211 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, 212 | "src.RpcHeader.service_name"); 213 | target = stream->WriteStringMaybeAliased( 214 | 1, this->_internal_service_name(), target); 215 | } 216 | 217 | // string method_name = 2; 218 | if (this->method_name().size() > 0) { 219 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( 220 | this->_internal_method_name().data(), static_cast(this->_internal_method_name().length()), 221 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, 222 | "src.RpcHeader.method_name"); 223 | target = stream->WriteStringMaybeAliased( 224 | 2, this->_internal_method_name(), target); 225 | } 226 | 227 | // uint32 args_len = 3; 228 | if (this->args_len() != 0) { 229 | target = stream->EnsureSpace(target); 230 | target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(3, this->_internal_args_len(), target); 231 | } 232 | 233 | if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { 234 | target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( 235 | _internal_metadata_.unknown_fields(), target, stream); 236 | } 237 | // @@protoc_insertion_point(serialize_to_array_end:src.RpcHeader) 238 | return target; 239 | } 240 | 241 | size_t RpcHeader::ByteSizeLong() const { 242 | // @@protoc_insertion_point(message_byte_size_start:src.RpcHeader) 243 | size_t total_size = 0; 244 | 245 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 246 | // Prevent compiler warnings about cached_has_bits being unused 247 | (void) cached_has_bits; 248 | 249 | // string service_name = 1; 250 | if (this->service_name().size() > 0) { 251 | total_size += 1 + 252 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( 253 | this->_internal_service_name()); 254 | } 255 | 256 | // string method_name = 2; 257 | if (this->method_name().size() > 0) { 258 | total_size += 1 + 259 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( 260 | this->_internal_method_name()); 261 | } 262 | 263 | // uint32 args_len = 3; 264 | if (this->args_len() != 0) { 265 | total_size += 1 + 266 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( 267 | this->_internal_args_len()); 268 | } 269 | 270 | if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { 271 | return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( 272 | _internal_metadata_, total_size, &_cached_size_); 273 | } 274 | int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); 275 | SetCachedSize(cached_size); 276 | return total_size; 277 | } 278 | 279 | void RpcHeader::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { 280 | // @@protoc_insertion_point(generalized_merge_from_start:src.RpcHeader) 281 | GOOGLE_DCHECK_NE(&from, this); 282 | const RpcHeader* source = 283 | ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( 284 | &from); 285 | if (source == nullptr) { 286 | // @@protoc_insertion_point(generalized_merge_from_cast_fail:src.RpcHeader) 287 | ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); 288 | } else { 289 | // @@protoc_insertion_point(generalized_merge_from_cast_success:src.RpcHeader) 290 | MergeFrom(*source); 291 | } 292 | } 293 | 294 | void RpcHeader::MergeFrom(const RpcHeader& from) { 295 | // @@protoc_insertion_point(class_specific_merge_from_start:src.RpcHeader) 296 | GOOGLE_DCHECK_NE(&from, this); 297 | _internal_metadata_.MergeFrom(from._internal_metadata_); 298 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 299 | (void) cached_has_bits; 300 | 301 | if (from.service_name().size() > 0) { 302 | 303 | service_name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.service_name_); 304 | } 305 | if (from.method_name().size() > 0) { 306 | 307 | method_name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.method_name_); 308 | } 309 | if (from.args_len() != 0) { 310 | _internal_set_args_len(from._internal_args_len()); 311 | } 312 | } 313 | 314 | void RpcHeader::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { 315 | // @@protoc_insertion_point(generalized_copy_from_start:src.RpcHeader) 316 | if (&from == this) return; 317 | Clear(); 318 | MergeFrom(from); 319 | } 320 | 321 | void RpcHeader::CopyFrom(const RpcHeader& from) { 322 | // @@protoc_insertion_point(class_specific_copy_from_start:src.RpcHeader) 323 | if (&from == this) return; 324 | Clear(); 325 | MergeFrom(from); 326 | } 327 | 328 | bool RpcHeader::IsInitialized() const { 329 | return true; 330 | } 331 | 332 | void RpcHeader::InternalSwap(RpcHeader* other) { 333 | using std::swap; 334 | _internal_metadata_.Swap(&other->_internal_metadata_); 335 | service_name_.Swap(&other->service_name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 336 | GetArenaNoVirtual()); 337 | method_name_.Swap(&other->method_name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 338 | GetArenaNoVirtual()); 339 | swap(args_len_, other->args_len_); 340 | } 341 | 342 | ::PROTOBUF_NAMESPACE_ID::Metadata RpcHeader::GetMetadata() const { 343 | return GetMetadataStatic(); 344 | } 345 | 346 | 347 | // @@protoc_insertion_point(namespace_scope) 348 | } // namespace src 349 | PROTOBUF_NAMESPACE_OPEN 350 | template<> PROTOBUF_NOINLINE ::src::RpcHeader* Arena::CreateMaybeMessage< ::src::RpcHeader >(Arena* arena) { 351 | return Arena::CreateInternal< ::src::RpcHeader >(arena); 352 | } 353 | PROTOBUF_NAMESPACE_CLOSE 354 | 355 | // @@protoc_insertion_point(global_scope) 356 | #include 357 | -------------------------------------------------------------------------------- /src/include/rpc_header.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: rpc_header.proto 3 | 4 | #ifndef GOOGLE_PROTOBUF_INCLUDED_rpc_5fheader_2eproto 5 | #define GOOGLE_PROTOBUF_INCLUDED_rpc_5fheader_2eproto 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #if PROTOBUF_VERSION < 3011000 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3011000 < PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include // IWYU pragma: export 33 | #include // IWYU pragma: export 34 | #include 35 | // @@protoc_insertion_point(includes) 36 | #include 37 | #define PROTOBUF_INTERNAL_EXPORT_rpc_5fheader_2eproto 38 | PROTOBUF_NAMESPACE_OPEN 39 | namespace internal { 40 | class AnyMetadata; 41 | } // namespace internal 42 | PROTOBUF_NAMESPACE_CLOSE 43 | 44 | // Internal implementation detail -- do not use these members. 45 | struct TableStruct_rpc_5fheader_2eproto { 46 | static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] 47 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 48 | static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[] 49 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 50 | static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1] 51 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 52 | static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; 53 | static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; 54 | static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[]; 55 | }; 56 | extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_rpc_5fheader_2eproto; 57 | namespace src { 58 | class RpcHeader; 59 | class RpcHeaderDefaultTypeInternal; 60 | extern RpcHeaderDefaultTypeInternal _RpcHeader_default_instance_; 61 | } // namespace src 62 | PROTOBUF_NAMESPACE_OPEN 63 | template<> ::src::RpcHeader* Arena::CreateMaybeMessage<::src::RpcHeader>(Arena*); 64 | PROTOBUF_NAMESPACE_CLOSE 65 | namespace src { 66 | 67 | // =================================================================== 68 | 69 | class RpcHeader : 70 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:src.RpcHeader) */ { 71 | public: 72 | RpcHeader(); 73 | virtual ~RpcHeader(); 74 | 75 | RpcHeader(const RpcHeader& from); 76 | RpcHeader(RpcHeader&& from) noexcept 77 | : RpcHeader() { 78 | *this = ::std::move(from); 79 | } 80 | 81 | inline RpcHeader& operator=(const RpcHeader& from) { 82 | CopyFrom(from); 83 | return *this; 84 | } 85 | inline RpcHeader& operator=(RpcHeader&& from) noexcept { 86 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 87 | if (this != &from) InternalSwap(&from); 88 | } else { 89 | CopyFrom(from); 90 | } 91 | return *this; 92 | } 93 | 94 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 95 | return GetDescriptor(); 96 | } 97 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 98 | return GetMetadataStatic().descriptor; 99 | } 100 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 101 | return GetMetadataStatic().reflection; 102 | } 103 | static const RpcHeader& default_instance(); 104 | 105 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 106 | static inline const RpcHeader* internal_default_instance() { 107 | return reinterpret_cast( 108 | &_RpcHeader_default_instance_); 109 | } 110 | static constexpr int kIndexInFileMessages = 111 | 0; 112 | 113 | friend void swap(RpcHeader& a, RpcHeader& b) { 114 | a.Swap(&b); 115 | } 116 | inline void Swap(RpcHeader* other) { 117 | if (other == this) return; 118 | InternalSwap(other); 119 | } 120 | 121 | // implements Message ---------------------------------------------- 122 | 123 | inline RpcHeader* New() const final { 124 | return CreateMaybeMessage(nullptr); 125 | } 126 | 127 | RpcHeader* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 128 | return CreateMaybeMessage(arena); 129 | } 130 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 131 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 132 | void CopyFrom(const RpcHeader& from); 133 | void MergeFrom(const RpcHeader& from); 134 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 135 | bool IsInitialized() const final; 136 | 137 | size_t ByteSizeLong() const final; 138 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 139 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 140 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 141 | int GetCachedSize() const final { return _cached_size_.Get(); } 142 | 143 | private: 144 | inline void SharedCtor(); 145 | inline void SharedDtor(); 146 | void SetCachedSize(int size) const final; 147 | void InternalSwap(RpcHeader* other); 148 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 149 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 150 | return "src.RpcHeader"; 151 | } 152 | private: 153 | inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { 154 | return nullptr; 155 | } 156 | inline void* MaybeArenaPtr() const { 157 | return nullptr; 158 | } 159 | public: 160 | 161 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 162 | private: 163 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 164 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_rpc_5fheader_2eproto); 165 | return ::descriptor_table_rpc_5fheader_2eproto.file_level_metadata[kIndexInFileMessages]; 166 | } 167 | 168 | public: 169 | 170 | // nested types ---------------------------------------------------- 171 | 172 | // accessors ------------------------------------------------------- 173 | 174 | enum : int { 175 | kServiceNameFieldNumber = 1, 176 | kMethodNameFieldNumber = 2, 177 | kArgsLenFieldNumber = 3, 178 | }; 179 | // string service_name = 1; 180 | void clear_service_name(); 181 | const std::string& service_name() const; 182 | void set_service_name(const std::string& value); 183 | void set_service_name(std::string&& value); 184 | void set_service_name(const char* value); 185 | void set_service_name(const char* value, size_t size); 186 | std::string* mutable_service_name(); 187 | std::string* release_service_name(); 188 | void set_allocated_service_name(std::string* service_name); 189 | private: 190 | const std::string& _internal_service_name() const; 191 | void _internal_set_service_name(const std::string& value); 192 | std::string* _internal_mutable_service_name(); 193 | public: 194 | 195 | // string method_name = 2; 196 | void clear_method_name(); 197 | const std::string& method_name() const; 198 | void set_method_name(const std::string& value); 199 | void set_method_name(std::string&& value); 200 | void set_method_name(const char* value); 201 | void set_method_name(const char* value, size_t size); 202 | std::string* mutable_method_name(); 203 | std::string* release_method_name(); 204 | void set_allocated_method_name(std::string* method_name); 205 | private: 206 | const std::string& _internal_method_name() const; 207 | void _internal_set_method_name(const std::string& value); 208 | std::string* _internal_mutable_method_name(); 209 | public: 210 | 211 | // uint32 args_len = 3; 212 | void clear_args_len(); 213 | ::PROTOBUF_NAMESPACE_ID::uint32 args_len() const; 214 | void set_args_len(::PROTOBUF_NAMESPACE_ID::uint32 value); 215 | private: 216 | ::PROTOBUF_NAMESPACE_ID::uint32 _internal_args_len() const; 217 | void _internal_set_args_len(::PROTOBUF_NAMESPACE_ID::uint32 value); 218 | public: 219 | 220 | // @@protoc_insertion_point(class_scope:src.RpcHeader) 221 | private: 222 | class _Internal; 223 | 224 | ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; 225 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr service_name_; 226 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr method_name_; 227 | ::PROTOBUF_NAMESPACE_ID::uint32 args_len_; 228 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 229 | friend struct ::TableStruct_rpc_5fheader_2eproto; 230 | }; 231 | // =================================================================== 232 | 233 | 234 | // =================================================================== 235 | 236 | #ifdef __GNUC__ 237 | #pragma GCC diagnostic push 238 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 239 | #endif // __GNUC__ 240 | // RpcHeader 241 | 242 | // string service_name = 1; 243 | inline void RpcHeader::clear_service_name() { 244 | service_name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 245 | } 246 | inline const std::string& RpcHeader::service_name() const { 247 | // @@protoc_insertion_point(field_get:src.RpcHeader.service_name) 248 | return _internal_service_name(); 249 | } 250 | inline void RpcHeader::set_service_name(const std::string& value) { 251 | _internal_set_service_name(value); 252 | // @@protoc_insertion_point(field_set:src.RpcHeader.service_name) 253 | } 254 | inline std::string* RpcHeader::mutable_service_name() { 255 | // @@protoc_insertion_point(field_mutable:src.RpcHeader.service_name) 256 | return _internal_mutable_service_name(); 257 | } 258 | inline const std::string& RpcHeader::_internal_service_name() const { 259 | return service_name_.GetNoArena(); 260 | } 261 | inline void RpcHeader::_internal_set_service_name(const std::string& value) { 262 | 263 | service_name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 264 | } 265 | inline void RpcHeader::set_service_name(std::string&& value) { 266 | 267 | service_name_.SetNoArena( 268 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 269 | // @@protoc_insertion_point(field_set_rvalue:src.RpcHeader.service_name) 270 | } 271 | inline void RpcHeader::set_service_name(const char* value) { 272 | GOOGLE_DCHECK(value != nullptr); 273 | 274 | service_name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 275 | // @@protoc_insertion_point(field_set_char:src.RpcHeader.service_name) 276 | } 277 | inline void RpcHeader::set_service_name(const char* value, size_t size) { 278 | 279 | service_name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 280 | ::std::string(reinterpret_cast(value), size)); 281 | // @@protoc_insertion_point(field_set_pointer:src.RpcHeader.service_name) 282 | } 283 | inline std::string* RpcHeader::_internal_mutable_service_name() { 284 | 285 | return service_name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 286 | } 287 | inline std::string* RpcHeader::release_service_name() { 288 | // @@protoc_insertion_point(field_release:src.RpcHeader.service_name) 289 | 290 | return service_name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 291 | } 292 | inline void RpcHeader::set_allocated_service_name(std::string* service_name) { 293 | if (service_name != nullptr) { 294 | 295 | } else { 296 | 297 | } 298 | service_name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), service_name); 299 | // @@protoc_insertion_point(field_set_allocated:src.RpcHeader.service_name) 300 | } 301 | 302 | // string method_name = 2; 303 | inline void RpcHeader::clear_method_name() { 304 | method_name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 305 | } 306 | inline const std::string& RpcHeader::method_name() const { 307 | // @@protoc_insertion_point(field_get:src.RpcHeader.method_name) 308 | return _internal_method_name(); 309 | } 310 | inline void RpcHeader::set_method_name(const std::string& value) { 311 | _internal_set_method_name(value); 312 | // @@protoc_insertion_point(field_set:src.RpcHeader.method_name) 313 | } 314 | inline std::string* RpcHeader::mutable_method_name() { 315 | // @@protoc_insertion_point(field_mutable:src.RpcHeader.method_name) 316 | return _internal_mutable_method_name(); 317 | } 318 | inline const std::string& RpcHeader::_internal_method_name() const { 319 | return method_name_.GetNoArena(); 320 | } 321 | inline void RpcHeader::_internal_set_method_name(const std::string& value) { 322 | 323 | method_name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 324 | } 325 | inline void RpcHeader::set_method_name(std::string&& value) { 326 | 327 | method_name_.SetNoArena( 328 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 329 | // @@protoc_insertion_point(field_set_rvalue:src.RpcHeader.method_name) 330 | } 331 | inline void RpcHeader::set_method_name(const char* value) { 332 | GOOGLE_DCHECK(value != nullptr); 333 | 334 | method_name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 335 | // @@protoc_insertion_point(field_set_char:src.RpcHeader.method_name) 336 | } 337 | inline void RpcHeader::set_method_name(const char* value, size_t size) { 338 | 339 | method_name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 340 | ::std::string(reinterpret_cast(value), size)); 341 | // @@protoc_insertion_point(field_set_pointer:src.RpcHeader.method_name) 342 | } 343 | inline std::string* RpcHeader::_internal_mutable_method_name() { 344 | 345 | return method_name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 346 | } 347 | inline std::string* RpcHeader::release_method_name() { 348 | // @@protoc_insertion_point(field_release:src.RpcHeader.method_name) 349 | 350 | return method_name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 351 | } 352 | inline void RpcHeader::set_allocated_method_name(std::string* method_name) { 353 | if (method_name != nullptr) { 354 | 355 | } else { 356 | 357 | } 358 | method_name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), method_name); 359 | // @@protoc_insertion_point(field_set_allocated:src.RpcHeader.method_name) 360 | } 361 | 362 | // uint32 args_len = 3; 363 | inline void RpcHeader::clear_args_len() { 364 | args_len_ = 0u; 365 | } 366 | inline ::PROTOBUF_NAMESPACE_ID::uint32 RpcHeader::_internal_args_len() const { 367 | return args_len_; 368 | } 369 | inline ::PROTOBUF_NAMESPACE_ID::uint32 RpcHeader::args_len() const { 370 | // @@protoc_insertion_point(field_get:src.RpcHeader.args_len) 371 | return _internal_args_len(); 372 | } 373 | inline void RpcHeader::_internal_set_args_len(::PROTOBUF_NAMESPACE_ID::uint32 value) { 374 | 375 | args_len_ = value; 376 | } 377 | inline void RpcHeader::set_args_len(::PROTOBUF_NAMESPACE_ID::uint32 value) { 378 | _internal_set_args_len(value); 379 | // @@protoc_insertion_point(field_set:src.RpcHeader.args_len) 380 | } 381 | 382 | #ifdef __GNUC__ 383 | #pragma GCC diagnostic pop 384 | #endif // __GNUC__ 385 | 386 | // @@protoc_insertion_point(namespace_scope) 387 | 388 | } // namespace src 389 | 390 | // @@protoc_insertion_point(global_scope) 391 | 392 | #include 393 | #endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_rpc_5fheader_2eproto 394 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # 一文讲解 基于C++手写Rpc项目 2 | 3 | [toc] 4 | 5 | # github 6 | 7 | > 请一定结合代码看博客 8 | 9 | https://github.com/stolendance/mrpc 10 | 11 | # 预备知识 12 | 13 | ## 集群和分布式 14 | 15 | > 我的理解: 系统部署到一台单机上,会存在问题:硬件不够, 并发满足不了, 还容易挂 16 | > 17 | > 所以扩展成集群, 集群每个服务器上都部署一套完整的系统, 硬件够了,也不容易挂了 18 | > 19 | > 但该方式较为浪费,有些模块不需要部署多台上, 太费资源了, 所以分布式 , 把系统拆分成模块 放到每台服务器上 需要高并发的模块就多放几台 容易挂的也多放几台 资源需求就蛮少 当然这样系统的复杂性大幅度提高 20 | 21 | 集群:每一台服务器独立运行一个工程的所有模块 22 | 23 | 分布式:一个工程拆分了很多模块,每一个模块独立部署运行在一个服务器主机上,所有服务器协同工作共同提供服务,每一台服务器称作分布式的一个节点,根据节点的并发要求,对一个节点可以再做节点模块集群部署 24 | 25 | ### 单机聊天服务器 26 | 27 | image-20230504110022486 28 | 29 | 1. 受限于硬件资源,聊天服务器所能承受的用户的并发量 30 | 2. 硬件挂了即整个系统将崩溃 31 | 3. 一个bug 整个代码全部重新编译 32 | 4. 系统中,有些模块属于cpu密集型的,有些模块属于io密集型的,造成各个对于硬件需求是不一样的 33 | 34 | ### 集群聊天服务器 35 | 36 | ![image-20230504110054259](image/readme/image-20230504110054259.png) 37 | 38 | 只解决了硬件资源, 挂了就完了这俩问题 39 | 40 | 代码需要费大力重新部署,每个模块对硬件的需求是不同的(只是水平扩展硬件) 这俩都没解决 41 | 42 | 比如后台管理模块这个模块,根本不需要高并发,没必要放到每个服务器上 43 | 44 | > 访问需要通过负载均衡模块, 将需求分配到服务器上 45 | 46 | ### 分布式聊天服务器 47 | 48 | 把系统拆分成模块 放到每台服务器上 需要高并发的模块就多放几台 容易挂的也多放几台 资源需求就蛮少 49 | 50 | ![image-20230504110857220](image/readme/image-20230504110857220.png) 51 | 52 | 比如消息管理 可以放置到 多个服务器上 53 | 54 | 硬件资源 解决 55 | 56 | 挂了 解决。 挂了 多放几台呗 57 | 58 | bug重新部署 解决 59 | 60 | io cpu需要不同 解决 61 | 62 | 根据分布式节点并发需求可以再扩展 63 | 64 | ### 从集群式 到 分布式聊天服务器 看来只有好处 ,但代价是什么? 65 | 66 | ==系统复杂性大大增加== , 或者说对基础架构要求很高 67 | 68 | 1. 大系统的软件模块该怎么划分 69 | 70 | 各模块可能会实现大量重复的代码,需要架构的比较好 71 | 2. 各个模块之间该怎么访问? 72 | 73 | 各个模块都运行在不同的进程里. 74 | 75 | docker虚拟化环境中 76 | 77 | ![image-20230504142329365](image/readme/image-20230504142329365.png) 78 | 79 | ## rpc 的 通信原理 remote procedure call 分布式通信 80 | 81 | 机器a如何 调用 机器 b 的函数 82 | 83 | ![image-20230504144250652](image/readme//image-20230504144250652.png) 84 | 85 | 一个函数 发现是rpc函数 ,服务配置中心查到这个服务在哪个机器上 , 把函数名与参数序列化发送给该机器 , 机器反序列化 执行该函数。把结果序列化 传给 原机器。 原机器序列化 得到结果 86 | 87 | ## 手写的rpc部分 88 | 89 | ![image-20230504144658261](image/readme/image-20230504144658261.png) 90 | 91 | 黄色部分:protobuf 序列化 92 | 93 | 绿色部分:zookeeper服务器配置中心 muduo网络库 94 | 95 | ## protobuf>=json 好处? 96 | 97 | 1. protobuf是二进制存储的;xml和json都是文本存储的 98 | 2. protobuf不需要存储额外的信息,json是怎么存储数据的呢 json是keyvalue 需要key 99 | 100 | protocol buffer 是google的一种数据交换的格式, 它独立于平台语言 101 | 102 | 它是一种二进制的格式,比使用xml(20倍) json(10倍) 进行数据交换快许多, 可以把它分布式应用之间的数据通信或者异构环境下的数据交换 作为一种效率和兼容性都很优秀的二进制数据传输格式,可以用于网络传输,配置文件,数据存储等领域 103 | 104 | # 介绍protobuf 105 | 106 | protocol Buffers are language-neutral, platform-neutral extensible mechanism for seializing structured data 107 | 108 | Protobuf 这是一种序列化数据的协议 从我理解, 这更是一种 通信协议 ,定义了如何交换数据, 数据包含哪些等等. 它很厉害的地方在于 语言中立 ,大部分语言都支持,支持两边语言不同也能 , 平台中立, 支持跨平台 109 | 110 | 这非常厉害 , 它同时采用二进制的方式对数据进行传输 相较于json数据小了很多 111 | 112 | 那我们从各个方面对比下 json 与 protobuf 吧 113 | 114 | ## protobuf 与 json 115 | 116 | ### 二者基本使用方式 117 | 118 | json本质就是一种规定好格式的字符串, 不需要任何代码定义的支持, 它默认采用键值对的方式 119 | 120 | 来划分数据 121 | 122 | ![image-20230531104449274](image/readme/image-20230531104449274.png) 123 | 124 | protobuf 双方首先使用同一份 .proto 文件 125 | 126 | > 是的,在传输之前,二者需要进行商量好 传什么内容, 这样protobuf在传输过程中就不需要传输键值, 能很大地节省数据量 127 | > 128 | > json不需要要商量好, 因此常用作接口, 来向任何可能调用接口的人表明数据的内容 129 | > 130 | > 而protobuf 用作服务器之间的通讯 131 | 132 | 在 .proto 文件中 定义了 需要传输的对象(message) 133 | 134 | ![image-20230531104953708](image/readme/image-20230531104953708.png) 135 | 136 | > 接下来讲解 protobuf 如何达到 语言中立 平台中立 137 | 138 | 定义好.proto文件后, 通过protoc 可以使用.proto 根据需要生成不同的代码依赖 139 | 140 | ![image-20230531105559663](image/readme/image-20230531105559663.png) 141 | 142 | 比如C++,会生成 .pb.cc .pb.h 其中代码包含了对象的定义及对象的序列化 与 解序列化 等相关函数 143 | 144 | 通过发送方与接收方都引入.proto生成的代码 145 | 146 | 发送方就可以做到定义数据并序列化 147 | 148 | 接受方就可以做到反序列化并取出数据 149 | 150 | > protobuf就是这样做到语言中立 , 平台中立的 , 太解耦了! 牛! 151 | 152 | ## .proto的基本定义 153 | 154 | 讲解基本的代码定义, 如有更深层次的需要 , 可以 查看文档 与 阅读源码 155 | 156 | ``` 157 | syntax="proto3";// 声明proto版本 158 | 159 | package fixbug;// 声明代码所在的包(对c++来说就是namespace) 160 | 161 | 162 | ``` 163 | 164 | 定义一个对象(消息 message) 165 | 166 | ``` 167 | message ResultCode 168 | { 169 | int32 errcode=1; 170 | bytes errmsg=2; // 1 ,2 代表第一个参数, 第二个参数 是占位符 171 | } 172 | ``` 173 | 174 | 还可以组合 175 | 176 | ``` 177 | message GetFriendListsResponse 178 | { 179 | ResultCode result=1; 180 | repeated User friend_lists=2; 181 | } 182 | ``` 183 | 184 | ## protobuf的基本代码 185 | 186 | ```c++ 187 | #include 188 | #include 189 | #include "test.pb.h" 190 | using namespace fixbug; 191 | using namespace std; // 引入 192 | 193 | // 定义对象 194 | // 封装了login请求对象的数据 195 | LoginRequest req; 196 | req.set_name("zhang san"); 197 | req.set_pwd("123456"); 198 | 199 | // 序列化 200 | // 对象数据序列化-》char* 201 | string send_str; 202 | if(req.SerializeToString(&send_str)) 203 | { 204 | cout<set_errcode(1); 322 | rc->set_errmsg("登陆处理失败"); 323 | ``` 324 | 325 | ### 列表定义 326 | 327 | ``` 328 | message User 329 | { 330 | bytes name; 331 | uint32 age=2; 332 | enum Sex 333 | { 334 | MAN=0; 335 | WOMAN=1; 336 | } 337 | Sex sex=3; 338 | } 339 | message GetFriendListsResponse 340 | { 341 | ResultCode result=1; 342 | repeated User users=2; 343 | } 344 | ``` 345 | 346 | ### 列表的初始化 347 | 348 | test.proto 349 | 350 | ``` 351 | GetFriendListsResponse rlist; 352 | ResultCode* rc2=rlist.mutable_result(); 353 | rc2->set_errcode(0); 354 | 355 | User *user1=rlist.add_friend_lists(); 356 | user1->set_name("zhang san"); 357 | user1->set_age(20); 358 | user1->set_sex(User::MAN); 359 | 360 | User *user2=rlist.add_friend_lists(); 361 | user2->set_name("zhang san"); 362 | user2->set_age(20); 363 | user2->set_sex(User::MAN); 364 | ``` 365 | 366 | ### 遍历列表 367 | 368 | main.cpp 369 | 370 | ``` 371 | cout< 505 | 506 | echo server 正常 507 | 508 | # protobuf 我的理解及源码分析 509 | 510 | 1. protobuf 实际上是一个通讯协议 两边通过使用同一份.proto文件可以定义 对象、函数、服务 511 | 2. protobuf通过针对不同语言基于.proto文件生成依赖代码 达到跨平台, 语言中立的效果 512 | 3. protobuf基础库分为三大层: service、method、message、 这三个是protobuf的基类 513 | 514 | service 代表 一个服务 515 | 516 | ### service.h 517 | 518 | 我们可以看到service基类, 有几个函数 519 | 520 | GetDescriptor() 获得service描述符 可以获得service相关的属性 521 | 522 | callmethod() 调用service下的method 523 | 524 | getrequestPrototype() 根据message描述符 得到参数的message 525 | 526 | getresponseprototype() 根据message描述符 得到响应的message 527 | 528 | ``` 529 | class PROTOBUF_EXPORT Service { 530 | public: 531 | inline Service() {} 532 | virtual ~Service(); 533 | 534 | enum ChannelOwnership { STUB_OWNS_CHANNEL, STUB_DOESNT_OWN_CHANNEL }; 535 | virtual const ServiceDescriptor* GetDescriptor() = 0; 536 | virtual void CallMethod(const MethodDescriptor* method, 537 | RpcController* controller, const Message* request, 538 | Message* response, Closure* done) = 0; 539 | virtual const Message& GetRequestPrototype( 540 | const MethodDescriptor* method) const = 0; 541 | virtual const Message& GetResponsePrototype( 542 | const MethodDescriptor* method) const = 0; 543 | 544 | private: 545 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Service); 546 | }; 547 | ``` 548 | 549 | method 代表 一个方法 550 | 551 | message 代表 一个对象 , 通常把函数的参数包装成一个对象、函数的返回值包装成一个对象 552 | 553 | protobuf生成的依赖代码(.user.pb.h user.pb.cc) 主要包含用户自定义的 service、method、message具体子类 554 | 555 | 他们从service、method、message继承而来 556 | 557 | ### servicedescriptor 558 | 559 | 可以看出主要获得service相关的属性 560 | 561 | 可以得到service的name、full_name、methoddescriptor、method的数目... 562 | 563 | ``` 564 | // Describes an RPC service. Use DescriptorPool to construct your own 565 | // descriptors. 566 | class PROTOBUF_EXPORT ServiceDescriptor { 567 | public: 568 | typedef ServiceDescriptorProto Proto; 569 | 570 | // The name of the service, not including its containing scope. 571 | const std::string& name() const; 572 | // The fully-qualified name of the service, scope delimited by periods. 573 | const std::string& full_name() const; 574 | // Index of this service within the file's services array. 575 | int index() const; 576 | 577 | // The .proto file in which this service was defined. Never nullptr. 578 | const FileDescriptor* file() const; 579 | 580 | // Get options for this service type. These are specified in the .proto file 581 | // by placing lines like "option foo = 1234;" in the service definition. 582 | // Allowed options are defined by ServiceOptions in descriptor.proto, and any 583 | // available extensions of that message. 584 | const ServiceOptions& options() const; 585 | 586 | // The number of methods this service defines. 587 | int method_count() const; 588 | // Gets a MethodDescriptor by index, where 0 <= index < method_count(). 589 | // These are returned in the order they were defined in the .proto file. 590 | const MethodDescriptor* method(int index) const; 591 | 592 | // Look up a MethodDescriptor by name. 593 | const MethodDescriptor* FindMethodByName(const std::string& name) const; 594 | // See Descriptor::CopyTo(). 595 | void CopyTo(ServiceDescriptorProto* proto) const; 596 | 597 | // See Descriptor::DebugString(). 598 | std::string DebugString() const; 599 | 600 | // See Descriptor::DebugStringWithOptions(). 601 | std::string DebugStringWithOptions(const DebugStringOptions& options) const; 602 | 603 | // Source Location --------------------------------------------------- 604 | 605 | // Updates |*out_location| to the source location of the complete 606 | // extent of this service declaration. Returns false and leaves 607 | // |*out_location| unchanged iff location information was not available. 608 | bool GetSourceLocation(SourceLocation* out_location) const; 609 | 610 | private: 611 | typedef ServiceOptions OptionsType; 612 | 613 | // Allows access to GetLocationPath for annotations. 614 | friend class io::Printer; 615 | friend class compiler::cpp::Formatter; 616 | 617 | // See Descriptor::DebugString(). 618 | void DebugString(std::string* contents, 619 | const DebugStringOptions& options) const; 620 | 621 | // Walks up the descriptor tree to generate the source location path 622 | // to this descriptor from the file root. 623 | void GetLocationPath(std::vector* output) const; 624 | 625 | const std::string* name_; 626 | const std::string* full_name_; 627 | const FileDescriptor* file_; 628 | const ServiceOptions* options_; 629 | MethodDescriptor* methods_; 630 | int method_count_; 631 | // IMPORTANT: If you add a new field, make sure to search for all instances 632 | // of Allocate() and AllocateArray() in 633 | // descriptor.cc and update them to initialize the field. 634 | 635 | // Must be constructed using DescriptorPool. 636 | ServiceDescriptor() {} 637 | friend class DescriptorBuilder; 638 | friend class FileDescriptor; 639 | friend class MethodDescriptor; 640 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); 641 | }; 642 | 643 | ``` 644 | 645 | ### method -> methoddescriptor 646 | 647 | 是的, 不存在method基类、存在的是methoddescriptor 648 | 649 | 可以看到 可以得到method的name、full_name、index、file、servicedescriptor .... 650 | 651 | 不能通过methoddescriptor调用, 只能通过service进行method调用 652 | 653 | ``` 654 | class PROTOBUF_EXPORT MethodDescriptor { 655 | public: 656 | typedef MethodDescriptorProto Proto; 657 | 658 | // Name of this method, not including containing scope. 659 | const std::string& name() const; 660 | // The fully-qualified name of the method, scope delimited by periods. 661 | const std::string& full_name() const; 662 | // Index within the service's Descriptor. 663 | int index() const; 664 | 665 | // The .proto file in which this method was defined. Never nullptr. 666 | const FileDescriptor* file() const; 667 | // Gets the service to which this method belongs. Never nullptr. 668 | const ServiceDescriptor* service() const; 669 | 670 | // Gets the type of protocol message which this method accepts as input. 671 | const Descriptor* input_type() const; 672 | // Gets the type of protocol message which this message produces as output. 673 | const Descriptor* output_type() const; 674 | 675 | // Gets whether the client streams multiple requests. 676 | bool client_streaming() const; 677 | // Gets whether the server streams multiple responses. 678 | bool server_streaming() const; 679 | 680 | // Get options for this method. These are specified in the .proto file by 681 | // placing lines like "option foo = 1234;" in curly-braces after a method 682 | // declaration. Allowed options are defined by MethodOptions in 683 | // descriptor.proto, and any available extensions of that message. 684 | const MethodOptions& options() const; 685 | 686 | // See Descriptor::CopyTo(). 687 | void CopyTo(MethodDescriptorProto* proto) const; 688 | 689 | // See Descriptor::DebugString(). 690 | std::string DebugString() const; 691 | 692 | // See Descriptor::DebugStringWithOptions(). 693 | std::string DebugStringWithOptions(const DebugStringOptions& options) const; 694 | 695 | // Source Location --------------------------------------------------- 696 | 697 | // Updates |*out_location| to the source location of the complete 698 | // extent of this method declaration. Returns false and leaves 699 | // |*out_location| unchanged iff location information was not available. 700 | bool GetSourceLocation(SourceLocation* out_location) const; 701 | 702 | private: 703 | typedef MethodOptions OptionsType; 704 | 705 | // Allows access to GetLocationPath for annotations. 706 | friend class io::Printer; 707 | friend class compiler::cpp::Formatter; 708 | 709 | // See Descriptor::DebugString(). 710 | void DebugString(int depth, std::string* contents, 711 | const DebugStringOptions& options) const; 712 | 713 | // Walks up the descriptor tree to generate the source location path 714 | // to this descriptor from the file root. 715 | void GetLocationPath(std::vector* output) const; 716 | 717 | const std::string* name_; 718 | const std::string* full_name_; 719 | const ServiceDescriptor* service_; 720 | mutable internal::LazyDescriptor input_type_; 721 | mutable internal::LazyDescriptor output_type_; 722 | const MethodOptions* options_; 723 | bool client_streaming_; 724 | bool server_streaming_; 725 | // IMPORTANT: If you add a new field, make sure to search for all instances 726 | // of Allocate() and AllocateArray() in 727 | // descriptor.cc and update them to initialize the field. 728 | 729 | // Must be constructed using DescriptorPool. 730 | MethodDescriptor() {} 731 | friend class DescriptorBuilder; 732 | friend class ServiceDescriptor; 733 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor); 734 | }; 735 | 736 | ``` 737 | 738 | ### message 739 | 740 | ``` 741 | class PROTOBUF_EXPORT Message : public MessageLite { 742 | public: 743 | inline Message() {} 744 | ~Message() override {} 745 | 746 | // Basic Operations ------------------------------------------------ 747 | 748 | // Construct a new instance of the same type. Ownership is passed to the 749 | // caller. (This is also defined in MessageLite, but is defined again here 750 | // for return-type covariance.) 751 | Message* New() const override = 0; 752 | 753 | // Construct a new instance on the arena. Ownership is passed to the caller 754 | // if arena is a nullptr. Default implementation allows for API compatibility 755 | // during the Arena transition. 756 | Message* New(Arena* arena) const override { 757 | Message* message = New(); 758 | if (arena != nullptr) { 759 | arena->Own(message); 760 | } 761 | return message; 762 | } 763 | ``` 764 | 765 | ### UserServiceRpc 依赖代码的具体service类 766 | 767 | 可以看到 其继承service基类 虚函数包含 定义的函数、 需要我们继承该类, 把函数实现了. 即声明该服务(完成服务的定义) 768 | 769 | ``` 770 | class UserServiceRpc : public ::PROTOBUF_NAMESPACE_ID::Service { 771 | protected: 772 | // This class should be treated as an abstract interface. 773 | inline UserServiceRpc() {}; 774 | public: 775 | virtual ~UserServiceRpc(); 776 | 777 | typedef UserServiceRpc_Stub Stub; 778 | 779 | static const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* descriptor(); 780 | 781 | virtual void Login(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 782 | const ::fixbug::LoginRequest* request, 783 | ::fixbug::LoginResponse* response, 784 | ::google::protobuf::Closure* done); 785 | virtual void Hello(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 786 | const ::fixbug::HelloRequest* request, 787 | ::fixbug::HelloReponse* response, 788 | ::google::protobuf::Closure* done); 789 | 790 | // implements Service ---------------------------------------------- 791 | 792 | const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* GetDescriptor(); 793 | void CallMethod(const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method, 794 | ::PROTOBUF_NAMESPACE_ID::RpcController* controller, 795 | const ::PROTOBUF_NAMESPACE_ID::Message* request, 796 | ::PROTOBUF_NAMESPACE_ID::Message* response, 797 | ::google::protobuf::Closure* done); 798 | const ::PROTOBUF_NAMESPACE_ID::Message& GetRequestPrototype( 799 | const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const; 800 | const ::PROTOBUF_NAMESPACE_ID::Message& GetResponsePrototype( 801 | const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const; 802 | 803 | private: 804 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UserServiceRpc); 805 | }; 806 | ``` 807 | 808 | ### UserServiceRpcStub 依赖代码的具体servicestub类 809 | 810 | UserServiceRpcStub继承自UserviceRpc 811 | 812 | 它对servicestub中定义的虚函数 Login Hello进行了具体实现 813 | 814 | 将它们具体使用RpcChannel的callmethod, 汇聚到了统一调用相同的函数上 815 | 816 | 没错, 这是为caller实现的一个基础类 ,我们通过继承RpcChannel 实现新的callmethod, 能够统一实现发送服务名,函数名,参数的能力 817 | 818 | ```c++ 819 | class UserServiceRpc_Stub : public UserServiceRpc { 820 | public: 821 | UserServiceRpc_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel); 822 | UserServiceRpc_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, 823 | ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership); 824 | ~UserServiceRpc_Stub(); 825 | 826 | inline ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel() { return channel_; } 827 | 828 | // implements UserServiceRpc ------------------------------------------ 829 | 830 | void Login(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 831 | const ::fixbug::LoginRequest* request, 832 | ::fixbug::LoginResponse* response, 833 | ::google::protobuf::Closure* done); 834 | void Hello(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 835 | const ::fixbug::HelloRequest* request, 836 | ::fixbug::HelloReponse* response, 837 | ::google::protobuf::Closure* done); 838 | private: 839 | ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel_; 840 | bool owns_channel_; 841 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UserServiceRpc_Stub); 842 | }; 843 | ``` 844 | 845 | ### 以Resultcode为例 依赖代码的具体message类 846 | 847 | 不具体介绍, 在protobuf示例代码中展示如何使用,核心思想是封装定义好的message 并且提供构造函数和设置初始化值相关函数 提供序列化和反序列化 848 | 849 | # 项目深剖 以login函数为例 850 | 851 | > tips:试着把整体逻辑用最简单的方式进行讲解: 852 | > 853 | > 从==callee方(函数提供方)==出发 854 | > 855 | > 我们首先定义proto文件,在其中定义message对象、service对象 . 对于service对象,我们需要继承, 实现其中定义的虚函数(完成service对象的定义) , 此时我们就完成了 “服务类” 的定义 856 | > 857 | > 然后需要对服务类初始化, 并且以哈希的方式“存储”(这样根据rpc服务名和函数名 可以快速进行调用) 858 | > 859 | > 启动rpc服务后, 将所有服务与函数注册至zookeeper 860 | 861 | > 使用muduo 做一个echo server , 接受序列化后的服务名 及函数名 和 参数 862 | > 863 | > 解序列化后 进行调用, 并且通过回调函数发送函数执行完后的结果 864 | 865 | > 从==caller方(函数调用方)==出发 866 | > 867 | > 定义proto文件后, 依赖代码中同时形成了service_stub对象, 其继承了service对象, 并且收束至调用 传入的rpcchannel对象的callmethod方法, 因此我们可以继承rpcchannel对象 ,并重写其中的callmethod方法, 使其先访问zookeeper ,找到服务器的ip地址与端口号, 发送服务名及 函数名 和 参数 , 从而调用远程函数, 得到结果后, 解析即可 868 | 869 | 将以 下面的线进行深剖 870 | 871 | 配置类外层->配置类底层 872 | 873 | callee-> 如何注册一个rpc函数-> 底层 874 | 875 | caller-> 如何调用一个rpc函数->底层 876 | 877 | 异步日志 878 | 879 | ## 框架外层-配置类 880 | 881 | 配置类的目的是 为了, ==从磁盘的文件中,读取信息到内存中, 使得程序可以随时从内存中取信息, 不用随时去磁盘读== 882 | 883 | src/include/MrpcApplication.h src/MrpcApplication.cpp 884 | 885 | 使用单例模式, 内存中读一份就ok了,使用的是饿汉模式 886 | 887 | 在本项目中 888 | 889 | callee方 890 | 891 | 配置类,需要定义 892 | 893 | rpc节点的ip地址 894 | 895 | rpc节点的端口号地址 896 | 897 | zookeeper的ip地址 898 | 899 | zookeeper的port地址 900 | 901 | 相当于 ==需要把服务方提供方的ip地址与端口号 注册到zookeeper中== 902 | 903 | caller方 904 | 905 | 配置类,需要定义 906 | 907 | zookeeper的ip地址 908 | 909 | zookeeper的port地址 910 | 911 | 相当于 ==服务调用方访问zookeeper得到rpc服务节点的ip地址及端口号, 因此不需要在文件中写明== 912 | 913 | > 项目中,层层开发, 最后加上zookeeper , 省事,两者读了一个 test.conf 914 | > 915 | > 但要明确,服务调用方 最后版本中, 并没有访问rpc的ip和port 916 | 917 | ### 配置文件 918 | 919 | ``` 920 | # rpc节点的地址 921 | rpcserverip=127.0.0.1 922 | #rpc节点的port端口号 923 | rpcserverport=8088 924 | #zk的ip地址 925 | zookeeperip=127.0.0.1 926 | 927 | 928 | #zk的port地址 929 | zookeeperport=2181 930 | ``` 931 | 932 | ### 配置类的初始化 933 | 934 | ``` 935 | MrpcApplication::Init(argc,argv); 936 | ``` 937 | 938 | ### 配置类的头文件及cpp 939 | 940 | src/include/MrpcApplication.h 941 | 942 | 要点: 采用单例模式 , 把构造相关的函数都给delete掉, 默认构造函数只能设置成private, 因为要在成员方法中用 943 | 944 | ``` 945 | #pragma once 946 | #include"MrpcConfig.h" 947 | // mrpc 框架的初始化类 948 | // 框架只需要一个 因此用单例模式进行设计 949 | 950 | class MrpcApplication 951 | { 952 | public: 953 | static void Init(int argc, char ** argv); 954 | static MrpcApplication& GetInstance(); 955 | static MrpcConfig& getConfig(); 956 | private: 957 | static MrpcConfig m_config; 958 | MrpcApplication(){}; 959 | MrpcApplication(const MrpcApplication & other)=delete; 960 | MrpcApplication(MrpcApplication && other)=delete; 961 | MrpcApplication& operator =(const MrpcApplication& other)=delete; 962 | 963 | }; 964 | ``` 965 | 966 | src/MrpcApplication.cpp 967 | 968 | 要点: 969 | 970 | 1. 可执行文件的参数要求,在运行时必须指明配置文件 即必须要有-i选项 且提供配置文件 971 | 2. 使用单例模式 饿汉模式 线程安全 在局部函数中申请静态变量, 延长其生命周期 .同时C++11 编译器能保证初始化静态局部变量的线程安全性 972 | 973 | ``` 974 | #include 975 | #include 976 | #include "MrpcApplication.h" 977 | MrpcConfig MrpcApplication::m_config; 978 | void ShowArgsHelp() 979 | { 980 | std::cout<<"format: command -i " <" <name(); 1090 | std::string rs=HelloQ(name); 1091 | response->set_hello(rs); 1092 | done->Run(); 1093 | } 1094 | 1095 | bool Login(std::string name, std::string pwd) 1096 | { 1097 | std::cout<<"doing local service: Login"<login(loginrequest)-> 1106 | 1107 | */ 1108 | void Login(::google::protobuf::RpcController* controller, 1109 | const ::fixbug::LoginRequest* request, 1110 | ::fixbug::LoginResponse* response, 1111 | ::google::protobuf::Closure* done) 1112 | { 1113 | // 框架给业务上爆了请求参数LoginRequest,业务获取相应数据做本地业务 1114 | std::string name=request->name(); 1115 | std::string pwd=request->pwd(); 1116 | 1117 | std::cout<<"rpc_login name: "<mutable_result(); 1123 | code->set_errcode(0); 1124 | code->set_errmsg(""); 1125 | response->set_success(login_result); 1126 | // 执行回调操作 执行响应对象数据的序列化和网络发送(都是由框架来完成的) 1127 | done->Run(); 1128 | 1129 | } 1130 | 1131 | 1132 | ``` 1133 | 1134 | ### 注册该服务 1135 | 1136 | ``` 1137 | // 调用框架的初始化操作 1138 | MrpcApplication::Init(argc,argv); 1139 | // 把UserService对象发布到rpc节点上 1140 | RpcProvider provider; // 网络发布对象 1141 | provider.NotifyService(new UserService()); 1142 | ``` 1143 | 1144 | ### 启动Rpc 1145 | 1146 | ``` 1147 | //启动rpc 1148 | provider.Run(); 1149 | ``` 1150 | 1151 | ### 函数的定义 1152 | 1153 | 底层 1154 | 1155 | ``` 1156 | class UserService:public fixbug::UserServiceRpc 1157 | { 1158 | public: 1159 | 1160 | bool Login(std::string name, std::string pwd) 1161 | { 1162 | std::cout<<"doing local service: Login"<login(loginrequest)-> 1171 | 1172 | */ 1173 | void Login(::google::protobuf::RpcController* controller, 1174 | const ::fixbug::LoginRequest* request, 1175 | ::fixbug::LoginResponse* response, 1176 | ::google::protobuf::Closure* done) 1177 | { 1178 | // 框架给业务上爆了请求参数LoginRequest,业务获取相应数据做本地业务 1179 | std::string name=request->name(); 1180 | std::string pwd=request->pwd(); 1181 | 1182 | std::cout<<"rpc_login name: "<mutable_result(); 1188 | code->set_errcode(0); 1189 | code->set_errmsg(""); 1190 | response->set_success(login_result); 1191 | // 执行回调操作 执行响应对象数据的序列化和网络发送(都是由框架来完成的) 1192 | done->Run(); 1193 | 1194 | } 1195 | 1196 | 1197 | }; 1198 | ``` 1199 | 1200 | ## 框架底层--rpc服务的注册底层 1201 | 1202 | ### RpcProvider.h 1203 | 1204 | RpcProvider 主要有NotifyService() , 代表将服务注册至Rpc 1205 | 1206 | Run(), 代表启动Rpc 1207 | 1208 | ``` 1209 | class RpcProvider 1210 | { 1211 | public: 1212 | // 这里是框架提供的外部进行注册 1213 | // void NotifyServise(UserService* service) 不能依赖于某个具体业务! 1214 | void NotifyService(google::protobuf::Service * service); 1215 | 1216 | // 启动网络调用函数 1217 | void Run(); 1218 | 1219 | void OnConnection(const muduo::net::TcpConnectionPtr &conn); 1220 | 1221 | void OnMessage(const muduo::net::TcpConnectionPtr&,muduo::net::Buffer*,muduo::Timestamp); 1222 | 1223 | void callmeback(const muduo::net::TcpConnectionPtr& conn,google::protobuf::Message* response); 1224 | private: 1225 | struct ServiceInfo 1226 | { 1227 | google::protobuf::Service* service_ptr; 1228 | std::map method_dic; 1229 | }; 1230 | std::map service_dic; 1231 | // 组合了evenetloop 1232 | muduo::net::EventLoop m_eventLoop; 1233 | }; 1234 | 1235 | ``` 1236 | 1237 | ### RpcProvider --NotifyService() 注册该服务至Rpc 1238 | 1239 | > RpcProvider 以哈希的方式 存储Service 及其下的method , 从而可以根据服务名与服务快速调用该函数 1240 | 1241 | RpcProvider 以 该形式 存储Rpc服务 1242 | 1243 | {"service1_name": [service1_ptr, {"method1_name": method_des_ptr .... } ] , “service2_name”: , “service3_name”: ....} 1244 | 1245 | ``` 1246 | void RpcProvider::NotifyService(google::protobuf::Service * service){ 1247 | const google::protobuf::ServiceDescriptor* service_ptr =service->GetDescriptor(); 1248 | // 得到method的数量 1249 | const std::string service_name=service_ptr->name(); 1250 | int n= service_ptr->method_count(); 1251 | std::map method_dic; 1252 | // 遍历方法 ,进行存储 1253 | for(int i=0;imethod(i); 1256 | const std::string method_name=method_ptr->name(); 1257 | method_dic[method_name]=method_ptr; 1258 | } 1259 | ServiceInfo sinfo; 1260 | sinfo.service_ptr=service; 1261 | sinfo.method_dic=method_dic; 1262 | service_dic[service_name]=sinfo; 1263 | 1264 | // for(auto item:service_dic) 1265 | // { 1266 | // std::cout<<"服务名:"<retrieveAllAsString(); 1339 | // 截取前四个字节 1340 | uint32_t len=0; 1341 | buffer_str.copy((char*)&len,4,0); 1342 | // 解析rpc_header对象 1343 | std::string rpc_header_str=buffer_str.substr(4,len); 1344 | src::RpcHeader rpcheader=src::RpcHeader(); 1345 | if(!rpcheader.ParseFromString(rpc_header_str)) 1346 | { 1347 | // 解析失败 1348 | std::cout<<"rpcheader解析失败"<GetRequestPrototype(method_des).New(); 1374 | google::protobuf::Message* response=service->GetResponsePrototype(method_des).New(); 1375 | if(!request->ParseFromString(args_str)) 1376 | { 1377 | std::cout<<"解析参数失败"< (callmeback,conn,response); 1382 | auto done=google::protobuf::NewCallback< RpcProvider,const muduo::net::TcpConnectionPtr& ,google::protobuf::Message* > (this,&RpcProvider::callmeback,conn,response); 1383 | 1384 | // 调用该函数 1385 | service->CallMethod(method_des,nullptr,request,response,done); 1386 | } 1387 | // 需要连接, response 1388 | void RpcProvider::callmeback(const muduo::net::TcpConnectionPtr& conn,google::protobuf::Message* response) 1389 | { 1390 | // 序列化 1391 | std::string response_str; 1392 | if(!response->SerializeToString(&response_str)) 1393 | { 1394 | std::cout<<"response序列化失败"<send(response_str); 1398 | // 模仿http的短连接 1399 | conn->shutdown(); 1400 | 1401 | } 1402 | ``` 1403 | 1404 | ## 框架外层--如何调用Rpc函数 1405 | 1406 | 1. 与调用方使用同一份.proto文件, 生成依赖代码文件 1407 | 2. 初始化配置类(注意: 只需要用到zookeeper的ip和port即可) 1408 | 3. 定义具体服务类的stub, 并传入重写的MrpcChannel() 1409 | 4. 准备参数, 根据stub调用相关函数 1410 | 1411 | ```C++ 1412 | #include 1413 | #include"MrpcApplication.h" 1414 | #include"MrpcChannel.h" 1415 | #include"MrpcController.h" 1416 | #include"user.pb.h" 1417 | int main(int argc, char** argv) 1418 | { 1419 | // 要是想调用的话, 需要传入相关参数 ,进行配置,全局只会初始化一次 1420 | MrpcApplication::Init(argc,argv); 1421 | fixbug::UserServiceRpc_Stub stub(new MrpcChannel()); 1422 | // 初始化相关参数 1423 | fixbug::LoginRequest request; 1424 | request.set_name("云霞川"); 1425 | request.set_pwd("hch12345"); 1426 | fixbug::LoginResponse response; 1427 | MrpcController controller; 1428 | stub.Login(&controller,&request,&response,nullptr); 1429 | // 会自动调rpcchannel 用callmethod 1430 | if(!controller.Failed()) 1431 | { 1432 | // 得到执行后的response 1433 | if(!response.success()) 1434 | { 1435 | std::cout<<"远程rpc函数执行失败"<service(); 1497 | std::string service_name=service->name(); 1498 | std::string method_name=method->name(); 1499 | //args序列化 并得到长度 1500 | std::string args_str; 1501 | request->SerializeToString(&args_str); 1502 | uint32_t args_len=args_str.size(); 1503 | header.set_args_len(args_len); 1504 | header.set_method_name(method_name); 1505 | header.set_service_name(service_name); 1506 | //rpc_header 序列化 1507 | std::string rpc_header_str; 1508 | header.SerializeToString(&rpc_header_str); 1509 | std::string rpc_header_len_str; 1510 | uint32_t rpc_header_len=rpc_header_str.size(); 1511 | rpc_header_len_str.insert(0,std::string((char*)&rpc_header_len,4)); 1512 | 1513 | // 字符串都已经准备好 1514 | std::string send_str; 1515 | send_str+=rpc_header_len_str; 1516 | send_str+=rpc_header_str; 1517 | send_str+=args_str; 1518 | 1519 | std::string zoo_ip=MrpcApplication::getConfig().Load("zookeeperip"); 1520 | uint16_t zoo_port=stoi(MrpcApplication::getConfig().Load("zookeeperport")); 1521 | 1522 | 1523 | std::string zoo_str="/"+service_name+"/"+method_name; 1524 | Zookeeperutil zk=Zookeeperutil(); 1525 | zk.start(); 1526 | std::string ip_port=zk.getData(zoo_str); 1527 | if(ip_port.size()==0) 1528 | { 1529 | std::cout<<"未找到zookeeper"<SetFailed("client_sock申请失败"); 1545 | return; 1546 | } 1547 | struct sockaddr_in sock_addr; 1548 | sock_addr.sin_family=AF_INET; 1549 | sock_addr.sin_port=htons(port); 1550 | sock_addr.sin_addr.s_addr=inet_addr(ip.c_str()); 1551 | if(connect(client_sock,(sockaddr*)&sock_addr,sizeof(sock_addr))<0) 1552 | { 1553 | controller->SetFailed("连接失败"); 1554 | return; 1555 | } 1556 | // 发送信息 1557 | int len=0; 1558 | if(len=send(client_sock,send_str.c_str(),send_str.size(),0)<0) 1559 | { 1560 | controller->SetFailed("发送失败"); 1561 | return; 1562 | } 1563 | char buf[1024]={0}; 1564 | int len2=0; 1565 | if((len2=recv(client_sock,buf,1024,0))<0) 1566 | { 1567 | controller->SetFailed("接受失败"); 1568 | return; 1569 | } 1570 | std::string response_str=buf; 1571 | response->ParseFromArray(buf,len2); 1572 | //std::cout<<"success: "<ParseFromString(response_str); 1574 | } 1575 | 1576 | 1577 | ``` 1578 | -------------------------------------------------------------------------------- /example/user.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: user.proto 3 | 4 | #ifndef GOOGLE_PROTOBUF_INCLUDED_user_2eproto 5 | #define GOOGLE_PROTOBUF_INCLUDED_user_2eproto 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #if PROTOBUF_VERSION < 3011000 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3011000 < PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include // IWYU pragma: export 33 | #include // IWYU pragma: export 34 | #include 35 | #include 36 | // @@protoc_insertion_point(includes) 37 | #include 38 | #define PROTOBUF_INTERNAL_EXPORT_user_2eproto 39 | PROTOBUF_NAMESPACE_OPEN 40 | namespace internal { 41 | class AnyMetadata; 42 | } // namespace internal 43 | PROTOBUF_NAMESPACE_CLOSE 44 | 45 | // Internal implementation detail -- do not use these members. 46 | struct TableStruct_user_2eproto { 47 | static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] 48 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 49 | static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[] 50 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 51 | static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[5] 52 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 53 | static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; 54 | static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; 55 | static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[]; 56 | }; 57 | extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_user_2eproto; 58 | namespace fixbug { 59 | class HelloReponse; 60 | class HelloReponseDefaultTypeInternal; 61 | extern HelloReponseDefaultTypeInternal _HelloReponse_default_instance_; 62 | class HelloRequest; 63 | class HelloRequestDefaultTypeInternal; 64 | extern HelloRequestDefaultTypeInternal _HelloRequest_default_instance_; 65 | class LoginRequest; 66 | class LoginRequestDefaultTypeInternal; 67 | extern LoginRequestDefaultTypeInternal _LoginRequest_default_instance_; 68 | class LoginResponse; 69 | class LoginResponseDefaultTypeInternal; 70 | extern LoginResponseDefaultTypeInternal _LoginResponse_default_instance_; 71 | class ResultCode; 72 | class ResultCodeDefaultTypeInternal; 73 | extern ResultCodeDefaultTypeInternal _ResultCode_default_instance_; 74 | } // namespace fixbug 75 | PROTOBUF_NAMESPACE_OPEN 76 | template<> ::fixbug::HelloReponse* Arena::CreateMaybeMessage<::fixbug::HelloReponse>(Arena*); 77 | template<> ::fixbug::HelloRequest* Arena::CreateMaybeMessage<::fixbug::HelloRequest>(Arena*); 78 | template<> ::fixbug::LoginRequest* Arena::CreateMaybeMessage<::fixbug::LoginRequest>(Arena*); 79 | template<> ::fixbug::LoginResponse* Arena::CreateMaybeMessage<::fixbug::LoginResponse>(Arena*); 80 | template<> ::fixbug::ResultCode* Arena::CreateMaybeMessage<::fixbug::ResultCode>(Arena*); 81 | PROTOBUF_NAMESPACE_CLOSE 82 | namespace fixbug { 83 | 84 | // =================================================================== 85 | 86 | class ResultCode : 87 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:fixbug.ResultCode) */ { 88 | public: 89 | ResultCode(); 90 | virtual ~ResultCode(); 91 | 92 | ResultCode(const ResultCode& from); 93 | ResultCode(ResultCode&& from) noexcept 94 | : ResultCode() { 95 | *this = ::std::move(from); 96 | } 97 | 98 | inline ResultCode& operator=(const ResultCode& from) { 99 | CopyFrom(from); 100 | return *this; 101 | } 102 | inline ResultCode& operator=(ResultCode&& from) noexcept { 103 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 104 | if (this != &from) InternalSwap(&from); 105 | } else { 106 | CopyFrom(from); 107 | } 108 | return *this; 109 | } 110 | 111 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 112 | return GetDescriptor(); 113 | } 114 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 115 | return GetMetadataStatic().descriptor; 116 | } 117 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 118 | return GetMetadataStatic().reflection; 119 | } 120 | static const ResultCode& default_instance(); 121 | 122 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 123 | static inline const ResultCode* internal_default_instance() { 124 | return reinterpret_cast( 125 | &_ResultCode_default_instance_); 126 | } 127 | static constexpr int kIndexInFileMessages = 128 | 0; 129 | 130 | friend void swap(ResultCode& a, ResultCode& b) { 131 | a.Swap(&b); 132 | } 133 | inline void Swap(ResultCode* other) { 134 | if (other == this) return; 135 | InternalSwap(other); 136 | } 137 | 138 | // implements Message ---------------------------------------------- 139 | 140 | inline ResultCode* New() const final { 141 | return CreateMaybeMessage(nullptr); 142 | } 143 | 144 | ResultCode* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 145 | return CreateMaybeMessage(arena); 146 | } 147 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 148 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 149 | void CopyFrom(const ResultCode& from); 150 | void MergeFrom(const ResultCode& from); 151 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 152 | bool IsInitialized() const final; 153 | 154 | size_t ByteSizeLong() const final; 155 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 156 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 157 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 158 | int GetCachedSize() const final { return _cached_size_.Get(); } 159 | 160 | private: 161 | inline void SharedCtor(); 162 | inline void SharedDtor(); 163 | void SetCachedSize(int size) const final; 164 | void InternalSwap(ResultCode* other); 165 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 166 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 167 | return "fixbug.ResultCode"; 168 | } 169 | private: 170 | inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { 171 | return nullptr; 172 | } 173 | inline void* MaybeArenaPtr() const { 174 | return nullptr; 175 | } 176 | public: 177 | 178 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 179 | private: 180 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 181 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_user_2eproto); 182 | return ::descriptor_table_user_2eproto.file_level_metadata[kIndexInFileMessages]; 183 | } 184 | 185 | public: 186 | 187 | // nested types ---------------------------------------------------- 188 | 189 | // accessors ------------------------------------------------------- 190 | 191 | enum : int { 192 | kErrmsgFieldNumber = 2, 193 | kErrcodeFieldNumber = 1, 194 | }; 195 | // bytes errmsg = 2; 196 | void clear_errmsg(); 197 | const std::string& errmsg() const; 198 | void set_errmsg(const std::string& value); 199 | void set_errmsg(std::string&& value); 200 | void set_errmsg(const char* value); 201 | void set_errmsg(const void* value, size_t size); 202 | std::string* mutable_errmsg(); 203 | std::string* release_errmsg(); 204 | void set_allocated_errmsg(std::string* errmsg); 205 | private: 206 | const std::string& _internal_errmsg() const; 207 | void _internal_set_errmsg(const std::string& value); 208 | std::string* _internal_mutable_errmsg(); 209 | public: 210 | 211 | // int32 errcode = 1; 212 | void clear_errcode(); 213 | ::PROTOBUF_NAMESPACE_ID::int32 errcode() const; 214 | void set_errcode(::PROTOBUF_NAMESPACE_ID::int32 value); 215 | private: 216 | ::PROTOBUF_NAMESPACE_ID::int32 _internal_errcode() const; 217 | void _internal_set_errcode(::PROTOBUF_NAMESPACE_ID::int32 value); 218 | public: 219 | 220 | // @@protoc_insertion_point(class_scope:fixbug.ResultCode) 221 | private: 222 | class _Internal; 223 | 224 | ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; 225 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr errmsg_; 226 | ::PROTOBUF_NAMESPACE_ID::int32 errcode_; 227 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 228 | friend struct ::TableStruct_user_2eproto; 229 | }; 230 | // ------------------------------------------------------------------- 231 | 232 | class LoginRequest : 233 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:fixbug.LoginRequest) */ { 234 | public: 235 | LoginRequest(); 236 | virtual ~LoginRequest(); 237 | 238 | LoginRequest(const LoginRequest& from); 239 | LoginRequest(LoginRequest&& from) noexcept 240 | : LoginRequest() { 241 | *this = ::std::move(from); 242 | } 243 | 244 | inline LoginRequest& operator=(const LoginRequest& from) { 245 | CopyFrom(from); 246 | return *this; 247 | } 248 | inline LoginRequest& operator=(LoginRequest&& from) noexcept { 249 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 250 | if (this != &from) InternalSwap(&from); 251 | } else { 252 | CopyFrom(from); 253 | } 254 | return *this; 255 | } 256 | 257 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 258 | return GetDescriptor(); 259 | } 260 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 261 | return GetMetadataStatic().descriptor; 262 | } 263 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 264 | return GetMetadataStatic().reflection; 265 | } 266 | static const LoginRequest& default_instance(); 267 | 268 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 269 | static inline const LoginRequest* internal_default_instance() { 270 | return reinterpret_cast( 271 | &_LoginRequest_default_instance_); 272 | } 273 | static constexpr int kIndexInFileMessages = 274 | 1; 275 | 276 | friend void swap(LoginRequest& a, LoginRequest& b) { 277 | a.Swap(&b); 278 | } 279 | inline void Swap(LoginRequest* other) { 280 | if (other == this) return; 281 | InternalSwap(other); 282 | } 283 | 284 | // implements Message ---------------------------------------------- 285 | 286 | inline LoginRequest* New() const final { 287 | return CreateMaybeMessage(nullptr); 288 | } 289 | 290 | LoginRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 291 | return CreateMaybeMessage(arena); 292 | } 293 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 294 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 295 | void CopyFrom(const LoginRequest& from); 296 | void MergeFrom(const LoginRequest& from); 297 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 298 | bool IsInitialized() const final; 299 | 300 | size_t ByteSizeLong() const final; 301 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 302 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 303 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 304 | int GetCachedSize() const final { return _cached_size_.Get(); } 305 | 306 | private: 307 | inline void SharedCtor(); 308 | inline void SharedDtor(); 309 | void SetCachedSize(int size) const final; 310 | void InternalSwap(LoginRequest* other); 311 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 312 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 313 | return "fixbug.LoginRequest"; 314 | } 315 | private: 316 | inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { 317 | return nullptr; 318 | } 319 | inline void* MaybeArenaPtr() const { 320 | return nullptr; 321 | } 322 | public: 323 | 324 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 325 | private: 326 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 327 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_user_2eproto); 328 | return ::descriptor_table_user_2eproto.file_level_metadata[kIndexInFileMessages]; 329 | } 330 | 331 | public: 332 | 333 | // nested types ---------------------------------------------------- 334 | 335 | // accessors ------------------------------------------------------- 336 | 337 | enum : int { 338 | kNameFieldNumber = 1, 339 | kPwdFieldNumber = 2, 340 | }; 341 | // bytes name = 1; 342 | void clear_name(); 343 | const std::string& name() const; 344 | void set_name(const std::string& value); 345 | void set_name(std::string&& value); 346 | void set_name(const char* value); 347 | void set_name(const void* value, size_t size); 348 | std::string* mutable_name(); 349 | std::string* release_name(); 350 | void set_allocated_name(std::string* name); 351 | private: 352 | const std::string& _internal_name() const; 353 | void _internal_set_name(const std::string& value); 354 | std::string* _internal_mutable_name(); 355 | public: 356 | 357 | // bytes pwd = 2; 358 | void clear_pwd(); 359 | const std::string& pwd() const; 360 | void set_pwd(const std::string& value); 361 | void set_pwd(std::string&& value); 362 | void set_pwd(const char* value); 363 | void set_pwd(const void* value, size_t size); 364 | std::string* mutable_pwd(); 365 | std::string* release_pwd(); 366 | void set_allocated_pwd(std::string* pwd); 367 | private: 368 | const std::string& _internal_pwd() const; 369 | void _internal_set_pwd(const std::string& value); 370 | std::string* _internal_mutable_pwd(); 371 | public: 372 | 373 | // @@protoc_insertion_point(class_scope:fixbug.LoginRequest) 374 | private: 375 | class _Internal; 376 | 377 | ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; 378 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; 379 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr pwd_; 380 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 381 | friend struct ::TableStruct_user_2eproto; 382 | }; 383 | // ------------------------------------------------------------------- 384 | 385 | class LoginResponse : 386 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:fixbug.LoginResponse) */ { 387 | public: 388 | LoginResponse(); 389 | virtual ~LoginResponse(); 390 | 391 | LoginResponse(const LoginResponse& from); 392 | LoginResponse(LoginResponse&& from) noexcept 393 | : LoginResponse() { 394 | *this = ::std::move(from); 395 | } 396 | 397 | inline LoginResponse& operator=(const LoginResponse& from) { 398 | CopyFrom(from); 399 | return *this; 400 | } 401 | inline LoginResponse& operator=(LoginResponse&& from) noexcept { 402 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 403 | if (this != &from) InternalSwap(&from); 404 | } else { 405 | CopyFrom(from); 406 | } 407 | return *this; 408 | } 409 | 410 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 411 | return GetDescriptor(); 412 | } 413 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 414 | return GetMetadataStatic().descriptor; 415 | } 416 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 417 | return GetMetadataStatic().reflection; 418 | } 419 | static const LoginResponse& default_instance(); 420 | 421 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 422 | static inline const LoginResponse* internal_default_instance() { 423 | return reinterpret_cast( 424 | &_LoginResponse_default_instance_); 425 | } 426 | static constexpr int kIndexInFileMessages = 427 | 2; 428 | 429 | friend void swap(LoginResponse& a, LoginResponse& b) { 430 | a.Swap(&b); 431 | } 432 | inline void Swap(LoginResponse* other) { 433 | if (other == this) return; 434 | InternalSwap(other); 435 | } 436 | 437 | // implements Message ---------------------------------------------- 438 | 439 | inline LoginResponse* New() const final { 440 | return CreateMaybeMessage(nullptr); 441 | } 442 | 443 | LoginResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 444 | return CreateMaybeMessage(arena); 445 | } 446 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 447 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 448 | void CopyFrom(const LoginResponse& from); 449 | void MergeFrom(const LoginResponse& from); 450 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 451 | bool IsInitialized() const final; 452 | 453 | size_t ByteSizeLong() const final; 454 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 455 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 456 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 457 | int GetCachedSize() const final { return _cached_size_.Get(); } 458 | 459 | private: 460 | inline void SharedCtor(); 461 | inline void SharedDtor(); 462 | void SetCachedSize(int size) const final; 463 | void InternalSwap(LoginResponse* other); 464 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 465 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 466 | return "fixbug.LoginResponse"; 467 | } 468 | private: 469 | inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { 470 | return nullptr; 471 | } 472 | inline void* MaybeArenaPtr() const { 473 | return nullptr; 474 | } 475 | public: 476 | 477 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 478 | private: 479 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 480 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_user_2eproto); 481 | return ::descriptor_table_user_2eproto.file_level_metadata[kIndexInFileMessages]; 482 | } 483 | 484 | public: 485 | 486 | // nested types ---------------------------------------------------- 487 | 488 | // accessors ------------------------------------------------------- 489 | 490 | enum : int { 491 | kResultFieldNumber = 1, 492 | kSuccessFieldNumber = 2, 493 | }; 494 | // .fixbug.ResultCode result = 1; 495 | bool has_result() const; 496 | private: 497 | bool _internal_has_result() const; 498 | public: 499 | void clear_result(); 500 | const ::fixbug::ResultCode& result() const; 501 | ::fixbug::ResultCode* release_result(); 502 | ::fixbug::ResultCode* mutable_result(); 503 | void set_allocated_result(::fixbug::ResultCode* result); 504 | private: 505 | const ::fixbug::ResultCode& _internal_result() const; 506 | ::fixbug::ResultCode* _internal_mutable_result(); 507 | public: 508 | 509 | // bool success = 2; 510 | void clear_success(); 511 | bool success() const; 512 | void set_success(bool value); 513 | private: 514 | bool _internal_success() const; 515 | void _internal_set_success(bool value); 516 | public: 517 | 518 | // @@protoc_insertion_point(class_scope:fixbug.LoginResponse) 519 | private: 520 | class _Internal; 521 | 522 | ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; 523 | ::fixbug::ResultCode* result_; 524 | bool success_; 525 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 526 | friend struct ::TableStruct_user_2eproto; 527 | }; 528 | // ------------------------------------------------------------------- 529 | 530 | class HelloRequest : 531 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:fixbug.HelloRequest) */ { 532 | public: 533 | HelloRequest(); 534 | virtual ~HelloRequest(); 535 | 536 | HelloRequest(const HelloRequest& from); 537 | HelloRequest(HelloRequest&& from) noexcept 538 | : HelloRequest() { 539 | *this = ::std::move(from); 540 | } 541 | 542 | inline HelloRequest& operator=(const HelloRequest& from) { 543 | CopyFrom(from); 544 | return *this; 545 | } 546 | inline HelloRequest& operator=(HelloRequest&& from) noexcept { 547 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 548 | if (this != &from) InternalSwap(&from); 549 | } else { 550 | CopyFrom(from); 551 | } 552 | return *this; 553 | } 554 | 555 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 556 | return GetDescriptor(); 557 | } 558 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 559 | return GetMetadataStatic().descriptor; 560 | } 561 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 562 | return GetMetadataStatic().reflection; 563 | } 564 | static const HelloRequest& default_instance(); 565 | 566 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 567 | static inline const HelloRequest* internal_default_instance() { 568 | return reinterpret_cast( 569 | &_HelloRequest_default_instance_); 570 | } 571 | static constexpr int kIndexInFileMessages = 572 | 3; 573 | 574 | friend void swap(HelloRequest& a, HelloRequest& b) { 575 | a.Swap(&b); 576 | } 577 | inline void Swap(HelloRequest* other) { 578 | if (other == this) return; 579 | InternalSwap(other); 580 | } 581 | 582 | // implements Message ---------------------------------------------- 583 | 584 | inline HelloRequest* New() const final { 585 | return CreateMaybeMessage(nullptr); 586 | } 587 | 588 | HelloRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 589 | return CreateMaybeMessage(arena); 590 | } 591 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 592 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 593 | void CopyFrom(const HelloRequest& from); 594 | void MergeFrom(const HelloRequest& from); 595 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 596 | bool IsInitialized() const final; 597 | 598 | size_t ByteSizeLong() const final; 599 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 600 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 601 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 602 | int GetCachedSize() const final { return _cached_size_.Get(); } 603 | 604 | private: 605 | inline void SharedCtor(); 606 | inline void SharedDtor(); 607 | void SetCachedSize(int size) const final; 608 | void InternalSwap(HelloRequest* other); 609 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 610 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 611 | return "fixbug.HelloRequest"; 612 | } 613 | private: 614 | inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { 615 | return nullptr; 616 | } 617 | inline void* MaybeArenaPtr() const { 618 | return nullptr; 619 | } 620 | public: 621 | 622 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 623 | private: 624 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 625 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_user_2eproto); 626 | return ::descriptor_table_user_2eproto.file_level_metadata[kIndexInFileMessages]; 627 | } 628 | 629 | public: 630 | 631 | // nested types ---------------------------------------------------- 632 | 633 | // accessors ------------------------------------------------------- 634 | 635 | enum : int { 636 | kNameFieldNumber = 1, 637 | }; 638 | // bytes name = 1; 639 | void clear_name(); 640 | const std::string& name() const; 641 | void set_name(const std::string& value); 642 | void set_name(std::string&& value); 643 | void set_name(const char* value); 644 | void set_name(const void* value, size_t size); 645 | std::string* mutable_name(); 646 | std::string* release_name(); 647 | void set_allocated_name(std::string* name); 648 | private: 649 | const std::string& _internal_name() const; 650 | void _internal_set_name(const std::string& value); 651 | std::string* _internal_mutable_name(); 652 | public: 653 | 654 | // @@protoc_insertion_point(class_scope:fixbug.HelloRequest) 655 | private: 656 | class _Internal; 657 | 658 | ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; 659 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; 660 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 661 | friend struct ::TableStruct_user_2eproto; 662 | }; 663 | // ------------------------------------------------------------------- 664 | 665 | class HelloReponse : 666 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:fixbug.HelloReponse) */ { 667 | public: 668 | HelloReponse(); 669 | virtual ~HelloReponse(); 670 | 671 | HelloReponse(const HelloReponse& from); 672 | HelloReponse(HelloReponse&& from) noexcept 673 | : HelloReponse() { 674 | *this = ::std::move(from); 675 | } 676 | 677 | inline HelloReponse& operator=(const HelloReponse& from) { 678 | CopyFrom(from); 679 | return *this; 680 | } 681 | inline HelloReponse& operator=(HelloReponse&& from) noexcept { 682 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 683 | if (this != &from) InternalSwap(&from); 684 | } else { 685 | CopyFrom(from); 686 | } 687 | return *this; 688 | } 689 | 690 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 691 | return GetDescriptor(); 692 | } 693 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 694 | return GetMetadataStatic().descriptor; 695 | } 696 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 697 | return GetMetadataStatic().reflection; 698 | } 699 | static const HelloReponse& default_instance(); 700 | 701 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 702 | static inline const HelloReponse* internal_default_instance() { 703 | return reinterpret_cast( 704 | &_HelloReponse_default_instance_); 705 | } 706 | static constexpr int kIndexInFileMessages = 707 | 4; 708 | 709 | friend void swap(HelloReponse& a, HelloReponse& b) { 710 | a.Swap(&b); 711 | } 712 | inline void Swap(HelloReponse* other) { 713 | if (other == this) return; 714 | InternalSwap(other); 715 | } 716 | 717 | // implements Message ---------------------------------------------- 718 | 719 | inline HelloReponse* New() const final { 720 | return CreateMaybeMessage(nullptr); 721 | } 722 | 723 | HelloReponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 724 | return CreateMaybeMessage(arena); 725 | } 726 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 727 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 728 | void CopyFrom(const HelloReponse& from); 729 | void MergeFrom(const HelloReponse& from); 730 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 731 | bool IsInitialized() const final; 732 | 733 | size_t ByteSizeLong() const final; 734 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 735 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 736 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 737 | int GetCachedSize() const final { return _cached_size_.Get(); } 738 | 739 | private: 740 | inline void SharedCtor(); 741 | inline void SharedDtor(); 742 | void SetCachedSize(int size) const final; 743 | void InternalSwap(HelloReponse* other); 744 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 745 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 746 | return "fixbug.HelloReponse"; 747 | } 748 | private: 749 | inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const { 750 | return nullptr; 751 | } 752 | inline void* MaybeArenaPtr() const { 753 | return nullptr; 754 | } 755 | public: 756 | 757 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 758 | private: 759 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 760 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_user_2eproto); 761 | return ::descriptor_table_user_2eproto.file_level_metadata[kIndexInFileMessages]; 762 | } 763 | 764 | public: 765 | 766 | // nested types ---------------------------------------------------- 767 | 768 | // accessors ------------------------------------------------------- 769 | 770 | enum : int { 771 | kHelloFieldNumber = 2, 772 | }; 773 | // bytes hello = 2; 774 | void clear_hello(); 775 | const std::string& hello() const; 776 | void set_hello(const std::string& value); 777 | void set_hello(std::string&& value); 778 | void set_hello(const char* value); 779 | void set_hello(const void* value, size_t size); 780 | std::string* mutable_hello(); 781 | std::string* release_hello(); 782 | void set_allocated_hello(std::string* hello); 783 | private: 784 | const std::string& _internal_hello() const; 785 | void _internal_set_hello(const std::string& value); 786 | std::string* _internal_mutable_hello(); 787 | public: 788 | 789 | // @@protoc_insertion_point(class_scope:fixbug.HelloReponse) 790 | private: 791 | class _Internal; 792 | 793 | ::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_; 794 | ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr hello_; 795 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 796 | friend struct ::TableStruct_user_2eproto; 797 | }; 798 | // =================================================================== 799 | 800 | class UserServiceRpc_Stub; 801 | 802 | class UserServiceRpc : public ::PROTOBUF_NAMESPACE_ID::Service { 803 | protected: 804 | // This class should be treated as an abstract interface. 805 | inline UserServiceRpc() {}; 806 | public: 807 | virtual ~UserServiceRpc(); 808 | 809 | typedef UserServiceRpc_Stub Stub; 810 | 811 | static const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* descriptor(); 812 | 813 | virtual void Login(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 814 | const ::fixbug::LoginRequest* request, 815 | ::fixbug::LoginResponse* response, 816 | ::google::protobuf::Closure* done); 817 | virtual void Hello(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 818 | const ::fixbug::HelloRequest* request, 819 | ::fixbug::HelloReponse* response, 820 | ::google::protobuf::Closure* done); 821 | 822 | // implements Service ---------------------------------------------- 823 | 824 | const ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor* GetDescriptor(); 825 | void CallMethod(const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method, 826 | ::PROTOBUF_NAMESPACE_ID::RpcController* controller, 827 | const ::PROTOBUF_NAMESPACE_ID::Message* request, 828 | ::PROTOBUF_NAMESPACE_ID::Message* response, 829 | ::google::protobuf::Closure* done); 830 | const ::PROTOBUF_NAMESPACE_ID::Message& GetRequestPrototype( 831 | const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const; 832 | const ::PROTOBUF_NAMESPACE_ID::Message& GetResponsePrototype( 833 | const ::PROTOBUF_NAMESPACE_ID::MethodDescriptor* method) const; 834 | 835 | private: 836 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UserServiceRpc); 837 | }; 838 | 839 | class UserServiceRpc_Stub : public UserServiceRpc { 840 | public: 841 | UserServiceRpc_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel); 842 | UserServiceRpc_Stub(::PROTOBUF_NAMESPACE_ID::RpcChannel* channel, 843 | ::PROTOBUF_NAMESPACE_ID::Service::ChannelOwnership ownership); 844 | ~UserServiceRpc_Stub(); 845 | 846 | inline ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel() { return channel_; } 847 | 848 | // implements UserServiceRpc ------------------------------------------ 849 | 850 | void Login(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 851 | const ::fixbug::LoginRequest* request, 852 | ::fixbug::LoginResponse* response, 853 | ::google::protobuf::Closure* done); 854 | void Hello(::PROTOBUF_NAMESPACE_ID::RpcController* controller, 855 | const ::fixbug::HelloRequest* request, 856 | ::fixbug::HelloReponse* response, 857 | ::google::protobuf::Closure* done); 858 | private: 859 | ::PROTOBUF_NAMESPACE_ID::RpcChannel* channel_; 860 | bool owns_channel_; 861 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UserServiceRpc_Stub); 862 | }; 863 | 864 | 865 | // =================================================================== 866 | 867 | 868 | // =================================================================== 869 | 870 | #ifdef __GNUC__ 871 | #pragma GCC diagnostic push 872 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 873 | #endif // __GNUC__ 874 | // ResultCode 875 | 876 | // int32 errcode = 1; 877 | inline void ResultCode::clear_errcode() { 878 | errcode_ = 0; 879 | } 880 | inline ::PROTOBUF_NAMESPACE_ID::int32 ResultCode::_internal_errcode() const { 881 | return errcode_; 882 | } 883 | inline ::PROTOBUF_NAMESPACE_ID::int32 ResultCode::errcode() const { 884 | // @@protoc_insertion_point(field_get:fixbug.ResultCode.errcode) 885 | return _internal_errcode(); 886 | } 887 | inline void ResultCode::_internal_set_errcode(::PROTOBUF_NAMESPACE_ID::int32 value) { 888 | 889 | errcode_ = value; 890 | } 891 | inline void ResultCode::set_errcode(::PROTOBUF_NAMESPACE_ID::int32 value) { 892 | _internal_set_errcode(value); 893 | // @@protoc_insertion_point(field_set:fixbug.ResultCode.errcode) 894 | } 895 | 896 | // bytes errmsg = 2; 897 | inline void ResultCode::clear_errmsg() { 898 | errmsg_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 899 | } 900 | inline const std::string& ResultCode::errmsg() const { 901 | // @@protoc_insertion_point(field_get:fixbug.ResultCode.errmsg) 902 | return _internal_errmsg(); 903 | } 904 | inline void ResultCode::set_errmsg(const std::string& value) { 905 | _internal_set_errmsg(value); 906 | // @@protoc_insertion_point(field_set:fixbug.ResultCode.errmsg) 907 | } 908 | inline std::string* ResultCode::mutable_errmsg() { 909 | // @@protoc_insertion_point(field_mutable:fixbug.ResultCode.errmsg) 910 | return _internal_mutable_errmsg(); 911 | } 912 | inline const std::string& ResultCode::_internal_errmsg() const { 913 | return errmsg_.GetNoArena(); 914 | } 915 | inline void ResultCode::_internal_set_errmsg(const std::string& value) { 916 | 917 | errmsg_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 918 | } 919 | inline void ResultCode::set_errmsg(std::string&& value) { 920 | 921 | errmsg_.SetNoArena( 922 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 923 | // @@protoc_insertion_point(field_set_rvalue:fixbug.ResultCode.errmsg) 924 | } 925 | inline void ResultCode::set_errmsg(const char* value) { 926 | GOOGLE_DCHECK(value != nullptr); 927 | 928 | errmsg_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 929 | // @@protoc_insertion_point(field_set_char:fixbug.ResultCode.errmsg) 930 | } 931 | inline void ResultCode::set_errmsg(const void* value, size_t size) { 932 | 933 | errmsg_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 934 | ::std::string(reinterpret_cast(value), size)); 935 | // @@protoc_insertion_point(field_set_pointer:fixbug.ResultCode.errmsg) 936 | } 937 | inline std::string* ResultCode::_internal_mutable_errmsg() { 938 | 939 | return errmsg_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 940 | } 941 | inline std::string* ResultCode::release_errmsg() { 942 | // @@protoc_insertion_point(field_release:fixbug.ResultCode.errmsg) 943 | 944 | return errmsg_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 945 | } 946 | inline void ResultCode::set_allocated_errmsg(std::string* errmsg) { 947 | if (errmsg != nullptr) { 948 | 949 | } else { 950 | 951 | } 952 | errmsg_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), errmsg); 953 | // @@protoc_insertion_point(field_set_allocated:fixbug.ResultCode.errmsg) 954 | } 955 | 956 | // ------------------------------------------------------------------- 957 | 958 | // LoginRequest 959 | 960 | // bytes name = 1; 961 | inline void LoginRequest::clear_name() { 962 | name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 963 | } 964 | inline const std::string& LoginRequest::name() const { 965 | // @@protoc_insertion_point(field_get:fixbug.LoginRequest.name) 966 | return _internal_name(); 967 | } 968 | inline void LoginRequest::set_name(const std::string& value) { 969 | _internal_set_name(value); 970 | // @@protoc_insertion_point(field_set:fixbug.LoginRequest.name) 971 | } 972 | inline std::string* LoginRequest::mutable_name() { 973 | // @@protoc_insertion_point(field_mutable:fixbug.LoginRequest.name) 974 | return _internal_mutable_name(); 975 | } 976 | inline const std::string& LoginRequest::_internal_name() const { 977 | return name_.GetNoArena(); 978 | } 979 | inline void LoginRequest::_internal_set_name(const std::string& value) { 980 | 981 | name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 982 | } 983 | inline void LoginRequest::set_name(std::string&& value) { 984 | 985 | name_.SetNoArena( 986 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 987 | // @@protoc_insertion_point(field_set_rvalue:fixbug.LoginRequest.name) 988 | } 989 | inline void LoginRequest::set_name(const char* value) { 990 | GOOGLE_DCHECK(value != nullptr); 991 | 992 | name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 993 | // @@protoc_insertion_point(field_set_char:fixbug.LoginRequest.name) 994 | } 995 | inline void LoginRequest::set_name(const void* value, size_t size) { 996 | 997 | name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 998 | ::std::string(reinterpret_cast(value), size)); 999 | // @@protoc_insertion_point(field_set_pointer:fixbug.LoginRequest.name) 1000 | } 1001 | inline std::string* LoginRequest::_internal_mutable_name() { 1002 | 1003 | return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1004 | } 1005 | inline std::string* LoginRequest::release_name() { 1006 | // @@protoc_insertion_point(field_release:fixbug.LoginRequest.name) 1007 | 1008 | return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1009 | } 1010 | inline void LoginRequest::set_allocated_name(std::string* name) { 1011 | if (name != nullptr) { 1012 | 1013 | } else { 1014 | 1015 | } 1016 | name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name); 1017 | // @@protoc_insertion_point(field_set_allocated:fixbug.LoginRequest.name) 1018 | } 1019 | 1020 | // bytes pwd = 2; 1021 | inline void LoginRequest::clear_pwd() { 1022 | pwd_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1023 | } 1024 | inline const std::string& LoginRequest::pwd() const { 1025 | // @@protoc_insertion_point(field_get:fixbug.LoginRequest.pwd) 1026 | return _internal_pwd(); 1027 | } 1028 | inline void LoginRequest::set_pwd(const std::string& value) { 1029 | _internal_set_pwd(value); 1030 | // @@protoc_insertion_point(field_set:fixbug.LoginRequest.pwd) 1031 | } 1032 | inline std::string* LoginRequest::mutable_pwd() { 1033 | // @@protoc_insertion_point(field_mutable:fixbug.LoginRequest.pwd) 1034 | return _internal_mutable_pwd(); 1035 | } 1036 | inline const std::string& LoginRequest::_internal_pwd() const { 1037 | return pwd_.GetNoArena(); 1038 | } 1039 | inline void LoginRequest::_internal_set_pwd(const std::string& value) { 1040 | 1041 | pwd_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 1042 | } 1043 | inline void LoginRequest::set_pwd(std::string&& value) { 1044 | 1045 | pwd_.SetNoArena( 1046 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 1047 | // @@protoc_insertion_point(field_set_rvalue:fixbug.LoginRequest.pwd) 1048 | } 1049 | inline void LoginRequest::set_pwd(const char* value) { 1050 | GOOGLE_DCHECK(value != nullptr); 1051 | 1052 | pwd_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 1053 | // @@protoc_insertion_point(field_set_char:fixbug.LoginRequest.pwd) 1054 | } 1055 | inline void LoginRequest::set_pwd(const void* value, size_t size) { 1056 | 1057 | pwd_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 1058 | ::std::string(reinterpret_cast(value), size)); 1059 | // @@protoc_insertion_point(field_set_pointer:fixbug.LoginRequest.pwd) 1060 | } 1061 | inline std::string* LoginRequest::_internal_mutable_pwd() { 1062 | 1063 | return pwd_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1064 | } 1065 | inline std::string* LoginRequest::release_pwd() { 1066 | // @@protoc_insertion_point(field_release:fixbug.LoginRequest.pwd) 1067 | 1068 | return pwd_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1069 | } 1070 | inline void LoginRequest::set_allocated_pwd(std::string* pwd) { 1071 | if (pwd != nullptr) { 1072 | 1073 | } else { 1074 | 1075 | } 1076 | pwd_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), pwd); 1077 | // @@protoc_insertion_point(field_set_allocated:fixbug.LoginRequest.pwd) 1078 | } 1079 | 1080 | // ------------------------------------------------------------------- 1081 | 1082 | // LoginResponse 1083 | 1084 | // .fixbug.ResultCode result = 1; 1085 | inline bool LoginResponse::_internal_has_result() const { 1086 | return this != internal_default_instance() && result_ != nullptr; 1087 | } 1088 | inline bool LoginResponse::has_result() const { 1089 | return _internal_has_result(); 1090 | } 1091 | inline void LoginResponse::clear_result() { 1092 | if (GetArenaNoVirtual() == nullptr && result_ != nullptr) { 1093 | delete result_; 1094 | } 1095 | result_ = nullptr; 1096 | } 1097 | inline const ::fixbug::ResultCode& LoginResponse::_internal_result() const { 1098 | const ::fixbug::ResultCode* p = result_; 1099 | return p != nullptr ? *p : *reinterpret_cast( 1100 | &::fixbug::_ResultCode_default_instance_); 1101 | } 1102 | inline const ::fixbug::ResultCode& LoginResponse::result() const { 1103 | // @@protoc_insertion_point(field_get:fixbug.LoginResponse.result) 1104 | return _internal_result(); 1105 | } 1106 | inline ::fixbug::ResultCode* LoginResponse::release_result() { 1107 | // @@protoc_insertion_point(field_release:fixbug.LoginResponse.result) 1108 | 1109 | ::fixbug::ResultCode* temp = result_; 1110 | result_ = nullptr; 1111 | return temp; 1112 | } 1113 | inline ::fixbug::ResultCode* LoginResponse::_internal_mutable_result() { 1114 | 1115 | if (result_ == nullptr) { 1116 | auto* p = CreateMaybeMessage<::fixbug::ResultCode>(GetArenaNoVirtual()); 1117 | result_ = p; 1118 | } 1119 | return result_; 1120 | } 1121 | inline ::fixbug::ResultCode* LoginResponse::mutable_result() { 1122 | // @@protoc_insertion_point(field_mutable:fixbug.LoginResponse.result) 1123 | return _internal_mutable_result(); 1124 | } 1125 | inline void LoginResponse::set_allocated_result(::fixbug::ResultCode* result) { 1126 | ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaNoVirtual(); 1127 | if (message_arena == nullptr) { 1128 | delete result_; 1129 | } 1130 | if (result) { 1131 | ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = nullptr; 1132 | if (message_arena != submessage_arena) { 1133 | result = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( 1134 | message_arena, result, submessage_arena); 1135 | } 1136 | 1137 | } else { 1138 | 1139 | } 1140 | result_ = result; 1141 | // @@protoc_insertion_point(field_set_allocated:fixbug.LoginResponse.result) 1142 | } 1143 | 1144 | // bool success = 2; 1145 | inline void LoginResponse::clear_success() { 1146 | success_ = false; 1147 | } 1148 | inline bool LoginResponse::_internal_success() const { 1149 | return success_; 1150 | } 1151 | inline bool LoginResponse::success() const { 1152 | // @@protoc_insertion_point(field_get:fixbug.LoginResponse.success) 1153 | return _internal_success(); 1154 | } 1155 | inline void LoginResponse::_internal_set_success(bool value) { 1156 | 1157 | success_ = value; 1158 | } 1159 | inline void LoginResponse::set_success(bool value) { 1160 | _internal_set_success(value); 1161 | // @@protoc_insertion_point(field_set:fixbug.LoginResponse.success) 1162 | } 1163 | 1164 | // ------------------------------------------------------------------- 1165 | 1166 | // HelloRequest 1167 | 1168 | // bytes name = 1; 1169 | inline void HelloRequest::clear_name() { 1170 | name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1171 | } 1172 | inline const std::string& HelloRequest::name() const { 1173 | // @@protoc_insertion_point(field_get:fixbug.HelloRequest.name) 1174 | return _internal_name(); 1175 | } 1176 | inline void HelloRequest::set_name(const std::string& value) { 1177 | _internal_set_name(value); 1178 | // @@protoc_insertion_point(field_set:fixbug.HelloRequest.name) 1179 | } 1180 | inline std::string* HelloRequest::mutable_name() { 1181 | // @@protoc_insertion_point(field_mutable:fixbug.HelloRequest.name) 1182 | return _internal_mutable_name(); 1183 | } 1184 | inline const std::string& HelloRequest::_internal_name() const { 1185 | return name_.GetNoArena(); 1186 | } 1187 | inline void HelloRequest::_internal_set_name(const std::string& value) { 1188 | 1189 | name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 1190 | } 1191 | inline void HelloRequest::set_name(std::string&& value) { 1192 | 1193 | name_.SetNoArena( 1194 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 1195 | // @@protoc_insertion_point(field_set_rvalue:fixbug.HelloRequest.name) 1196 | } 1197 | inline void HelloRequest::set_name(const char* value) { 1198 | GOOGLE_DCHECK(value != nullptr); 1199 | 1200 | name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 1201 | // @@protoc_insertion_point(field_set_char:fixbug.HelloRequest.name) 1202 | } 1203 | inline void HelloRequest::set_name(const void* value, size_t size) { 1204 | 1205 | name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 1206 | ::std::string(reinterpret_cast(value), size)); 1207 | // @@protoc_insertion_point(field_set_pointer:fixbug.HelloRequest.name) 1208 | } 1209 | inline std::string* HelloRequest::_internal_mutable_name() { 1210 | 1211 | return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1212 | } 1213 | inline std::string* HelloRequest::release_name() { 1214 | // @@protoc_insertion_point(field_release:fixbug.HelloRequest.name) 1215 | 1216 | return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1217 | } 1218 | inline void HelloRequest::set_allocated_name(std::string* name) { 1219 | if (name != nullptr) { 1220 | 1221 | } else { 1222 | 1223 | } 1224 | name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name); 1225 | // @@protoc_insertion_point(field_set_allocated:fixbug.HelloRequest.name) 1226 | } 1227 | 1228 | // ------------------------------------------------------------------- 1229 | 1230 | // HelloReponse 1231 | 1232 | // bytes hello = 2; 1233 | inline void HelloReponse::clear_hello() { 1234 | hello_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1235 | } 1236 | inline const std::string& HelloReponse::hello() const { 1237 | // @@protoc_insertion_point(field_get:fixbug.HelloReponse.hello) 1238 | return _internal_hello(); 1239 | } 1240 | inline void HelloReponse::set_hello(const std::string& value) { 1241 | _internal_set_hello(value); 1242 | // @@protoc_insertion_point(field_set:fixbug.HelloReponse.hello) 1243 | } 1244 | inline std::string* HelloReponse::mutable_hello() { 1245 | // @@protoc_insertion_point(field_mutable:fixbug.HelloReponse.hello) 1246 | return _internal_mutable_hello(); 1247 | } 1248 | inline const std::string& HelloReponse::_internal_hello() const { 1249 | return hello_.GetNoArena(); 1250 | } 1251 | inline void HelloReponse::_internal_set_hello(const std::string& value) { 1252 | 1253 | hello_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); 1254 | } 1255 | inline void HelloReponse::set_hello(std::string&& value) { 1256 | 1257 | hello_.SetNoArena( 1258 | &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 1259 | // @@protoc_insertion_point(field_set_rvalue:fixbug.HelloReponse.hello) 1260 | } 1261 | inline void HelloReponse::set_hello(const char* value) { 1262 | GOOGLE_DCHECK(value != nullptr); 1263 | 1264 | hello_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 1265 | // @@protoc_insertion_point(field_set_char:fixbug.HelloReponse.hello) 1266 | } 1267 | inline void HelloReponse::set_hello(const void* value, size_t size) { 1268 | 1269 | hello_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), 1270 | ::std::string(reinterpret_cast(value), size)); 1271 | // @@protoc_insertion_point(field_set_pointer:fixbug.HelloReponse.hello) 1272 | } 1273 | inline std::string* HelloReponse::_internal_mutable_hello() { 1274 | 1275 | return hello_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1276 | } 1277 | inline std::string* HelloReponse::release_hello() { 1278 | // @@protoc_insertion_point(field_release:fixbug.HelloReponse.hello) 1279 | 1280 | return hello_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); 1281 | } 1282 | inline void HelloReponse::set_allocated_hello(std::string* hello) { 1283 | if (hello != nullptr) { 1284 | 1285 | } else { 1286 | 1287 | } 1288 | hello_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), hello); 1289 | // @@protoc_insertion_point(field_set_allocated:fixbug.HelloReponse.hello) 1290 | } 1291 | 1292 | #ifdef __GNUC__ 1293 | #pragma GCC diagnostic pop 1294 | #endif // __GNUC__ 1295 | // ------------------------------------------------------------------- 1296 | 1297 | // ------------------------------------------------------------------- 1298 | 1299 | // ------------------------------------------------------------------- 1300 | 1301 | // ------------------------------------------------------------------- 1302 | 1303 | 1304 | // @@protoc_insertion_point(namespace_scope) 1305 | 1306 | } // namespace fixbug 1307 | 1308 | // @@protoc_insertion_point(global_scope) 1309 | 1310 | #include 1311 | #endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_user_2eproto 1312 | --------------------------------------------------------------------------------