NwFramer

class NwFramer(maxFrameSize: Int = DEFAULT_MAX_FRAME_SIZE)

Stateful, incremental decoder for the 4-byte-big-endian-length-prefixed frame format produced by encodeFrame (wire-compatible with :kuilt-stream's framed()).

Push-based, unlike framed()'s pull-based Source.readInt/readByteArray: feed arbitrary byte chunks — as delivered off the wire, e.g. from NwApi.bytesReceived — to decode, which returns whichever frames that chunk completed. A chunk may contain a partial frame, exactly one frame, several frames, or a frame split across many chunks; bytes that don't yet complete a frame are buffered internally and carried forward to the next decode call.

Single-reader contract: NwFramer holds mutable buffer state and is deliberately NOT thread-safe — it is designed to be driven by a single reader coroutine (one NwFramer per connection, fed serially from that connection's receive path). Do not call decode concurrently or share one instance across connections.

Constructors

Link copied to clipboard
constructor(maxFrameSize: Int = DEFAULT_MAX_FRAME_SIZE)

Functions

Link copied to clipboard

Feed the next chunk of bytes off the wire. Returns the frames this chunk completed, in order (possibly empty). Throws FrameTooLargeException before allocating the payload if a decoded length prefix is negative or exceeds maxFrameSize.