getConstantDecoder function
Returns a decoder that verifies a predefined constant byte sequence.
This decoder reads the next bytes and checks that they match the provided
constant. If the bytes differ, it throws an error.
Implementation
FixedSizeDecoder<void> getConstantDecoder(Uint8List constant) {
return FixedSizeDecoder<void>(
fixedSize: constant.length,
read: (bytes, offset) {
if (!containsBytes(bytes, constant, offset)) {
// Build hex strings inline to avoid dependency on codecs_strings.
final hexConstant = _toHex(constant);
final hexData = _toHex(bytes);
throw SolanaError(SolanaErrorCode.codecsInvalidConstant, {
'hexConstant': hexConstant,
'hexData': hexData,
'offset': offset,
});
}
return (null, offset + constant.length);
},
);
}