toBytes method
Converts the UDX packet to raw bytes
Implementation
Uint8List toBytes() {
final framesBytes =
frames.map((f) => f.toBytes()).expand((b) => b).toList();
const headerLength = 28;
final buffer = Uint8List(headerLength + framesBytes.length);
final view = ByteData.view(buffer.buffer);
buffer.setAll(0, destinationCid.bytes);
buffer.setAll(ConnectionId.cidLength, sourceCid.bytes);
view.setUint32(16, sequence, Endian.big);
view.setUint32(20, destinationStreamId, Endian.big);
view.setUint32(24, sourceStreamId, Endian.big);
buffer.setAll(headerLength, framesBytes);
return buffer;
}