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

Function read_varint

nodedb-array/src/codec/coord_delta.rs:48–62  ·  view source on GitHub ↗

Returns (value, bytes_consumed). Returns None on truncated input.

(data: &[u8])

Source from the content-addressed store, hash-verified

46
47/// Returns (value, bytes_consumed). Returns None on truncated input.
48fn read_varint(data: &[u8]) -> Option<(u64, usize)> {
49 let mut val: u64 = 0;
50 let mut shift = 0u32;
51 for (i, &b) in data.iter().enumerate() {
52 val |= ((b & 0x7F) as u64) << shift;
53 if b & 0x80 == 0 {
54 return Some((val, i + 1));
55 }
56 shift += 7;
57 if shift >= 70 {
58 return None;
59 }
60 }
61 None
62}
63
64// ---------------------------------------------------------------------------
65// Public API

Callers 1

decode_coord_axisFunction · 0.70

Calls 1

iterMethod · 0.45

Tested by

no test coverage detected