Result constructor

Result(
  1. Edge solution
)

Implementation

Result(Edge solution) {
  final input = solution.input;
  int size = 0;
  final bytesAL = <int>[];
  final randomizePostfixLength = <int>[];
  final randomizeLengths = <int>[];
  if ((solution.mode == Mode.C40 ||
          solution.mode == Mode.TEXT ||
          solution.mode == Mode.X12) &&
      solution.endMode != Mode.ASCII) {
    size += prepend(Edge.getBytes(254), bytesAL);
  }
  Edge? current = solution;
  while (current != null) {
    size += prepend(current.getDataBytes(), bytesAL);

    if (current.previous == null ||
        current.previousStartMode != current.getMode()) {
      if (current.getMode() == Mode.B256) {
        if (size <= 249) {
          bytesAL.insert(0, size);
          size++;
        } else {
          bytesAL.insert(0, (size % 250));
          bytesAL.insert(0, (size ~/ 250 + 249));
          size += 2;
        }
        randomizePostfixLength.add(bytesAL.length);
        randomizeLengths.add(size);
      }
      prepend(current.getLatchBytes(), bytesAL);
      size = 0;
    }

    current = current.previous;
  }
  if (input.macroId == 5) {
    size += prepend(Edge.getBytes(236), bytesAL);
  } else if (input.macroId == 6) {
    size += prepend(Edge.getBytes(237), bytesAL);
  }

  if (input.fnc1Character > 0) {
    size += prepend(Edge.getBytes(232), bytesAL);
  }
  for (int i = 0; i < randomizePostfixLength.length; i++) {
    applyRandomPattern(
      bytesAL,
      bytesAL.length - randomizePostfixLength[i],
      randomizeLengths[i],
    );
  }
  //add padding
  final capacity = solution.getMinSymbolSize(bytesAL.length);
  if (bytesAL.length < capacity) {
    bytesAL.add(129);
  }
  while (bytesAL.length < capacity) {
    bytesAL.add(randomize253State(bytesAL.length + 1));
  }

  _bytes = Uint8List.fromList(bytesAL);
}