getPredicateDecoder
Returns a decoder that selects between two decoders based on a predicate.
This decoder uses a boolean predicate function on the raw bytes to determine
which of two decoders to use. If the predicate returns true, the ifTrue
decoder is used; otherwise, the ifFalse decoder is used.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TTo | any | The type of the value to decode. |
TIfTrue extends Decoder<TTo> | Decoder<TTo> | - |
TIfFalse extends Decoder<TTo> | Decoder<TTo> | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
predicate | (value) => boolean | A function that returns true or false for a given byte array. |
ifTrue | TIfTrue | The decoder to use when the predicate returns true. |
ifFalse | SameType<TIfTrue extends Decoder<TFrom> ? TFrom : never, TIfFalse extends Decoder<TFrom> ? TFrom : never> & TIfFalse | The decoder to use when the predicate returns false. |
Returns
GetUnionDecoderType<readonly [TIfTrue, TIfFalse]>
A Decoder based on the provided decoders.
Example
Decoding small and large numbers based on byte length.