resizeDecoder
Call Signature
resizeDecoder<
TFrom
,TSize
,TNewSize
>(decoder
,resize
):FixedSizeDecoder
<TFrom
,TNewSize
>
Updates the size of a given decoder.
This function modifies the size of a decoder using a provided transformation function.
For fixed-size decoders, it updates the fixedSize
property to reflect the new size.
Variable-size decoders remain unchanged, as their size is determined dynamically.
If the new size is negative, an error will be thrown.
For more details, see resizeCodec.
Type Parameters
Type Parameter | Description |
---|---|
TFrom | - |
TSize extends number | The original fixed size of the decoded value. |
TNewSize extends number | The new fixed size after resizing. |
Parameters
Parameter | Type | Description |
---|---|---|
decoder | FixedSizeDecoder <TFrom , TSize > | The decoder whose size will be updated. |
resize | (size ) => TNewSize | A function that takes the current size and returns the new size. |
Returns
FixedSizeDecoder
<TFrom
, TNewSize
>
A new decoder with the updated size.
Examples
Expanding a u16
decoder to read 4 bytes instead of 2.
Shrinking a u32
decoder to only read 2 bytes.
See
Call Signature
resizeDecoder<
TDecoder
>(decoder
,resize
):TDecoder
Updates the size of a given decoder.
This function modifies the size of a decoder using a provided transformation function.
For fixed-size decoders, it updates the fixedSize
property to reflect the new size.
Variable-size decoders remain unchanged, as their size is determined dynamically.
If the new size is negative, an error will be thrown.
For more details, see resizeCodec.
Type Parameters
Type Parameter |
---|
TDecoder extends AnyDecoder |
Parameters
Parameter | Type | Description |
---|---|---|
decoder | TDecoder | The decoder whose size will be updated. |
resize | (size ) => number | A function that takes the current size and returns the new size. |
Returns
TDecoder
A new decoder with the updated size.
Examples
Expanding a u16
decoder to read 4 bytes instead of 2.
Shrinking a u32
decoder to only read 2 bytes.