| 35 | } |
| 36 | |
| 37 | fn get(input: &mut &[u8]) -> Result<u64> { |
| 38 | let mut n = 0; |
| 39 | for shift in (0..70).step_by(7) { |
| 40 | let (&b, rest) = input.split_first().context("truncated varint")?; |
| 41 | *input = rest; |
| 42 | ensure!(shift != 63 || b <= 1, "varint overflow"); |
| 43 | n |= u64::from(b & 127) << shift; |
| 44 | if b < 128 { |
| 45 | ensure!(shift == 0 || b != 0, "noncanonical varint"); |
| 46 | return Ok(n); |
| 47 | } |
| 48 | } |
| 49 | bail!("varint overflow") |
| 50 | } |
| 51 | |
| 52 | // Wrapping differences cover the entire u64 domain, including descending IDs. |
| 53 | fn delta(out: &mut Vec<u8>, previous: &mut u64, next: u64) { |