bytes static method

Implementation

static BcsType<Uint8List,Uint8List> bytes(int size, [BcsTypeOptions<Uint8List, Iterable<int>>? options]) {
  return fixedSizeBcsType<Uint8List,Uint8List>(
    name: 'bytes[$size]',
    size: size,
    read: (reader) => reader.readBytes(size),
    write: (value, writer) {
      for (int i = 0; i < size; i++) {
        writer.write8(value.elementAt(i));
      }
    },
    validate: (value) {
      options?.validate?.call(value);
      if (value.length != size) {
        throw ArgumentError('Expected Iterable of length $size, found ${value.length}');
      }
    },
  );
}