decode static method
Implementation
static UQrDecodeResult decode(List<int> codewords) {
final StringBuffer result = StringBuffer();
final List<int> byteSegments = <int>[];
int? eci;
int index = 0;
while (index < codewords.length) {
final int code = codewords[index++];
switch (code) {
case _textCompactionModeLatch:
index = _textCompaction(codewords, index, result);
break;
case _byteCompactionModeLatch:
case _byteCompactionModeLatch6:
index = _byteCompaction(codewords, index, result, byteSegments);
break;
case _modeShiftToByteCompaction:
if (index < codewords.length) {
final int value = codewords[index++] % 256;
result.writeCharCode(value);
byteSegments.add(value);
}
break;
case _numericCompactionModeLatch:
index = _numericCompaction(codewords, index, result);
break;
case _eciCharset:
if (index < codewords.length) eci = codewords[index++];
break;
case _beginMacroControlBlock:
case _beginMacroOptionalField:
case _macroTerminator:
index = codewords.length;
break;
default:
index = _textCompaction(codewords, index - 1, result);
break;
}
}
final String text = result.toString();
return UQrDecodeResult(text: text, bytes: byteSegments.isNotEmpty ? Uint8List.fromList(byteSegments) : Uint8List.fromList(utf8.encode(text)), eci: eci);
}