You can follow the detailed example below:
example.proto
IDL above.protoc example.proto --cpp_out=./ --proto_path=./
to get two files: example.pb.h
and example.pb.cpp
.srpc_generator protobuf ./example.proto ./
in SRPC to get example.srpc.h
.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());
}
};