Module binary

Module binary 

Source
Expand description

Binary TLV codec (varint + frames) for LogLine Workspace.

Provides:

  • Varint (u64): base-128 encoding with MSB as continuation bit
  • TLV: Tag (u8) + optional Length (varint) + Value (bytes)
  • Frames: typ (u8) + len (varint) + payload

Fixed-size types (CID32, PUBKEY32, SIG64) don’t carry length (known size).

§Security Limits

  • MAX_FRAME_LEN: Hard limit on frame payload (~1 MiB) to prevent DoS
  • MAX_VARINT_BYTES: Maximum bytes for varint encoding (10) to prevent overflow

Structs§

Decoder
Binary TLV decoder.
Encoder
Binary TLV encoder.

Enums§

BinaryCodecError
Errors from binary codec operations.

Constants§

MAX_BYTES_LEN
Maximum bytes for variable-length TLV fields (same as frame limit).
MAX_FRAME_LEN
Hard limit for frame payload size (~1 MiB). Prevents memory exhaustion DoS.
MAX_VARINT_BYTES
Maximum bytes for a varint-encoded u64 (ceil(64/7) = 10).
T_BYTES
Tag for variable-length bytes.
T_CID32
Tag for 32-byte CID (BLAKE3).
T_PUBKEY32
Tag for 32-byte Ed25519 public key.
T_SIG64
Tag for 64-byte Ed25519 signature.
T_STR
Tag for UTF-8 string.
T_U64
Tag for varint-encoded u64.

Functions§

decode_frame
Decodes a frame, returning (typ, payload).
decode_varint_u64
Decodes a base-128 varint from input starting at pos, advancing pos.
encode_frame
Encodes a frame: typ (u8) + len (varint) + payload.
encode_varint_u64
Encodes a u64 as a base-128 varint, appending to out.