CrcConfiguration constructor

CrcConfiguration({
  1. required BinaryPolynomial polynomial,
  2. BigInt? initialValue,
  3. bool reflectInput = false,
  4. bool reflectOutput = false,
  5. BigInt? finalXor,
  6. BigInt? check,
  7. BigInt? residue,
})

Creates a custom CRC configuration.

Implementation

CrcConfiguration({
  required this.polynomial,
  BigInt? initialValue,
  this.reflectInput = false,
  this.reflectOutput = false,
  BigInt? finalXor,
  this.check,
  this.residue,
})  : initialValue = initialValue ?? BigInt.zero,
      finalXor = finalXor ?? BigInt.zero {
  if (polynomial.degree <= 0 || !polynomial.coefficient(0)) {
    throw RohdHclException(
      'CRC polynomial must have positive degree and a non-zero constant.',
    );
  }
  for (final (name, value) in [
    ('initialValue', this.initialValue),
    ('finalXor', this.finalXor),
    ('check', check),
    ('residue', residue),
  ]) {
    if (value != null && (value.isNegative || value > mask)) {
      throw RohdHclException(
        'CRC $name $value does not fit in $width bits.',
      );
    }
  }
}