Widen[V: Any val, Msg: Any val]¶
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.
Implements¶
- Codec[Msg] val
Constructors¶
create¶
Parameters¶
- codec: Codec[V] val
- narrow: {(Msg): V ?}[V, Msg] val
Returns¶
- Widen[V, Msg] val^
Public Functions¶
decode¶
Parameters¶
Returns¶
- ((Msg , USize val) | DecodeError)
encode¶
Parameters¶
- value: Msg
Returns¶
- (Array[U8 val] val | EncodeError)