resizeDecoder<T> function
Updates the size of a given decoder using a resize function.
For fixed-size decoders, the fixedSize is updated.
Variable-size decoders are returned unchanged since their size is
determined dynamically.
Throws a SolanaError if the new size is negative.
Implementation
Decoder<T> resizeDecoder<T>(Decoder<T> decoder, int Function(int size) resize) {
return switch (decoder) {
FixedSizeDecoder<T>() => () {
final newFixedSize = resize(decoder.fixedSize);
if (newFixedSize < 0) {
throw SolanaError(SolanaErrorCode.codecsExpectedPositiveByteLength, {
'bytesLength': newFixedSize,
'codecDescription': 'resizeDecoder',
});
}
return FixedSizeDecoder<T>(fixedSize: newFixedSize, read: decoder.read);
}(),
VariableSizeDecoder<T>() => decoder,
};
}