I'm trying to length prefix a payload that i'm streaming through a socket, and so far the only way i've been able to get it working is:
Uint8List payload = getPayloadSomehow();
final lBytes = ByteData(4)..setUint32(0, payload.length);
final prefix = lBytes.buffer.asUint8List();
final prefixedPayload = []..addAll(prefix)..addAll(payload);
Creating a ByteData and filling it with the length, and then extracting the buffer as a Uint8List feels very roundabout. But i haven't been able to find a cleaner way to do the conversion and prefixing.
I'd really appreciate it if someone could point me to a better solution, thanks.