plushie/transport/framing

Frame encoding and decoding for the plushie wire protocol.

Transports that deliver raw byte streams need framing logic. This module provides it for both MessagePack (4-byte length prefix) and JSONL (newline delimiter) modes.

Transports with built-in framing (e.g. Erlang Ports with {packet, 4}) don’t need this module.

Values

pub fn decode_lines(
  buffer: BitArray,
) -> #(List(BitArray), BitArray)

Split a buffer on newline boundaries. Returns complete lines and any remaining partial line.

pub fn decode_packets(
  buffer: BitArray,
) -> #(List(BitArray), BitArray)

Extract complete length-prefixed frames from a buffer. Returns the decoded messages and any remaining partial data.

pub fn encode_line(data: BitArray) -> BitArray

Encode a message with a newline terminator.

pub fn encode_packet(data: BitArray) -> BitArray

Encode a message with a 4-byte big-endian length prefix.

Search Document