Crate workflow_rpc
source ·Expand description
//!
async Rust-centric RPC framework supporting a custom high-performance Borsh
and an extended JSON-RPC
protocols.
Features:
- High-performance Borsh message encoding protocol
- RPC method and notification handler declarations based on serializable generics
- Client to Server RPC method invocation
- Client to Server notification messages
- Server to Client notification messages
- Server-side handshake scaffolding for custom connection negotiation
- Easy to retain connection data structure for posting async client notifications
This framework provides server
and client
modules. The server infrastructure is built on top of
Tokio and Tungtenite and
provides scaffolding for connection handshake negotiation.
The client is built on top of Workflow WebSocket and
operates uniformly in native applications and in the browser WASM environment. For native applications
Workflow Websocket uses Tokio and Tungstenite and in the browser environment it uses the browser
WebSocket
object.
§Client-side
ⓘ
interface.notification(
TestOps::Notify,
notification!(|notification: TestNotify| async move {
// handle notification
Ok(())
}),
);
let resp: MyResponse = rpc.call(MyOps::MyMethod, MethodRequest { ... }).await?;
§Server-side
ⓘ
interface.method(
TestOps::SomeRequest,
method!(|connection_ctx, server_ctx, request: TestReq| async move {
// handle request and return a response
Ok(SomeResponse { })
}),
);
interface.notification(
TestOps::Notify,
notification!(
|connection_ctx, server_ctx, notification: TestNotify| async move {
// handle notification
Ok(())
}
),
);
Modules§
- RPC client (operates uniformly in native and WASM-browser environments).
- Module containing a helper
Encoding
enum use in RPC server constructors. - RPC message serialization module (header serialization and deserialization for
Borsh
andJSON
data structures) - Result enum encapsulating
super::error::Error
enum common to client and server - RPC server module (native only). This module encapsulates server-side types used to create an RPC server:
RpcServer
,RpcHandler
,Messenger
,Interface
and the protocol handlers:BorshProtocol
andJsonProtocol
. - Trait constraints for RPC methods (Ops) and message (Req,Resp,Msg).