pub fn decode_frame(buf: &[u8]) -> Result<(DecodedFrame, usize), WireError>Expand description
Decode the first complete frame at the front of buf.
Returns the frame and the number of bytes it consumed (advance the
caller’s read cursor by that much). On WireError::Truncated, the caller should read more
bytes and retry; any other error signals an unrecoverable peer
violation.
use kevy_replicate::wire::{decode_frame, encode_frame};
let set = kevy_resp::Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]);
let mut stream = encode_frame(0, &set);
stream.extend(encode_frame(1, &set));
let (first, used) = decode_frame(&stream)?;
let (second, _) = decode_frame(&stream[used..])?; // advance past the first
assert_eq!((first.offset, second.offset), (0, 1));