serialize method

  1. @override
Uint8List serialize(
  1. FsharpExternalScannerState state
)
override

Implementation

@override
Uint8List serialize(FsharpExternalScannerState state) {
  final runbackCount = state.runback.length.clamp(0, 0xff);
  final output = BytesBuilder(copy: false)..addByte(runbackCount);
  for (var index = 0; index < runbackCount; index++) {
    output.addByte(state.runback[index]);
  }

  output.addByte(_serializedIndentLengthSize);
  final indentLength = ByteData(_serializedIndentLengthSize)
    ..setUint32(0, state.indentLength & 0xffffffff, Endian.host);
  output.add(indentLength.buffer.asUint8List());

  var length = 1 + runbackCount + 1 + _serializedIndentLengthSize;
  for (
    var index = 1;
    index < state.indentLengthStack.length &&
        length < _serializationBufferSize;
    index++
  ) {
    // The C++ scanner writes each uint32_t indentation through a char.
    output.addByte(state.indentLengthStack[index] & 0xff);
    length++;
  }
  return output.takeBytes();
}