decode static method
Decode a frame from raw bytes.
Returns null if data is too short (less than headerSize bytes).
A declared payload length over maxPayloadLen, or a metadata frame's
over maxMetadataLen, throws RpcFrameException instead of allocating,
as decodeAll does: a peer claiming a huge frame cannot force unbounded
buffering.
Malformed metadata (a length past the end, bytes after the last header, invalid UTF-8) throws RpcFrameException rather than letting a raw RangeError/FormatException escape into the receive loop.
Implementation
static RpcDecodedFrame? decode(
Uint8List data, {
int? maxPayloadLen,
int? maxMetadataLen,
}) {
if (data.length < headerSize) return null;
final header = _readHeader(
ByteData.sublistView(data),
0,
maxPayloadLen: maxPayloadLen,
maxMetadataLen: maxMetadataLen,
);
if (data.length < headerSize + header.payloadLen) return null;
return _frameAt(data, 0, header);
}