serializeFrame method

  1. @override
dynamic serializeFrame(
  1. StompFrame frame
)
override

We don't need to worry about reversing the header since we use a map and the last value written would just be the most up to date value, which is also fine with the spec https://stomp.github.io/stomp-specification-1.2.html#Repeated_Header_Entries

Implementation

@override
dynamic serializeFrame(StompFrame frame) {
  final serializedHeaders = _serializeCmdAndHeaders(frame) ?? '';

  if (frame.binaryBody != null) {
    final binaryList = Uint8List(
        serializedHeaders.codeUnits.length + 1 + frame.binaryBody!.length);
    binaryList.setRange(
        0, serializedHeaders.codeUnits.length, serializedHeaders.codeUnits);
    binaryList.setRange(
        serializedHeaders.codeUnits.length,
        serializedHeaders.codeUnits.length + frame.binaryBody!.length,
        frame.binaryBody!);
    binaryList[serializedHeaders.codeUnits.length +
        frame.binaryBody!.length] = _NULL;
    return binaryList;
  } else {
    var serializedFrame = serializedHeaders;
    serializedFrame += frame.body ?? '';
    serializedFrame += String.fromCharCode(_NULL);
    return serializedFrame;
  }
}