Skip to content

feat: pluggable framing — Framing trait + JSON-RPC (7g) - #10

Merged
Kinflou merged 1 commit into
mainfrom
feat/pluggable-framing
Sep 1, 2026
Merged

feat: pluggable framing — Framing trait + JSON-RPC (7g)#10
Kinflou merged 1 commit into
mainfrom
feat/pluggable-framing

Conversation

@Kinflou

@Kinflou Kinflou commented Sep 1, 2026

Copy link
Copy Markdown
Member

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 dispatch / client code runs over JSON-RPC unchanged.

contract::Framing encode/decode request + response; name() folds into the handshake
contract::DatagramFraming the current binary framing, extracted — the top-level wire module is deleted, this is now the one impl of that byte layout
framing::JsonRpcFraming (std) name-oriented: {"jsonrpc":"2.0","method":…,"params":…,"id":N}; a raised schema error → a JSON-RPC error object keyed by ordinal. Pairs with format::Json (new, serde_json)

Contract changes (need a companion codegen PR):

  • Dispatch::dispatchout: &mut dyn BufMutreply: &mut Reply (a framing-agnostic ok / err / none sink) — the datagram Envelope layout 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. 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.

Test

tests/jsonrpc_roundtrip.rs — the identical Greet stub over JsonRpcFraming + 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 the Reply-based Dispatch. All feature configs green (--no-default-features, --features alloc, default); clippy clean.

Next

comline-codegen-rust: emit fn calls(), reply.ok()/reply.err() instead of Envelope::encode_*, Call::new(i, "name") in the client stub, and a framing type param / selector on the generated connect / serve helpers.

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.
@Kinflou
Kinflou merged commit 0dda42d into main Sep 1, 2026
6 checks passed
@Kinflou
Kinflou deleted the feat/pluggable-framing branch September 2, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant