Skip to main content

Module codec

Module codec 

Source
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§

FrameCodec
A configured framing codec.

Enums§

CodecError
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, or crate::error::WireErrorCode::FrameTooLarge — canonically via wire_code (and the From<&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 u32 frame-length prefix, in bytes.

Functions§

decode_frame
Decode one complete length-prefixed frame from buf against an explicit max_frame_bytes bound. See FrameCodec::decode for the contract.
decode_frame_with_consumed
Decode one complete length-prefixed frame from buf and report the number of bytes consumed: LENGTH_PREFIX_BYTES plus 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_frame is this function with the consumed count discarded.
encode_frame
Encode one frame as a complete length-prefixed wire buffer, using DEFAULT_MAX_FRAME_BYTES as the encode-side size guard.
encode_frame_with_max
Encode one frame against an explicit max_frame_bytes bound.