1 Star 0 Fork 51

ryvius_key / srpc

forked from 搜狗开源 / srpc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tutorial-02-service.md 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
liyingxin 提交于 2021-06-20 22:25 . update docs

中文版

RPC Service

  • It is the basic unit for sogouRPC services.
  • Each service must be generated by one type of IDLs.
  • Service is determined by IDL type, not by specific network communication protocol.

Sample

You can follow the detailed example below:

  • Use the same example.proto IDL above.
  • Run the official protoc example.proto --cpp_out=./ --proto_path=./ to get two files: example.pb.h and example.pb.cpp.
  • Run the srpc_generator protobuf ./example.proto ./ in SogouRPC to get example.srpc.h.
  • Derive Example::Service to implement the rpc business logic, which is an RPC Service.
  • Please note that this Service does not involve any concepts such as network, port, communication protocol, etc., and it is only responsible for completing the business logic that convert EchoRequest to EchoResponse.
class ExampleServiceImpl : public Example::Service
{
public:
    void Echo(EchoRequest *request, EchoResponse *response, RPCContext *ctx) override
    {
        response->set_message("Hi, " + request->name());

        printf("get_req:\n%s\nset_resp:\n%s\n",
                request->DebugString().c_str(),
                response->DebugString().c_str());
    }
};
C++
1
https://gitee.com/ryvius_key/srpc.git
git@gitee.com:ryvius_key/srpc.git
ryvius_key
srpc
srpc
master

搜索帮助