encode method
Implementation
@override
void encode(EncoderContext context) {
//step B
final n = HighLevelEncoder.determineConsecutiveDigitCount(
context.message,
context.pos,
);
if (n >= 2) {
context.writeCodeword(
_encodeASCIIDigits(
context.message.codeUnitAt(context.pos),
context.message.codeUnitAt(context.pos + 1),
),
);
context.pos += 2;
} else {
final c = context.currentChar;
final newMode = HighLevelEncoder.lookAheadTest(
context.message,
context.pos,
encodingMode,
);
if (newMode != encodingMode) {
switch (newMode) {
case HighLevelEncoder.BASE256_ENCODATION:
context.writeCodeword(HighLevelEncoder.LATCH_TO_BASE256);
context.signalEncoderChange(HighLevelEncoder.BASE256_ENCODATION);
return;
case HighLevelEncoder.C40_ENCODATION:
context.writeCodeword(HighLevelEncoder.LATCH_TO_C40);
context.signalEncoderChange(HighLevelEncoder.C40_ENCODATION);
return;
case HighLevelEncoder.X12_ENCODATION:
context.writeCodeword(HighLevelEncoder.LATCH_TO_ANSIX12);
context.signalEncoderChange(HighLevelEncoder.X12_ENCODATION);
break;
case HighLevelEncoder.TEXT_ENCODATION:
context.writeCodeword(HighLevelEncoder.LATCH_TO_TEXT);
context.signalEncoderChange(HighLevelEncoder.TEXT_ENCODATION);
break;
case HighLevelEncoder.EDIFACT_ENCODATION:
context.writeCodeword(HighLevelEncoder.LATCH_TO_EDIFACT);
context.signalEncoderChange(HighLevelEncoder.EDIFACT_ENCODATION);
break;
default:
throw StateError('Illegal mode: $newMode');
}
} else if (HighLevelEncoder.isExtendedASCII(c)) {
context.writeCodeword(HighLevelEncoder.UPPER_SHIFT);
context.writeCodeword(c - 128 + 1);
context.pos++;
} else {
context.writeCodeword(c + 1);
context.pos++;
}
}
}