Function
decode_varint
(reader: &mut impl BufReader<'a>)
Source from the content-addressed store, hash-verified
| 35 | |
| 36 | #[inline] |
| 37 | pub 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)] |
| 53 | mod tests { |
Tested by
no test coverage detected
Used in the wild real call sites across dependent graphs
searching dependent graphs…