pub fn try_decode_frame<T>(
buffer: &[u8],
) -> Result<Option<(T, usize)>, ProtocolError>where
T: DeserializeOwned,Expand description
Attempt to decode a single length-prefixed frame from the provided buffer.
The wire format is:
- 4-byte big-endian payload length (
u32) - payload bytes encoded as JSON
§Returns
Ok(None)if the buffer does not yet contain a full frame,- deserialized frame with with the number of consumed bytes if buffer contains a full frame.
Trailing bytes after the decoded frame are not treated as an error. The caller is expected to keep them in the input buffer and pass them again when decoding subsequent frames.
§Errors
Returns Err(ProtocolError) an error if:
- the decoded payload length cannot be represented as
usize, - frame length arithmetic overflows,
- payload contains invalid JSON for the requested type.