feat: consumer-side Client + a TCP transport (rollout step 7e) - #5
Merged
Conversation
The mirror of 7d's Server, and a real stream transport under it.
- client Client<T, W> -- owns a Transport + a WireFormat, hands out
request ids, reuses its send / recv buffers. call(call_id,
¶ms) encodes straight into the frame header (no params
scratch), sends, blocks for the response, and returns
(Envelope, &W) -- both views out of one &mut self borrow, so the
generated stub can decode Ok as R or map an Err ordinal without
reaching back into the client. One outstanding call at a time;
pipelining is a later, additive layer.
- transport Tcp -- a Transport over a TCP byte stream. No message
boundaries on a stream, so each frame gets a u32 LE length
prefix; recv reads exactly one and rejects a prefix over
MAX_FRAME (16 MiB) before allocating. new() wraps an accepted
stream, connect() dials.
- wire encode_request_header split out of encode_request, so a client
frames the header then serializes params into the same buffer.
tests/client_roundtrip.rs: a Greet protocol (with a raised schema error)
driven through a Client-backed stub against a Server -- once over InMemory,
once over loopback Tcp -- plus a check that back-to-back Tcp frames keep
their boundaries.
Client is alloc-gated (Vec buffers), like serve / transport; Tcp is
std-gated, like InMemory. All feature configs green: cargo test (13 lib + 3
client + 3 dispatch + 1 serve), --no-default-features (2), --features alloc
(9). Warnings unchanged (1, the pre-existing abi_stable macro lint).
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.
Follows #4 — the mirror of 7d's
Server, and a real stream transport under it.clientClient<T, W>— owns aTransport+ aWireFormat, hands out request ids, reuses its send / recv buffers.call(call_id, ¶ms)frames the header, serializes params straight in after it (no scratch buffer), sends, blocks for the response, and returns(Envelope<'_>, &W)— both views out of one&mut selfborrow, so the generated stub decodesOkasRor maps anErrordinal without reaching back into the client. One outstanding call at a time; pipelining is a later, additive layer.transportTcp— aTransportover a TCP byte stream. A stream has no message boundaries, so every frame gets au32LE length prefix;recvreads exactly one and rejects a prefix overMAX_FRAME(16 MiB) before allocating.Tcp::newwraps an accepted stream,Tcp::connectdials.wireencode_request_headersplit out ofencode_requestso a client can frame the header then encode params into the same buffer.tests/client_roundtrip.rs— aGreetprotocol (with a raised schema error) driven through aClient-backed stub against aServer, once overInMemoryand once over loopbackTcp, plus a check that back-to-backTcpframes keep their boundaries.Clientisalloc-gated (Vecbuffers) likeserve/transport;Tcpisstd-gated likeInMemory.Verified
All feature configs green:
cargo test(13 lib + 3 client + 3 dispatch + 1 serve),--no-default-features(2),--features alloc(9). Warnings unchanged (1 — the pre-existingabi_stablemacro lint).Next (7f)
Fold JSON-RPC back in as a framing option (name-oriented
Kind,{jsonrpc, method, params, id}envelope) selectable under the sameClient/Server; then the async (std) layer.