Expand description
The length-prefixed framing codec.
One wire frame is a 4-byte big-endian u32 length prefix followed by
that many bytes of JSON, matching the existing Unix-domain-socket framing
this crate remains base-compatible with (crates/khive-runtime/src/daemon.rs,
read_frame/write_frame). This crate defines what the JSON payload
inside that framing is; it performs no I/O itself — decode_frame and
encode_frame operate on in-memory byte slices, and a transport crate
is responsible for reading/writing those bytes from a socket and for
buffering partial reads until a complete frame is available.
Structs§
- Frame
Codec - A configured framing codec.
Enums§
- Codec
Error - A codec failure, distinguishing every frame-level case this crate can
identify. Every variant maps onto the wire error taxonomy —
crate::error::WireErrorCode::MalformedFrame,crate::error::WireErrorCode::Internal, orcrate::error::WireErrorCode::FrameTooLarge— canonically viawire_code(and theFrom<&CodecError>impl), so servers need no hand-maintained mapping; this crate keeps the finer-grained variant so a caller (including a test) can assert the specific failure rather than only “decoding failed”.
Constants§
- DEFAULT_
MAX_ FRAME_ BYTES - Default maximum frame size: 8 MiB.
- LENGTH_
PREFIX_ BYTES - Length of the big-endian
u32frame-length prefix, in bytes.
Functions§
- decode_
frame - Decode one complete length-prefixed frame from
bufagainst an explicitmax_frame_bytesbound. SeeFrameCodec::decodefor the contract. - decode_
frame_ with_ consumed - Decode one complete length-prefixed frame from
bufand report the number of bytes consumed:LENGTH_PREFIX_BYTESplus the declared payload length. Bytes beyond the consumed prefix — if any — belong to the next frame, letting a transport split a buffered stream into frames without re-parsing the length prefix itself.decode_frameis this function with the consumed count discarded. - encode_
frame - Encode one frame as a complete length-prefixed wire buffer, using
DEFAULT_MAX_FRAME_BYTESas the encode-side size guard. - encode_
frame_ with_ max - Encode one frame against an explicit
max_frame_bytesbound.