decode static method

DecoderResult decode(
  1. Uint8List bytes,
  2. int mode
)

Implementation

static DecoderResult decode(Uint8List bytes, int mode) {
  final result = StringBuilder();
  switch (mode) {
    case 2:
    case 3:
      String postcode;
      if (mode == 2) {
        final pc = _getPostCode2(bytes);
        final ps2Length = _getPostCode2Length(bytes);
        if (ps2Length > 10) {
          throw FormatsException.instance;
        }
        postcode = pc.toString().padLeft(math.min(10, ps2Length), '0');
      } else {
        postcode = _getPostCode3(bytes);
      }
      // NumberFormat threeDigits = DecimalFormat("000");
      final country = _getCountry(bytes).toString().padLeft(3, '0');
      final service = _getServiceClass(bytes).toString().padLeft(3, '0');
      result.write(_getMessage(bytes, 10, 84));
      if (result.toString().startsWith('[)>${_rs}01$_gs')) {
        result.insert(9, postcode + _gs + country + _gs + service + _gs);
      } else {
        result.insert(0, postcode + _gs + country + _gs + service + _gs);
      }
      break;
    case 4:
      result.write(_getMessage(bytes, 1, 93));
      break;
    case 5:
      result.write(_getMessage(bytes, 1, 77));
      break;
  }
  return DecoderResult(bytes, result.toString(), null, (mode).toString());
}