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

Function read_str_advance

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

Read a string slice at `*off`, advancing `*off` past it. Zero-copy. Returns `None` for non-string types, invalid UTF-8, or truncated input.

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

Source from the content-addressed store, hash-verified

277/// Read a string slice at `*off`, advancing `*off` past it. Zero-copy.
278/// Returns `None` for non-string types, invalid UTF-8, or truncated input.
279pub fn read_str_advance<'a>(buf: &'a [u8], off: &mut usize) -> Option<&'a str> {
280 let (start, len) = str_bounds(buf, *off)?;
281 let bytes = buf.get(start..start + len)?;
282 let s = str::from_utf8(bytes).ok()?;
283 *off = start + len;
284 Some(s)
285}
286
287/// Read a `bin` value at `*off`, advancing `*off` past it. Zero-copy —
288/// the returned slice borrows from `buf`. Returns `None` for non-bin tags

Callers 1

Calls 3

str_boundsFunction · 0.85
getMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected