resizeCodec
Call Signature
resizeCodec<
TFrom
,TTo
,TSize
,TNewSize
>(codec
,resize
):FixedSizeCodec
<TFrom
,TTo
,TNewSize
>
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
Type Parameter | Description |
---|---|
TFrom | The type of the value to encode. |
TTo | The type of the decoded value. |
TSize extends number | The original fixed size of the encoded/decoded value (for fixed-size codecs). |
TNewSize extends number | The new fixed size after resizing (for fixed-size codecs). |
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
resizeCodec<
TCodec
>(codec
,resize
):TCodec
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
Type Parameter |
---|
TCodec extends AnyCodec |
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.