alux-jsonrpc-direct
alux-jsonrpc-direct interprets an alux-jsonrpc program as a
JSON-RPC 2.0 message handler. It performs method-name dispatch, parameter decoding, response
rendering, batch handling, notification handling, and protocol error reporting without a framework.
Its only dependencies are serde and serde_json.
use JsonRpcProgramExt;
use DirectImpl;
let rpc = new;
let methods = rpc.compile_jsonrpc?;
let answer = methods.dispatch.await;
assert_eq!;
dispatch answers with nothing when the document asks for nothing — a notification, or a batch of
them. Everything else answers with one response document.
A method marked fallible converts its error into a protocol error through RpcErrorAlg, exactly as
alux-jsonrpc-jsonrpsee does, so the same program and the
same domain compile through either interpretation unchanged.
What it owns, and what it does not
It owns the message layer: a MethodTable maps each method name to its decoded, applied, and rendered
answer. Two tables can be combined with merge when they contain different method names.
It owns no transport and no runtime. A surface answers one request document and says nothing about how
that document arrived, so serving it over HTTP, a WebSocket, a pipe, or a test harness is a separate
decision — and an HTTP surface can be declared with alux-http rather
than bundled in here.
Differences from the jsonrpsee interpretation
- A method's output needs
Serialize, notSerialize + Clone, because no answer is ever duplicated. - Protocol errors are stated by this crate rather than by a framework, so their codes and messages are part of its observable behavior and are covered by its tests.
mergereports a duplicated method name asDuplicateMethodrather than a framework error.