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

Function read_u32_advance

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

Read an unsigned integer that fits in a `u32` at `*off`, advancing `*off` past it. Accepts positive fixint, uint8, uint16, uint32. Returns `None` for negative, signed-typed, oversized (uint64), or non-integer values.

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

Source from the content-addressed store, hash-verified

306/// past it. Accepts positive fixint, uint8, uint16, uint32. Returns `None`
307/// for negative, signed-typed, oversized (uint64), or non-integer values.
308pub fn read_u32_advance(buf: &[u8], off: &mut usize) -> Option<u32> {
309 let tag = get(buf, *off)?;
310 match tag {
311 0x00..=0x7f => {
312 *off += 1;
313 Some(tag as u32)
314 }
315 UINT8 => {
316 let v = get(buf, *off + 1)? as u32;
317 *off += 2;
318 Some(v)
319 }
320 UINT16 => {
321 let v = read_u16_be(buf, *off + 1)? as u32;
322 *off += 3;
323 Some(v)
324 }
325 UINT32 => {
326 let v = read_u32_be(buf, *off + 1)?;
327 *off += 5;
328 Some(v)
329 }
330 _ => None,
331 }
332}
333
334/// Return `(data_start, byte_len)` for the string at `offset` without
335/// validating UTF-8. Used internally for key comparison.

Callers 2

Calls 3

getFunction · 0.85
read_u16_beFunction · 0.85
read_u32_beFunction · 0.85

Tested by

no test coverage detected