Skip to main content

Module document

Module document 

Source
Expand description

The documents a client writes, and the one it reads back.

§This is a mirror, not a second encoder

A stdio client and a stdio server speak the same wire format, and the server’s half of it is reply. The two modules cannot be merged — one is a driving adapter, one is a driven one, and a client crate that cannot build a reply has no business knowing how — but they are one format with one shape, and this one is kept deliberately beside its counterpart: the members are inserted through serde_json::Map, so jsonrpc, id, method and params serialise in the same order they always have, and a server reading a client request sees what it would see from any other client.

§The id is re-escaped, not debug-printed

RequestId::to_json is the wrong one-liner here for the same reason reply says so: Debug for a string is escape_debug, which writes DEL as \u{7f} — Rust syntax, and not a legal JSON escape. So the id is handed to serde_json as a Value, which escapes it the way WireId::to_json does, for the same reason, and a peer that chose an id full of control characters gets its own id back rather than a parse error against its own request.

§A reply is matched by id, not taken on faith

reply_result is given the id the request went out with and refuses a frame that answers a different one. A stdio server is free to send notifications and server-initiated requests on the same stream the replies arrive on, so the first frame after a request is not automatically that request’s answer — and a client that assumed it was would hand its caller somebody else’s result.

A frame that is not a reply at all is RequestError::NotAnObject or RequestError::MissingResult, not a silent skip. On stdio, stdout is the protocol; a peer that puts anything else there has broken it, and the useful thing to do with that is say so.

Enums§

RequestError
Why a document could not be built, or a frame could not be read as one.

Functions§

notification_document
The notification document, ready to frame.
reply_result
The result out of a reply frame, if that frame is this request’s answer.
request_document
The request document, ready to frame.