The aim is to build a minimal protobuf RPC lib using Google's Protocol Buffers.
libpbrpc is flexible as it is not bound to the http server, it's a lightweight middleware.
The only dependency is Protocol Buffers.
To use this lib is really simple. First define ServiceManager
some where in your code.
ServiceManager srvMan;
Then the ServiceManager
only provides two functions:
-
Register a service:
void regService(Service *service);
-
Handle the RPC message:
void handleRPC(const char *data, const size_t len, string &ret);
data
is the raw Protobuf binary,len
is the length of the data,ret
is the result generated, you can send it back directly. (Note: use ret.length() to get the correct length.)
The over all design is really simple:
- Protocol. The RPC protocol is defined in the "pbrpc.proto" file. The protocol took the JSON RPC 2.0 as a reference.
Service
s. The RPC server provides severalService
s, and eachService
has someMethod
s.Method
s. EachMethod
should have input(params
) and output(results
).
Please take a look of my other repository pbrpc as a demo which implements a simple RPC server.
One major limitation of this library is it's synchronous. It is possible to adapt task queue for asynchronous message handling.