Skip to content

Codec[A: Any val]

[Source]

A bidirectional codec that decodes bytes into a value and encodes a value into bytes.

Codecs are val — immutable and shareable across actors. Small codecs compose into larger ones via combinators like Seq2, Mapped, and FlatZip.

decode takes an array and a bit offset, returning either the decoded value paired with the number of bits consumed, or a DecodeError. The array is val so byte-slice codecs like Bytes can return zero-copy views via Array.trim.

encode converts a value to bytes, returning either the encoded bytes or an EncodeError.

trait val Codec[A: Any val]

Public Functions

decode

[Source]

Decode a value from data starting at the given bit offset.

fun box decode(
  data: Array[U8 val] val,
  offset: USize val)
: ((A , USize val) | DecodeError)

Parameters

Returns


encode

[Source]

fun box encode(
  value: A)
: (Array[U8 val] val | EncodeError)

Parameters

  • value: A

Returns