JSON RPC 2.0 server and client, part of RoboPLC project.
Description
Ultra-lightweight JSON RPC 2.0 server and client library. Fully generic implementation, no runtime dispatching, maximum performance and exhaustiveness.
Protocol-agnostic, can be used with any transport layer.
Note: batch requests are not supported as used pretty never in practice. In
case if you really need them, submit an issue/pull request.
Example
Client
use ;
use ;
// use tag = "method", content = "params" for the canonical JSON-RPC 2.0
let client: = new;
let req = client.request.unwrap;
// send req.payload() via the chosen transport to the server
// if response is received, get the result
// let result = client.handle_response(&response); // returns MyResult or RpcError
Server
use ;
use ;
// use the same types as in the client, e.g. share a common crate
let server = new;
// get the request from the transport
let request_payload = r#"{"i":1,"m":"hello","p":{"name":"world"}}"#.as_bytes;
if let Some = server.
Canonical/minimalistic JSON-RPC 2.0
By default the crate works in a "minimalistic" mode:
-
jsonrpcfield is not required in the request/response, the version is never checked. -
id,methodandparamsrequest fields are renamed toi,mandprespectively. -
id,resultanderrorresponse fields are renamed toi,randerespectively.
The mode can be changed to JSON-RPC 2.0 canonical by enabling the canonical
feature.
Features
std- std support (enabled by default).msgpack- enables MessagePack serialization support.http- certain tools for HTTP transport (calls via HTTP GET, minimalistic responses).canonical- enable canonical JSON-RPC 2.0
no-std
This library is no_std compatible. Use --no-default-features to disable std support.
heapless::String is used for strings instead of the standard one (for error messages).
Limitations:
- Request id can be
u32only. - Provides data types only, no client/server implementations.
- Error messages can be 128 bytes long only.
MSRV
1.68.0