offsetEncoder
Moves the offset of a given encoder before and/or after encoding.
This function allows an encoder to write its encoded value at a different offset than the one originally provided. It supports both pre-offset adjustments (before encoding) and post-offset adjustments (after encoding).
The pre-offset function determines where encoding should start, while the post-offset function adjusts where the next encoder should continue writing.
For more details, see offsetCodec.
Type Parameters
| Type Parameter |
|---|
TEncoder extends AnyEncoder |
Parameters
| Parameter | Type | Description |
|---|---|---|
encoder | TEncoder | The encoder to adjust. |
config | OffsetConfig | An object specifying how the offset should be modified. |
Returns
TEncoder
A new encoder with adjusted offsets.
Examples
Moving the pre-offset forward by 2 bytes.
Moving the post-offset forward by 2 bytes.
Using wrapBytes to ensure an offset wraps around the byte array length.
Remarks
If you need both encoding and decoding offsets to be adjusted, use offsetCodec.