tapDecoderBytes
Observes the raw bytes of a decoder before it decodes them, without modifying them.
This function takes an existing decoder and returns a new decoder of the exact same type that
calls the provided tap function with the byte array before each value is read. The bytes are
provided as a ReadonlyUint8Array and are passed through unchanged, making this useful for
adding validation guards, logging, or other read-only side effects on the raw bytes.
If the tap function throws, the decoding is aborted and the error propagates to the caller.
Type Parameters
| Type Parameter | Description |
|---|---|
TDecoder extends AnyDecoder | The type of the decoder being tapped. The returned decoder has the same type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
decoder | TDecoder | The decoder whose raw bytes should be observed. |
tap | (bytes, offset) => void | A function called with the byte array and offset before reading. It may throw to abort decoding. |
Returns
TDecoder
A new decoder of the same type that observes its raw bytes.
Throws
Whatever error the tap function throws, aborting the decoding.
Example
Guarding the raw bytes of a boolean decoder.
Remarks
To observe the decoded value instead of the raw bytes, use tapDecoder.