getConstantEncoder function

FixedSizeEncoder<void> getConstantEncoder(
  1. Uint8List constant
)

Returns an encoder that always writes a predefined constant byte sequence.

This encoder ensures that encoding always produces the specified byte array, ignoring any input values.

Implementation

FixedSizeEncoder<void> getConstantEncoder(Uint8List constant) {
  return FixedSizeEncoder<void>(
    fixedSize: constant.length,
    write: (_, bytes, offset) {
      bytes.setAll(offset, constant);
      return offset + constant.length;
    },
  );
}