getPredicateCodec
Call Signature
Returns a codec that selects between two codecs based on predicates.
This codec uses boolean predicate functions to determine which of two codecs
to use for encoding and decoding. If the encoding predicate returns true
for a value, the ifTrue codec is used to encode it; otherwise ifFalse.
Similarly, if the decoding predicate returns true for the bytes, the
ifTrue codec is used to decode them.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TTo | The type of the value to decode. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
encodePredicate | (value) => boolean | A function that returns true or false for a given value. |
decodePredicate | (value) => boolean | A function that returns true or false for a given byte array. |
ifTrue | FixedSizeCodec<TFrom, TTo, TSize> | The codec to use when the respective predicate returns true. |
ifFalse | FixedSizeCodec<TFrom, TTo, TSize> | The codec to use when the respective predicate returns false. |
Returns
FixedSizeCodec<TFrom, TTo, TSize>
A Codec based on the provided codecs.
Example
Encoding and decoding small and large numbers differently.
See
Call Signature
Returns a codec that selects between two codecs based on predicates.
This codec uses boolean predicate functions to determine which of two codecs
to use for encoding and decoding. If the encoding predicate returns true
for a value, the ifTrue codec is used to encode it; otherwise ifFalse.
Similarly, if the decoding predicate returns true for the bytes, the
ifTrue codec is used to decode them.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TTo | The type of the value to decode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encodePredicate | (value) => boolean | A function that returns true or false for a given value. |
decodePredicate | (value) => boolean | A function that returns true or false for a given byte array. |
ifTrue | FixedSizeCodec<TFrom, TTo> | The codec to use when the respective predicate returns true. |
ifFalse | FixedSizeCodec<TFrom, TTo> | The codec to use when the respective predicate returns false. |
Returns
FixedSizeCodec<TFrom, TTo>
A Codec based on the provided codecs.
Example
Encoding and decoding small and large numbers differently.
See
Call Signature
Returns a codec that selects between two codecs based on predicates.
This codec uses boolean predicate functions to determine which of two codecs
to use for encoding and decoding. If the encoding predicate returns true
for a value, the ifTrue codec is used to encode it; otherwise ifFalse.
Similarly, if the decoding predicate returns true for the bytes, the
ifTrue codec is used to decode them.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TTo | The type of the value to decode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encodePredicate | (value) => boolean | A function that returns true or false for a given value. |
decodePredicate | (value) => boolean | A function that returns true or false for a given byte array. |
ifTrue | VariableSizeCodec<TFrom, TTo> | The codec to use when the respective predicate returns true. |
ifFalse | VariableSizeCodec<TFrom, TTo> | The codec to use when the respective predicate returns false. |
Returns
VariableSizeCodec<TFrom, TTo>
A Codec based on the provided codecs.
Example
Encoding and decoding small and large numbers differently.
See
Call Signature
Returns a codec that selects between two codecs based on predicates.
This codec uses boolean predicate functions to determine which of two codecs
to use for encoding and decoding. If the encoding predicate returns true
for a value, the ifTrue codec is used to encode it; otherwise ifFalse.
Similarly, if the decoding predicate returns true for the bytes, the
ifTrue codec is used to decode them.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TTo | The type of the value to decode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encodePredicate | (value) => boolean | A function that returns true or false for a given value. |
decodePredicate | (value) => boolean | A function that returns true or false for a given byte array. |
ifTrue | Codec<TFrom, TTo> | The codec to use when the respective predicate returns true. |
ifFalse | Codec<TFrom, TTo> | The codec to use when the respective predicate returns false. |
Returns
Codec<TFrom, TTo>
A Codec based on the provided codecs.
Example
Encoding and decoding small and large numbers differently.