encode method

  1. @override
void encode(
  1. EncoderContext context
)
override

Implementation

@override
void encode(EncoderContext context) {
  //step F
  final buffer = StringBuilder();
  while (context.hasMoreCharacters) {
    final c = context.currentChar;
    _encodeChar(c, buffer);
    context.pos++;

    final count = buffer.length;
    if (count >= 4) {
      context.writeCodewords(_encodeToCodewords(buffer));
      buffer.delete(0, 4);

      final newMode = HighLevelEncoder.lookAheadTest(
        context.message,
        context.pos,
        encodingMode,
      );
      if (newMode != encodingMode) {
        // Return to ASCII encodation, which will actually handle latch to new mode
        context.signalEncoderChange(HighLevelEncoder.asciiEncodation);
        break;
      }
    }
  }
  buffer.writeCharCode(31); //Unlatch
  _handleEOD(context, buffer);
}