Expand description
The macro-free typed path: a transport’s wire items, typed by hand.
A generated client builds its streams with MethodStream::call and
call_one. These are the same decoding for a caller
holding a raw ItemStream — a test, a tool that reads a stream the
macro did not generate a client for — with the item type spelled at the
call site:
use futures::TryStreamExt;
use plexus_client::{decode, MemoryTransport, MethodRef, Transport};
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct Tick { n: u32 }
const COUNT: MethodRef = MethodRef::new("demo", "count");
let t = MemoryTransport::new().script_events(COUNT, &[Tick { n: 1 }, Tick { n: 2 }]);
let ticks: Vec<Tick> = futures::executor::block_on(
decode::<Tick>(t.call(COUNT, serde_json::json!({}))).try_collect(),
)
.unwrap();
assert_eq!(ticks, vec![Tick { n: 1 }, Tick { n: 2 }]);The decoding table is method_stream’s.
Functions§
- decode
- A plain-
Tmethod’s items: each data frame’scontentdecodes asI; progress frames are dropped. The stream’s aggregate isIitself (MethodStream::eventsyields the items). - decode_
raw decodeon a typed call’s items (PERF.115-36): each data item’s content decoded straight from the wire’s JSON intoI, never into aValuefirst — what a generated client reads, onTransport::call_raw’s items. A decode error says whatdecodesays of the same content.- decode_
result - A Result method’s items: each data frame’s
contentis{"ok": t}or{"err": e}(wire_result) and decodes asOk(t)/Err(e). AnErris data — the activation saying no — so it does not end the stream. - decode_
with_ progress decode, opted in to progress: items asFrame::Item(i), progress frames decoded asPand yielded asFrame::Progress(p), in arrival order.