| 35 | out.push(n as u8); |
| 36 | } |
| 37 | pub(super) fn get(input: &mut &[u8]) -> FormatResult<u64> { |
| 38 | let mut n = 0; |
| 39 | for shift in (0..70).step_by(7) { |
| 40 | let (&b, rest) = input |
| 41 | .split_first() |
| 42 | .ok_or_else(|| invalid("truncated varint"))?; |
| 43 | *input = rest; |
| 44 | if shift == 63 && b > 1 { |
| 45 | return Err(invalid("varint overflow")); |
| 46 | } |
| 47 | n |= u64::from(b & 127) << shift; |
| 48 | if b < 128 { |
| 49 | if shift > 0 && b == 0 { |
| 50 | return Err(invalid("noncanonical varint")); |
| 51 | } |
| 52 | return Ok(n); |
| 53 | } |
| 54 | } |
| 55 | Err(invalid("varint overflow")) |
| 56 | } |
| 57 | #[derive(Default)] |
| 58 | pub(super) struct Delta(pub u64); |
| 59 | impl Delta { |