getPatternMatchCodec
Call Signature
Returns a codec that selects which variant codec to use based on pattern matching.
This codec evaluates values and byte arrays against a series of predicate functions in order, using the first matching codec for encoding or decoding.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the value to encode. |
TTo | TFrom | The type of the value to decode. |
TSize extends number | number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | FixedSizePatternMatchCodecEntry<TFrom, TFrom, TTo, TSize>[] | An array of [valuePredicate, bytesPredicate, codec] triples. Predicates are tested in order and the first match determines the codec used. During encoding, valuePredicate receives the value to encode. During decoding, bytesPredicate receives the byte array. |
Returns
FixedSizeCodec<TFrom, TTo, TSize>
A codec that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if a value being encoded does not match any of the specified patterns.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_BYTES error if a byte array being decoded does not match any of the specified patterns.
Example
Encoding and decoding using pattern matching.
See
Call Signature
Returns a codec that selects which variant codec to use based on pattern matching.
This codec evaluates values and byte arrays against a series of predicate functions in order, using the first matching codec for encoding or decoding.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the value to encode. |
TTo | TFrom | The type of the value to decode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | FixedSizePatternMatchCodecEntry<TFrom, TFrom, TTo, number>[] | An array of [valuePredicate, bytesPredicate, codec] triples. Predicates are tested in order and the first match determines the codec used. During encoding, valuePredicate receives the value to encode. During decoding, bytesPredicate receives the byte array. |
Returns
FixedSizeCodec<TFrom, TTo>
A codec that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if a value being encoded does not match any of the specified patterns.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_BYTES error if a byte array being decoded does not match any of the specified patterns.
Example
Encoding and decoding using pattern matching.
See
Call Signature
Returns a codec that selects which variant codec to use based on pattern matching.
This codec evaluates values and byte arrays against a series of predicate functions in order, using the first matching codec for encoding or decoding.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the value to encode. |
TTo | TFrom | The type of the value to decode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | VariableSizePatternMatchCodecEntry<TFrom, TFrom, TTo>[] | An array of [valuePredicate, bytesPredicate, codec] triples. Predicates are tested in order and the first match determines the codec used. During encoding, valuePredicate receives the value to encode. During decoding, bytesPredicate receives the byte array. |
Returns
VariableSizeCodec<TFrom, TTo>
A codec that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if a value being encoded does not match any of the specified patterns.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_BYTES error if a byte array being decoded does not match any of the specified patterns.
Example
Encoding and decoding using pattern matching.
See
Call Signature
Returns a codec that selects which variant codec to use based on pattern matching.
This codec evaluates values and byte arrays against a series of predicate functions in order, using the first matching codec for encoding or decoding.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
TFrom | - | The type of the value to encode. |
TTo | TFrom | The type of the value to decode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | PatternMatchCodecEntry<TFrom, TFrom, TTo>[] | An array of [valuePredicate, bytesPredicate, codec] triples. Predicates are tested in order and the first match determines the codec used. During encoding, valuePredicate receives the value to encode. During decoding, bytesPredicate receives the byte array. |
Returns
Codec<TFrom, TTo>
A codec that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if a value being encoded does not match any of the specified patterns.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_BYTES error if a byte array being decoded does not match any of the specified patterns.
Example
Encoding and decoding using pattern matching.