feat: pluggable framing — Framing trait + JSON-RPC (7g) - #10
Merged
Conversation
The framing axis (how a call becomes bytes and back) is now a trait,
orthogonal to WireFormat (which serialises the parts). Client<T, W, F> and
Server<D, W, F> are generic over one, defaulting to the Comline datagram
framing -- the same call/dispatch code runs over JSON-RPC unchanged.
- contract::Framing -- encode/decode request + response; carries name()
for the handshake.
- contract::DatagramFraming -- the current binary framing, extracted
(top-level `wire` module deleted; DatagramFraming is the one impl of
that byte layout now).
- framing::JsonRpcFraming (std) -- name-oriented, `{"jsonrpc":"2.0",
"method":...,"params":...,"id":N}`; a raised schema error maps to a
JSON-RPC error object keyed by ordinal. Pairs with format::Json (new,
serde_json).
- Dispatch: `out: &mut dyn BufMut` -> `reply: &mut Reply` (framing-agnostic
ok/err/none sink) + a `calls()` method so a name can be resolved to an
ordinal. Kind is unchanged; Server always hands the dispatcher Kind::Id.
- Client::call takes `impl Into<Call>` -- a bare u16 for datagram-only
callers, `Call::new(id, name)` from a generated stub.
- Client/Server: `with_framing` / `connect_with_framing` constructors.
tests/jsonrpc_roundtrip.rs: the identical Greet stub over JsonRpcFraming +
Json -- a call, a typed error, and a byte check
(`{"jsonrpc":"2.0","method":"hello",...}`). All existing roundtrip tests
updated to the Reply-based Dispatch; all feature configs green.
Generated dispatchers need the new signature -- a companion codegen PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The framing axis — how a call becomes bytes and back — is now a trait, orthogonal to
WireFormat(which serialises the parts).Client<T, W, F>andServer<D, W, F>are generic over one, defaulting to the Comline datagram framing. The same dispatch / client code runs over JSON-RPC unchanged.contract::Framingname()folds into the handshakecontract::DatagramFramingwiremodule is deleted, this is now the one impl of that byte layoutframing::JsonRpcFraming(std){"jsonrpc":"2.0","method":…,"params":…,"id":N}; a raised schema error → a JSON-RPCerrorobject keyed by ordinal. Pairs withformat::Json(new,serde_json)Contract changes (need a companion codegen PR):
Dispatch::dispatch—out: &mut dyn BufMut→reply: &mut Reply(a framing-agnostic ok / err / none sink) — the datagramEnvelopelayout is no longer baked into every dispatcher.Dispatch::calls() -> &'static [&'static str]— so a name-oriented framing's method can be resolved to an ordinal.Kindis unchanged;Serveralways hands the dispatcherKind::Id.Client::calltakesimpl Into<Call>— a bareu16for datagram-only callers,Call::new(id, name)from a generated stub.Client/Server:with_framing/connect_with_framingconstructors.Test
tests/jsonrpc_roundtrip.rs— the identicalGreetstub overJsonRpcFraming+Json: a call, a typed raised error, and a byte assertion ({"jsonrpc":"2.0","method":"hello","params":{"name":"x"},"id":0}). Every existing roundtrip test updated to theReply-basedDispatch. All feature configs green (--no-default-features,--features alloc, default); clippy clean.Next
comline-codegen-rust: emitfn calls(),reply.ok()/reply.err()instead ofEnvelope::encode_*,Call::new(i, "name")in the client stub, and a framing type param / selector on the generatedconnect/servehelpers.