| 77 | out.push(n as u8); |
| 78 | } |
| 79 | fn get(input: &mut &[u8]) -> Result<u64> { |
| 80 | let mut n = 0; |
| 81 | for shift in (0..70).step_by(7) { |
| 82 | let (&b, rest) = input.split_first().context("truncated graph varint")?; |
| 83 | *input = rest; |
| 84 | ensure!(shift != 63 || b <= 1, "graph varint overflow"); |
| 85 | n |= u64::from(b & 127) << shift; |
| 86 | if b < 128 { |
| 87 | ensure!(shift == 0 || b != 0, "noncanonical graph varint"); |
| 88 | return Ok(n); |
| 89 | } |
| 90 | } |
| 91 | anyhow::bail!("graph varint overflow") |
| 92 | } |
| 93 | fn delta(out: &mut Vec<u8>, previous: &mut u64, next: u64) { |
| 94 | let d = next.wrapping_sub(*previous); |
| 95 | put(out, (d << 1) ^ ((d as i64 >> 63) as u64)); |