parseRecord function
Parse a single ONC RPC record from the head of bytes. Returns
null when fewer than 4 header bytes have arrived, or when the
declared payload length exceeds what's buffered.
Implementation
OncRpcRecord? parseRecord(Uint8List bytes) {
if (bytes.length < 4) return null;
final view = ByteData.sublistView(bytes);
final marker = view.getUint32(0, Endian.big);
final last = (marker & 0x80000000) != 0;
final length = marker & 0x7FFFFFFF;
if (bytes.length < 4 + length) return null;
return OncRpcRecord(
last: last,
payload: Uint8List.fromList(bytes.sublist(4, 4 + length)),
totalBytes: 4 + length,
);
}