crc static method

int crc(
  1. Uint8List data,
  2. int offset,
  3. int length
)

Calculate CRC16 checksum for a byte array

Implementation

static int crc(Uint8List data, int offset, int length) {
  if (offset < 0) {
    throw ArgumentError('Offset cannot be negative');
  }
  if (length < 0) {
    throw ArgumentError('Length cannot be negative');
  }
  if (offset + length > data.length) {
    throw ArgumentError('Offset + length exceeds array bounds');
  }

  int crc = 0;

  for (int i = offset; i < offset + length; i++) {
    int b = data[i] & 0xFF;
    int index = ((crc >> 8) ^ b) & 0xFF;
    crc = ((crc << 8) ^ _table[index]) & 0xFFFF;
  }

  return crc;
}