encode method
returns encoded data
or throw ReedSolomonException if data cannot be encoded
Implementation
List<int> encode(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 dataPolynomial =
GFPolynomial(this._galoisField, data.reversed.toList());
GFPolynomial remainder =
dataPolynomial.divide(this._polynomialGenerator)[1];
List<int> message = List<int>.filled(this._eccCount, 0);
int numZero = this._eccCount - remainder.length;
message.setAll(numZero, remainder.coefficients);
return message.reversed.toList();
}