fixEncoderSize
Creates a fixed-size encoder from a given encoder.
The resulting encoder ensures that encoded values always have the specified number of bytes.
If the original encoded value is larger than fixedBytes, it is truncated.
If it is smaller, it is padded with trailing zeroes.
For more details, see fixCodecSize.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The type of the value to encode. |
TSize extends number | The fixed size of the encoded value in bytes. |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | Encoder<TFrom> | The encoder to wrap into a fixed-size encoder. |
fixedBytes | TSize | The fixed number of bytes to write. |
Returns
FixedSizeEncoder<TFrom, TSize>
A FixedSizeEncoder that ensures a consistent output size.
Example
Remarks
If you need a full codec with both encoding and decoding, use fixCodecSize.