getPatternMatchEncoder
Call Signature
Returns an encoder that selects which variant encoder to use based on pattern matching.
This encoder evaluates the value against a series of predicate functions in order, and uses the first matching encoder to encode the value.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TSize extends number | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | FixedSizePatternMatchEncoderEntry<TFrom, TFrom, TSize>[] | An array of [predicate, encoder] pairs. Predicates are tested in order and the first matching encoder is used to encode the value. Note that predicates can be either type predicates that narrow the type of the value, or boolean predicates. If using type predicates, the encoder can be for the narrowed type. |
Returns
FixedSizeEncoder<TFrom, TSize>
An encoder that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if the value does not match any of the specified patterns.
Example
Encoding values using pattern matching.
See
Call Signature
Returns an encoder that selects which variant encoder to use based on pattern matching.
This encoder evaluates the value against a series of predicate functions in order, and uses the first matching encoder to encode the value.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | FixedSizePatternMatchEncoderEntry<TFrom, TFrom, number>[] | An array of [predicate, encoder] pairs. Predicates are tested in order and the first matching encoder is used to encode the value. Note that predicates can be either type predicates that narrow the type of the value, or boolean predicates. If using type predicates, the encoder can be for the narrowed type. |
Returns
FixedSizeEncoder<TFrom>
An encoder that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if the value does not match any of the specified patterns.
Example
Encoding values using pattern matching.
See
Call Signature
Returns an encoder that selects which variant encoder to use based on pattern matching.
This encoder evaluates the value against a series of predicate functions in order, and uses the first matching encoder to encode the value.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | VariableSizePatternMatchEncoderEntry<TFrom, TFrom>[] | An array of [predicate, encoder] pairs. Predicates are tested in order and the first matching encoder is used to encode the value. Note that predicates can be either type predicates that narrow the type of the value, or boolean predicates. If using type predicates, the encoder can be for the narrowed type. |
Returns
VariableSizeEncoder<TFrom>
An encoder that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if the value does not match any of the specified patterns.
Example
Encoding values using pattern matching.
See
Call Signature
Returns an encoder that selects which variant encoder to use based on pattern matching.
This encoder evaluates the value against a series of predicate functions in order, and uses the first matching encoder to encode the value.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
Parameters
| Parameter | Type | Description |
|---|---|---|
patterns | PatternMatchEncoderEntry<TFrom, TFrom>[] | An array of [predicate, encoder] pairs. Predicates are tested in order and the first matching encoder is used to encode the value. Note that predicates can be either type predicates that narrow the type of the value, or boolean predicates. If using type predicates, the encoder can be for the narrowed type. |
Returns
Encoder<TFrom>
An encoder that selects the appropriate variant based on the matched pattern.
Throws
Throws a SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE error if the value does not match any of the specified patterns.
Example
Encoding values using pattern matching.