pub fn msgpack_document_len(
bytes: &[u8],
max_depth: usize,
) -> Result<usize, MsgpackStructureError>Expand description
Runs the walk check_msgpack_structure describes and returns the length,
in bytes, of the document at the start of bytes.
It accepts and rejects exactly what check_msgpack_structure does. The
walk stops where the document ends, so the length is at least 1 and at most
bytes.len(), and a length below bytes.len() means trailing bytes follow.
A caller that requires the input to be exactly one document compares the
two instead of walking the input a second time.
§Errors
The same MsgpackStructureError, for the same inputs, as
check_msgpack_structure.
§Examples
use cachekit_core::msgpack_document_len;
// nil, then two bytes the walk never reads (so 0xc1 is not rejected here).
let input = [0xc0, 0xc1, 0xff];
assert_eq!(msgpack_document_len(&input, 100), Ok(1));
// [[nil], "x"]: five bytes, the whole input.
let doc = [0x92, 0x91, 0xc0, 0xa1, b'x'];
assert_eq!(msgpack_document_len(&doc, 100), Ok(doc.len()));