Skip to content

Widen[V: Any val, Msg: Any val]

[Source]

Widen a codec's type from a specific variant V to a broader union Msg.

On decode, the narrower value is returned as Msg (since V is a subtype of Msg). On encode, the narrowing function attempts to cast Msg back to V; if the cast fails, encoding errors.

class val Widen[V: Any val, Msg: Any val] is
  Codec[Msg] val

Implements


Constructors

create

[Source]

new val create(
  codec: Codec[V] val,
  narrow: {(Msg): V ?}[V, Msg] val)
: Widen[V, Msg] val^

Parameters

  • codec: Codec[V] val
  • narrow: {(Msg): V ?}[V, Msg] val

Returns


Public Functions

decode

[Source]

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

Parameters

Returns


encode

[Source]

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

Parameters

  • value: Msg

Returns