MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / read_bin_advance

Function read_bin_advance

nodedb-query/src/msgpack_scan/reader.rs:290–303  ·  view source on GitHub ↗

Read a `bin` value at `*off`, advancing `*off` past it. Zero-copy — the returned slice borrows from `buf`. Returns `None` for non-bin tags or truncated input.

(buf: &'a [u8], off: &mut usize)

Source from the content-addressed store, hash-verified

288/// the returned slice borrows from `buf`. Returns `None` for non-bin tags
289/// or truncated input.
290pub fn read_bin_advance<'a>(buf: &'a [u8], off: &mut usize) -> Option<&'a [u8]> {
291 let tag = get(buf, *off)?;
292 let (len, header) = match tag {
293 BIN8 => (get(buf, *off + 1)? as usize, 2),
294 BIN16 => (read_u16_be(buf, *off + 1)? as usize, 3),
295 BIN32 => (read_u32_be(buf, *off + 1)? as usize, 5),
296 _ => return None,
297 };
298 let start = *off + header;
299 let end = start + len;
300 let data = buf.get(start..end)?;
301 *off = end;
302 Some(data)
303}
304
305/// Read an unsigned integer that fits in a `u32` at `*off`, advancing `*off`
306/// past it. Accepts positive fixint, uint8, uint16, uint32. Returns `None`

Calls 4

getFunction · 0.85
read_u16_beFunction · 0.85
read_u32_beFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected