encodeECC200 static method
Creates the ECC200 error correction for an encoded message.
@param codewords the codewords @param symbolInfo information about the symbol to be encoded @return the codewords with interleaved error correction.
Implementation
static String encodeECC200(String codewords, SymbolInfo symbolInfo) {
if (codewords.length != symbolInfo.dataCapacity) {
throw ArgumentError(
'The number of codewords does not match the selected symbol',
);
}
final sb = StringBuilder();
sb.write(codewords);
final blockCount = symbolInfo.interleavedBlockCount;
if (blockCount == 1) {
final ecc = _createECCBlock(codewords, symbolInfo.errorCodewords);
sb.write(ecc);
} else {
sb.setLength(symbolInfo.dataCapacity + symbolInfo.errorCodewords);
// this is using for temp StringBuffer's init length
//List<int> dataSizes = List.generate(blockCount, (index) => symbolInfo.getDataLengthForInterleavedBlock(index + 1));
final errorSizes = List.generate(
blockCount,
(index) => symbolInfo.getErrorLengthForInterleavedBlock(index + 1),
);
for (int block = 0; block < blockCount; block++) {
final temp = StringBuffer();
for (int d = block; d < symbolInfo.dataCapacity; d += blockCount) {
temp.write(codewords[d]);
}
final ecc = _createECCBlock(temp.toString(), errorSizes[block]);
int pos = 0;
for (int e = block;
e < errorSizes[block] * blockCount;
e += blockCount) {
sb.setCharAt(symbolInfo.dataCapacity + e, ecc[pos++]);
}
}
}
return sb.toString();
}