toPacket method
Implementation
Uint8List toPacket(Uint8List payload, Random random, int blockSize) {
Uint8List buffer = Uint8List(nextMultipleOfN(
4 + BinaryPacket.headerSize + payload.length, max(8, blockSize)));
SerializableOutput output = SerializableOutput(buffer);
int padding = buffer.length - BinaryPacket.headerSize - payload.length;
output.addUint32(buffer.length - 4);
output.addUint8(padding);
output.addBytes(payload);
output.addBytes(randBytes(random, padding));
if (!output.done) {
throw FormatException('${output.offset}/${output.buffer.length}');
}
return buffer;
}