resizeCodec<TFrom, TTo> function

Codec<TFrom, TTo> resizeCodec<TFrom, TTo>(
  1. Codec<TFrom, TTo> codec,
  2. int resize(
    1. int size
    )
)

Updates the size of a given codec using a resize function.

For fixed-size codecs, both the encoder and decoder sizes are updated. For variable-size codecs, only the encoder size is updated.

Throws a SolanaError if the new size is negative.

Implementation

Codec<TFrom, TTo> resizeCodec<TFrom, TTo>(
  Codec<TFrom, TTo> codec,
  int Function(int size) resize,
) {
  return combineCodec(
    resizeEncoder(encoderFromCodec(codec), resize),
    resizeDecoder(decoderFromCodec(codec), resize),
  );
}