decode method
returns decoded data
or throw ReedSolomonException if data cannot be decoded
Implementation
List<int> decode(List<int> data) {
if (data.length > this._galoisField.size - 1) {
throw ReedSolomonException(
'message is too long, ${data.length} when max is ${this._galoisField.size - 1}');
}
GFPolynomial poly = GFPolynomial(this._galoisField, data);
GFPolynomial synd = this._calculateSyndromes(poly);
if (synd.isZero) return data.sublist(0, data.length - this._eccCount);
GFPolynomial correctedData =
this._correctError(GFPolynomial(this._galoisField, data), synd);
synd = this._calculateSyndromes(correctedData);
if (synd.isZero)
return correctedData.coefficients
.sublist(0, data.length - this._eccCount);
throw ReedSolomonException('Data cannot be decoded');
}