split static method
List<UQrDataBlock>
split(
- Uint8List rawCodewords,
- UQrVersion version,
- UQrFormatInformation formatInfo
Implementation
static List<UQrDataBlock> split(Uint8List rawCodewords, UQrVersion version, UQrFormatInformation formatInfo) {
if (rawCodewords.length != version.totalCodewords) throw const UCodeDecodeException("Codeword length mismatch");
final UQrEcBlocks ecBlocks = version.ecBlocks[formatInfo.levelIndex];
final List<UQrDataBlock> result = <UQrDataBlock>[];
for (final UQrEcb block in ecBlocks.blocks) {
for (int i = 0; i < block.count; i++) {
result.add(UQrDataBlock(block.dataCodewords, Uint8List(ecBlocks.ecCodewordsPerBlock + block.dataCodewords)));
}
}
final int numResultBlocks = result.length;
final int shorterBlocksTotalCodewords = result.first.codewords.length;
int longerBlocksStartAt = numResultBlocks - 1;
while (longerBlocksStartAt >= 0) {
if (result[longerBlocksStartAt].codewords.length == shorterBlocksTotalCodewords) break;
longerBlocksStartAt--;
}
longerBlocksStartAt++;
final int shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ecCodewordsPerBlock;
int rawCodewordsOffset = 0;
for (int i = 0; i < shorterBlocksNumDataCodewords; i++) {
for (int j = 0; j < numResultBlocks; j++) {
result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
}
}
for (int j = longerBlocksStartAt; j < numResultBlocks; j++) {
result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];
}
final int max = result.first.codewords.length;
for (int i = shorterBlocksNumDataCodewords; i < max; i++) {
for (int j = 0; j < numResultBlocks; j++) {
final int iOffset = j < longerBlocksStartAt ? i : i + 1;
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
}
}
return result;
}