createDecoderThatConsumesEntireByteArray
Create a Decoder that asserts that the bytes provided to decode
or read
are fully consumed by the inner decoder
Type Parameters
Type Parameter | Description |
---|---|
T | The type of the decoder |
Parameters
Parameter | Type | Description |
---|---|---|
decoder | Decoder <T > | A decoder to wrap |
Returns
Decoder
<T
>
A new decoder that will throw if provided with a byte array that it does not fully consume
Remarks
Note that this compares the offset after encoding to the length of the input byte array
The offset
parameter to decode
and read
is still considered, and will affect the new offset that is compared to the byte array length
The error that is thrown by the returned decoder is a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_DECODER_TO_CONSUME_ENTIRE_BYTE_ARRAY
Example
Create a decoder that decodes a u32
(4 bytes) and ensures the entire byte array is consumed