pub struct FrameCodec { /* private fields */ }Expand description
A configured framing codec.
Stateless beyond the configured max_frame_bytes
bound: encode and decode operate on
one frame at a time and hold no connection state (handshake sequencing
is crate::handshake::HandshakeGate’s job, not the codec’s).
Implementations§
Source§impl FrameCodec
impl FrameCodec
Sourcepub const fn new(max_frame_bytes: usize) -> Self
pub const fn new(max_frame_bytes: usize) -> Self
A codec with the given maximum frame size (the JSON payload length, not counting the 4-byte prefix).
pub const fn max_frame_bytes(&self) -> usize
Sourcepub fn encode(&self, frame: &Frame) -> Result<Vec<u8>, CodecError>
pub fn encode(&self, frame: &Frame) -> Result<Vec<u8>, CodecError>
Encode one frame as a complete length-prefixed wire buffer: 4-byte BE length followed by the JSON payload, guarded by this codec’s own configured maximum so encode and decode share one bound.
Sourcepub fn decode(&self, buf: &[u8]) -> Result<Frame, CodecError>
pub fn decode(&self, buf: &[u8]) -> Result<Frame, CodecError>
Decode one complete length-prefixed frame from buf.
buf must contain at least the full frame (prefix + payload); this
function does not support partial/streaming input. Bytes in buf
beyond the decoded frame, if any, are ignored — a transport that
reads a stream is responsible for slicing exactly one frame’s bytes
(using the length prefix) before calling this, or for using
decode_with_consumed to learn where
the decoded frame ends.
Sourcepub fn decode_with_consumed(
&self,
buf: &[u8],
) -> Result<(Frame, usize), CodecError>
pub fn decode_with_consumed( &self, buf: &[u8], ) -> Result<(Frame, usize), CodecError>
Decode one complete length-prefixed frame from buf and report the
number of bytes consumed: the 4-byte length prefix plus the
declared payload length. The remainder buf[consumed..] — if any —
is the next frame’s bytes, letting a transport split a buffered
stream into frames without re-parsing the length prefix itself.
The frame itself is decoded exactly as decode.