feat(rust): @framing selector for a protocol's connect/serve helpers - #9
Merged
Conversation
A protocol can now declare its wire framing with an annotation:
@framing = "jsonrpc"
protocol Rpc { function now() -> u32; }
The generator reads it off the frozen Protocol.parameters and, for a
non-datagram pick, emits the JSON-RPC stack instead of the hard-wired
datagram one:
- <Proto>Client wraps Client<T, W, comline_runtime::framing::JsonRpcFraming>
- connect() calls Client::connect_with_framing(..)
- <Proto>Dispatcher::serve() calls Server::with_framing(..)
- the Handshake carries framing.name() rather than FRAMING_DATAGRAM
- the Framing trait is added to the generated import list; FRAMING_DATAGRAM
is dropped when no protocol in the file uses it
Absent or unrecognised @framing keeps the datagram default, byte-for-byte
(the conformance goldens are unchanged). No runtime rev bump — the runtime
already ships JsonRpcFraming + the *_with_framing constructors.
tests:
- generate.rs: @framing = "jsonrpc" emits the JsonRpcFraming stack
- compiles.rs: a second schema with a @framing = "jsonrpc" protocol is
compiled against the real runtime alongside the datagram one
Member
Author
|
Framing should likely be at a project's settings level such as comline.toml, this is just for testing |
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.
What
Makes wire framing reachable from a schema. A
protocoldeclares it with an annotation:The Rust generator reads
@framingoff the frozenProtocol.parametersand, for a non-datagram pick, emits the JSON-RPC stack instead of the hard-wired datagram one:@framing = "jsonrpc"<Proto>ClientnewtypeClient<T, W>Client<T, W, comline_runtime::framing::JsonRpcFraming>connect()Client::connect(..)Client::connect_with_framing(.., framing, ..)<Proto>Dispatcher::serve()Server::new(..)Server::with_framing(.., framing)Handshakeframing fieldFRAMING_DATAGRAMframing.name()+ Framing,- FRAMING_DATAGRAMwhen no protocol in the file needs itRecognised values:
jsonrpc,json-rpc,jsonrpc-2.0. Anything absent or unrecognised keeps the datagram default byte-for-byte — the conformance goldens don't move.Why
The handshake,
Framingtrait,JsonRpcFramingimpl, and*_with_framingconstructors all already exist in the runtime; nothing selected them. This is the last piece: a schema-level switch so the generatedconnect/servehelpers aren't pinned to datagram.No
RUNTIME_REVbump — the runtime side is already landed.Tests
generate.rs::framing_annotation_selects_jsonrpc_for_the_connect_and_serve_helpers— string-checks the emitted JSON-RPC stack and the absence of the datagram path.compiles.rs— a second schema carrying a@framing = "jsonrpc"protocol is generated andcargo build-ed against the realcomline-runtimenext to the datagram one.code_mode_generates_enum_and_protocol(asserts the exact datagram imports +Server::new+Client::connect) still passes unchanged.