resizeEncoder
Call Signature
Updates the size of a given encoder.
This function modifies the size of an encoder using a provided transformation function.
For fixed-size encoders, it updates the fixedSize property, and for variable-size
encoders, it adjusts the size calculation based on the encoded value.
If the new size is negative, an error will be thrown.
For more details, see resizeCodec.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TSize extends number | The original fixed size of the encoded value. |
TNewSize extends number | The new fixed size after resizing. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | FixedSizeEncoder<TFrom, TSize> | The encoder whose size will be updated. |
resize | (size) => TNewSize | A function that takes the current size and returns the new size. |
Returns
FixedSizeEncoder<TFrom, TNewSize>
A new encoder with the updated size.
Examples
Increasing the size of a u16 encoder by 2 bytes.
Shrinking a u32 encoder to only use 2 bytes.
See
Call Signature
Updates the size of a given encoder.
This function modifies the size of an encoder using a provided transformation function.
For fixed-size encoders, it updates the fixedSize property, and for variable-size
encoders, it adjusts the size calculation based on the encoded value.
If the new size is negative, an error will be thrown.
For more details, see resizeCodec.
Type Parameters
| Type Parameter |
|---|
TEncoder extends AnyEncoder |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | TEncoder | The encoder whose size will be updated. |
resize | (size) => number | A function that takes the current size and returns the new size. |
Returns
TEncoder
A new encoder with the updated size.
Examples
Increasing the size of a u16 encoder by 2 bytes.
Shrinking a u32 encoder to only use 2 bytes.