Skip to content

VariableSize[A: Any val]

[Source]

Length-prefixed data: a size codec determines how many bytes the body codec reads from. The size field is structural — it does not appear in the decoded type.

On decode: read the size, then decode the body from exactly that many bytes. On encode: encode the body, measure it, write the size, then the body.

class val VariableSize[A: Any val] is
  Codec[A] val

Implements


Constructors

create

[Source]

new val create(
  size_codec: Codec[U16 val] val,
  body_codec: Codec[A] val)
: VariableSize[A] val^

Parameters

Returns


Public Functions

decode

[Source]

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