convert method

  1. @override
Iterable<bool> convert(
  1. String data
)
override

Actual barcode computation method, returns a stream of bool which represents the presence or absence of a bar

Implementation

@override
Iterable<bool> convert(String data) sync* {
  // Start
  yield* add(BarcodeMaps.telepenStart, BarcodeMaps.telepenLen);

  var checksum = 0;

  for (var code in data.codeUnits) {
    if (code >= BarcodeMaps.telepen.length) {
      throw BarcodeException(
          'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
    }
    final codeValue = BarcodeMaps.telepen[code];
    yield* add(codeValue, BarcodeMaps.telepenLen);
    checksum += code;
  }

  // Checksum
  checksum = 127 - (checksum % 127);
  if (checksum == 127) {
    checksum = 0;
  }
  yield* add(BarcodeMaps.telepen[checksum], BarcodeMaps.telepenLen);

  // Stop
  yield* add(BarcodeMaps.telepenEnd, BarcodeMaps.telepenLen);
}