datastream/binary

Framing operations on Stream(BitArray).

Real byte sources (sockets, files, pipes) deliver bytes in arbitrary chunks. A frame may straddle chunks, several frames may sit in one chunk, or a chunk may end mid-prefix. Every framing combinator here owns the buffer needed to reassemble.

All combinators are lazy and chunk-boundary-aware; none of them materialises the full input.

Values

pub fn bytes(
  over stream: datastream.Stream(BitArray),
) -> datastream.Stream(Int)

Yield each byte of each chunk in order, as Int in 0..255.

The trivial degenerate framing: bridges from Stream(BitArray) to Stream(Int) so callers can move into the byte-stream-shaped world without writing the per-byte unfold themselves.

pub fn delimited(
  over stream: datastream.Stream(BitArray),
  on delimiter: BitArray,
) -> datastream.Stream(BitArray)

Yield delimiter-separated frames in source order, preserving empty frames between consecutive delimiters and the trailing frame after a trailing delimiter. The delimiter itself is NOT included in any emitted frame.

If the input does not end with a delimiter, the trailing partial frame is emitted as the last element.

pub fn fixed_size(
  over stream: datastream.Stream(BitArray),
  size size: Int,
) -> datastream.Stream(BitArray)

Yield successive size-byte frames in source order. The trailing partial frame on EOF is discarded — by definition a fixed-size framing combinator cannot emit a frame of fewer than size bytes.

size MUST be >= 1. Other values are rejected at construction time with a panic.

pub fn length_prefixed(
  over stream: datastream.Stream(BitArray),
  prefix_size prefix_size: Int,
) -> datastream.Stream(BitArray)

Read a prefix_size byte big-endian unsigned length, then yield the next length bytes as a frame.

prefix_size MUST be one of {1, 2, 4, 8}. Other values are rejected at construction time with a panic.

Incomplete frames at end-of-input (short prefix or short payload) are NOT emitted; the stream simply halts.

Search Document