toBytes method
Serialize the frame into a byte list.
Implementation
@override
Uint8List toBytes() {
final reasonBytes = reasonPhrase.codeUnits;
final buffer = Uint8List(length);
final view = ByteData.view(buffer.buffer);
int offset = 0;
view.setUint8(offset, FrameType.connectionClose.index);
offset += 1;
view.setUint32(offset, errorCode, Endian.big);
offset += 4;
view.setUint32(offset, frameType, Endian.big);
offset += 4;
view.setUint16(offset, reasonBytes.length, Endian.big);
offset += 2;
buffer.setAll(offset, reasonBytes);
return buffer;
}