resizeCodec
Call Signature
Updates the size of a given codec.
This function modifies the size of both the codec using a provided transformation function. It is useful for adjusting the allocated byte size for encoding and decoding without altering the underlying data structure.
If the new size is negative, an error will be thrown.
Type Parameters
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | FixedSizeCodec<TFrom, TTo, TSize> | The codec whose size will be updated. |
resize | (size) => TNewSize | A function that takes the current size and returns the new size. |
Returns
FixedSizeCodec<TFrom, TTo, TNewSize>
A new codec with the updated size.
Examples
Expanding a u16 codec from 2 to 4 bytes.
Shrinking a u32 codec to only use 2 bytes.
Remarks
If you only need to resize an encoder, use resizeEncoder. If you only need to resize a decoder, use resizeDecoder.
See
Call Signature
Updates the size of a given codec.
This function modifies the size of both the codec using a provided transformation function. It is useful for adjusting the allocated byte size for encoding and decoding without altering the underlying data structure.
If the new size is negative, an error will be thrown.
Type Parameters
Parameters
| Parameter | Type | Description |
|---|---|---|
codec | TCodec | The codec whose size will be updated. |
resize | (size) => number | A function that takes the current size and returns the new size. |
Returns
TCodec
A new codec with the updated size.
Examples
Expanding a u16 codec from 2 to 4 bytes.
Shrinking a u32 codec to only use 2 bytes.
Remarks
If you only need to resize an encoder, use resizeEncoder. If you only need to resize a decoder, use resizeDecoder.