MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / decode_varint

Function decode_varint

crates/commitlog/src/varint.rs:37–50  ·  view source on GitHub ↗
(reader: &mut impl BufReader<'a>)

Source from the content-addressed store, hash-verified

35
36#[inline]
37pub fn decode_varint<'a>(reader: &mut impl BufReader<'a>) -> Result<usize, DecodeError> {
38 let mut result = 0;
39 let mut shift = 0;
40 loop {
41 let byte = reader.get_u8()?;
42 if (byte & 0x80) == 0 {
43 result |= (byte as usize) << shift;
44 return Ok(result);
45 } else {
46 result |= ((byte & 0x7F) as usize) << shift;
47 }
48 shift += 7;
49 }
50}
51
52#[cfg(test)]
53mod tests {

Callers 3

skipMethod · 0.85
decodeMethod · 0.85
consumeMethod · 0.85

Calls 2

get_u8Method · 0.80
OkFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…