Expand description
Framed stdio transport for bytes-only named component contracts.
An executable stays alive for its component’s lifetime. Stdin and stdout carry only frames;
stderr is inherited for diagnostics. A timeout or protocol failure that leaves the connection
unusable terminates and reaps the child; the connection is then respawned from the verified
executable on a later call, up to the manager’s restart budget, re-running the describe
validation and the host’s session setup (SidecarSessionSetup) each time. Producer status
failures leave the connection usable.
The host starts the child with STDIO_PROTOCOLS_ENV listing the protocol versions it speaks
(1,2). The first request is always a protocol-1 JSON frame: a four-byte little-endian
unsigned JSON byte length, followed by {"op":"describe"}. Its successful response payload
contains JSON matching StdioDescriptor, checked against the verified artifact’s manifest.
The descriptor’s protocol_version selects the framing of every later frame:
- Protocol 1 (
STDIO_PROTOCOL_VERSION): JSON envelopes,{"op":"call","contract":"name","method":"name","payload":[0,255]}answered by{"status":0,"payload":[0,255]}, with payloads as JSON byte arrays. Calls are serialized across all contracts sharing the executable, and a timeout is fatal. - Protocol 2 (
STDIO_BINARY_PROTOCOL_VERSION): binary frames (frame) carrying raw payload bytes and a request id. A protocol-2 descriptor may addmax_in_flight(default 1): the host pipelines up to that many unanswered requests and the sidecar may answer them in any order. A timeout abandons only its own request (a late response is dropped) unless the sidecar answered nothing during the whole deadline, which is fatal.
Status codes use AlefStatus semantics; a nonzero status carries error message bytes. The wire
format is specified in docs/design/component-stdio-binary-protocol.md.
This transport supports crate::LoadedComponent::invoke_bytes. Arbitrary generated C
function tables cannot be represented across a process boundary: typed table access and
typed instance creation return an explicit unsupported-transport error.
Re-exports§
pub use frame::BINARY_FRAME_MAGIC;pub use frame::BINARY_FRAME_PREFIX_LEN;pub use frame::BinaryFrame;pub use frame::BinaryFrameKind;pub use frame::MAX_BINARY_HEADER_SIZE;pub use frame::RESPONSE_HEADER_LEN;pub use frame::decode_call_header;pub use frame::decode_response_header;pub use frame::encode_binary_frame;pub use frame::encode_call_header;pub use frame::encode_response_header;pub use frame::read_binary_frame;pub use frame::write_binary_frame;
Modules§
- frame
- Binary frames of stdio protocol 2. The byte layout is specified in
docs/design/component-stdio-binary-protocol.md; this module is its reference implementation.
Structs§
- Sidecar
Session - One stdio connection as seen by a host’s session setup: a
SidecarSessionSetupreceives it once a sidecar child has started and passed describe validation, and callsSidecarSession::invoketo re-establish whatever session the host had built on the previous connection. - Stdio
Descriptor - Metadata returned as JSON inside the successful
describeresponse payload. A protocol-2 descriptor may also carrymax_in_flight, which the runtime reads separately so this type stays exactly the protocol-1 shape. - Stdio
Response - A response envelope, using the component ABI’s integer status codes.
Enums§
- Stdio
Request - A request envelope. A producer must answer exactly once for every request.
Constants§
- MAX_
FRAME_ SIZE - Largest JSON body of a protocol-1 frame, and largest payload of a protocol-2 frame.
- STDIO_
BINARY_ PROTOCOL_ VERSION - The binary-frame protocol: raw payload bytes, request ids, optional pipelining.
- STDIO_
PROTOCOLS_ ENV - Environment variable the host sets on the child: the comma-separated protocol versions it
speaks. A sidecar declares protocol 2 only when this lists
2, so it still serves older hosts. - STDIO_
PROTOCOL_ VERSION - The JSON-envelope protocol every sidecar speaks for
describe, and for every later frame when its descriptor declares this version.
Functions§
- read_
frame - Read one complete bounded frame. EOF, including between frames, is an error.
- write_
frame - Write and flush one bounded frame.
Type Aliases§
- Sidecar
Restart Event - Handler called with the component id and the new restart count after each successful stdio
respawn (see
crate::ComponentManager::with_sidecar_restart_event). - Sidecar
Session Setup - Host-provided setup for a stdio sidecar connection, replayed after the first spawn and after
every respawn of the connection (see
crate::ComponentManager::with_sidecar_session).