getPatternMatchDecoder
Returns a decoder that selects which variant decoder to use based on pattern matching.
This decoder evaluates the byte array against a series of predicate functions in order, and uses the first matching decoder to decode the value.
Type Parameters
| Type Parameter |
|---|
TPatterns extends readonly PatternMatchDecoderEntry<any>[] |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | TPatterns | An array of [predicate, decoder] pairs. Predicates are tested in order and the first matching decoder is used to decode the byte array. |
Returns
GetUnionDecoderType<GetPatternMatchDecoders<TPatterns>>
A decoder that selects the appropriate variant based on the matched byte pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_BYTES error if the byte array does not match any of the specified patterns.
Example
Decoding values using pattern matching on bytes.