decode static method

DecoderResult decode(
  1. List<int> codewords,
  2. String ecLevel
)

Implementation

static DecoderResult decode(List<int> codewords, String ecLevel) {
  final result = ECIStringBuilder();
  // Get compaction mode
  int codeIndex = _textCompaction(codewords, 1, result);
  final resultMetadata = PDF417ResultMetadata();
  while (codeIndex < codewords[0]) {
    final code = codewords[codeIndex++];
    switch (code) {
      case _TEXT_COMPACTION_MODE_LATCH:
        codeIndex = _textCompaction(codewords, codeIndex, result);
        break;
      case _BYTE_COMPACTION_MODE_LATCH:
      case _BYTE_COMPACTION_MODE_LATCH_6:
        codeIndex = _byteCompaction(code, codewords, codeIndex, result);
        break;
      case _MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
        result.writeCharCode(codewords[codeIndex++]);
        break;
      case _NUMERIC_COMPACTION_MODE_LATCH:
        codeIndex = _numericCompaction(codewords, codeIndex, result);
        break;
      case _ECI_CHARSET:
        result.appendECI(codewords[codeIndex++]);
        break;
      case _ECI_GENERAL_PURPOSE:
        // Can't do anything with generic ECI; skip its 2 characters
        codeIndex += 2;
        break;
      case _ECI_USER_DEFINED:
        // Can't do anything with user ECI; skip its 1 character
        codeIndex++;
        break;
      case _BEGIN_MACRO_PDF417_CONTROL_BLOCK:
        codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
        break;
      case _BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
      case _MACRO_PDF417_TERMINATOR:
        // Should not see these outside a macro block
        throw FormatsException.instance;
      default:
        // Default to text compaction. During testing numerous barcodes
        // appeared to be missing the starting mode. In these cases defaulting
        // to text compaction seems to work.
        codeIndex--;
        codeIndex = _textCompaction(codewords, codeIndex, result);
        break;
    }
  }
  if (result.isEmpty && resultMetadata.fileId == null) {
    throw FormatsException.instance;
  }
  final decoderResult = DecoderResult(null, result.toString(), null, ecLevel);
  decoderResult.other = resultMetadata;
  return decoderResult;
}