distribute/codec/composite

Values

pub fn option(
  inner: codec.Codec(a),
) -> codec.Codec(option.Option(a))
pub fn option_decoder(
  inner: fn(BitArray) -> Result(a, codec.DecodeError),
) -> fn(BitArray) -> Result(option.Option(a), codec.DecodeError)

Strict top-level Option(a) decoder. None is one byte (0) followed by EOF; Some(a) is 1 followed by a’s encoded form.

The earlier <<0, _:bytes>> pattern matched a None tag plus any number of trailing bytes, mirroring the smuggling vector that we closed inside tuple2/tuple3. The Some branch is already strict because inner is itself a top-level Decoder(a) (built via to_decoder).

pub fn option_encoder(
  inner: fn(a) -> Result(BitArray, codec.EncodeError),
) -> fn(option.Option(a)) -> Result(BitArray, codec.EncodeError)

Encoder for Option(a). None is 0x00, Some(v) is 0x01 + encoded value.

pub fn option_sized_decoder(
  inner: fn(BitArray) -> Result(#(a, BitArray), codec.DecodeError),
) -> fn(BitArray) -> Result(
  #(option.Option(a), BitArray),
  codec.DecodeError,
)
pub fn result(
  ok_codec: codec.Codec(a),
  error_codec: codec.Codec(e),
) -> codec.Codec(Result(a, e))
pub fn result_decoder(
  ok_decoder: fn(BitArray) -> Result(a, codec.DecodeError),
  error_decoder: fn(BitArray) -> Result(e, codec.DecodeError),
) -> fn(BitArray) -> Result(Result(a, e), codec.DecodeError)
pub fn result_encoder(
  ok_encoder: fn(a) -> Result(BitArray, codec.EncodeError),
  error_encoder: fn(e) -> Result(BitArray, codec.EncodeError),
) -> fn(Result(a, e)) -> Result(BitArray, codec.EncodeError)

Encoder for Result(a, e). Ok is 0x00 + encoded, Error is 0x01 + encoded.

pub fn result_sized_decoder(
  ok_decoder: fn(BitArray) -> Result(
    #(a, BitArray),
    codec.DecodeError,
  ),
  error_decoder: fn(BitArray) -> Result(
    #(e, BitArray),
    codec.DecodeError,
  ),
) -> fn(BitArray) -> Result(
  #(Result(a, e), BitArray),
  codec.DecodeError,
)
pub fn tuple2(
  first: codec.Codec(a),
  second: codec.Codec(b),
) -> codec.Codec(#(a, b))
pub fn tuple2_decoder(
  first: fn(BitArray) -> Result(#(a, BitArray), codec.DecodeError),
  second: fn(BitArray) -> Result(
    #(b, BitArray),
    codec.DecodeError,
  ),
) -> fn(BitArray) -> Result(#(a, b), codec.DecodeError)
pub fn tuple2_encoder(
  first: fn(a) -> Result(BitArray, codec.EncodeError),
  second: fn(b) -> Result(BitArray, codec.EncodeError),
) -> fn(#(a, b)) -> Result(BitArray, codec.EncodeError)

Encoder for #(a, b). First element is length-prefixed (32-bit).

The length prefix is validated against the unsigned-32 bound. A first element larger than 4 GiB would silently truncate the prefix and corrupt the wire frame. Mirrors the bound enforced by string_encoder / bitarray_encoder / list_encoder / subject_encoder / tagged.encoder.

pub fn tuple2_sized_decoder(
  first: fn(BitArray) -> Result(#(a, BitArray), codec.DecodeError),
  second: fn(BitArray) -> Result(
    #(b, BitArray),
    codec.DecodeError,
  ),
) -> fn(BitArray) -> Result(
  #(#(a, b), BitArray),
  codec.DecodeError,
)
pub fn tuple3(
  first: codec.Codec(a),
  second: codec.Codec(b),
  third: codec.Codec(c),
) -> codec.Codec(#(a, b, c))
pub fn tuple3_decoder(
  first: fn(BitArray) -> Result(#(a, BitArray), codec.DecodeError),
  second: fn(BitArray) -> Result(
    #(b, BitArray),
    codec.DecodeError,
  ),
  third: fn(BitArray) -> Result(#(c, BitArray), codec.DecodeError),
) -> fn(BitArray) -> Result(#(a, b, c), codec.DecodeError)
pub fn tuple3_encoder(
  first: fn(a) -> Result(BitArray, codec.EncodeError),
  second: fn(b) -> Result(BitArray, codec.EncodeError),
  third: fn(c) -> Result(BitArray, codec.EncodeError),
) -> fn(#(a, b, c)) -> Result(BitArray, codec.EncodeError)

Encoder for #(a, b, c). First two elements are length-prefixed (32-bit).

Both length prefixes are validated against the unsigned-32 bound; see tuple2_encoder for the rationale.

pub fn tuple3_sized_decoder(
  first: fn(BitArray) -> Result(#(a, BitArray), codec.DecodeError),
  second: fn(BitArray) -> Result(
    #(b, BitArray),
    codec.DecodeError,
  ),
  third: fn(BitArray) -> Result(#(c, BitArray), codec.DecodeError),
) -> fn(BitArray) -> Result(
  #(#(a, b, c), BitArray),
  codec.DecodeError,
)
Search Document