* Given data and error-correction codewords received, possibly corrupted by errors, attempts to * correct the errors in-place using Reed-Solomon error correction. * * @param codewordBytes data and error correction codewords * @param numDataCodewords number of codewords that are data bytes * @return false if error correction fails */
| 369 | * @return false if error correction fails |
| 370 | */ |
| 371 | static bool |
| 372 | CorrectErrors(ByteArray& codewordBytes, int numDataCodewords) |
| 373 | { |
| 374 | // First read into an array of ints |
| 375 | std::vector<int> codewordsInts(codewordBytes.begin(), codewordBytes.end()); |
| 376 | int numECCodewords = Size(codewordBytes) - numDataCodewords; |
| 377 | |
| 378 | if (!ReedSolomonDecode(GenericGF::DataMatrixField256(), codewordsInts, numECCodewords)) |
| 379 | return false; |
| 380 | |
| 381 | // Copy back into array of bytes -- only need to worry about the bytes that were data |
| 382 | // We don't care about errors in the error-correction codewords |
| 383 | std::copy_n(codewordsInts.begin(), numDataCodewords, codewordBytes.begin()); |
| 384 | |
| 385 | return true; |
| 386 | } |
| 387 | |
| 388 | static DecoderResult DoDecode(const BitMatrix& bits) |
| 389 | { |
no test coverage detected