encode method

void encode(
  1. List<int> toEncode,
  2. int ecBytes
)

Implementation

void encode(List<int> toEncode, int ecBytes) {
  if (ecBytes == 0) {
    throw ArgumentError('No error correction bytes');
  }
  final dataBytes = toEncode.length - ecBytes;
  if (dataBytes <= 0) {
    throw ArgumentError('No data bytes provided');
  }
  final generator = _buildGenerator(ecBytes);
  final infoCoefficients = Int32List(dataBytes);
  List.copyRange(infoCoefficients, 0, toEncode, 0, dataBytes);
  GenericGFPoly info = GenericGFPoly(_field, infoCoefficients);
  info = info.multiplyByMonomial(ecBytes, 1);
  final remainder = info.divide(generator)[1];
  final coefficients = remainder.coefficients;
  final numZeroCoefficients = ecBytes - coefficients.length;
  for (int i = 0; i < numZeroCoefficients; i++) {
    toEncode[dataBytes + i] = 0;
  }
  List.copyRange(
    toEncode,
    dataBytes + numZeroCoefficients,
    coefficients,
    0,
    coefficients.length,
  );
}