Decode a 1–3 byte varint back to `u32`. Any bits beyond 22 are ignored.
(bufman: &BufferManager, cursor: u64)
| 41 | |
| 42 | /// Decode a 1–3 byte varint back to `u32`. Any bits beyond 22 are ignored. |
| 43 | pub fn read_len(bufman: &BufferManager, cursor: u64) -> Result<u32, BufIoError> { |
| 44 | let b0 = bufman.read_u8_with_cursor(cursor)? as u32; |
| 45 | if b0 & 0x80 == 0 { |
| 46 | return Ok(b0); |
| 47 | } |
| 48 | |
| 49 | let b1 = bufman.read_u8_with_cursor(cursor)? as u32; |
| 50 | let low14 = (b0 & 0x7F) | ((b1 & 0x7F) << 7); |
| 51 | if b1 & 0x80 == 0 { |
| 52 | return Ok(low14); |
| 53 | } |
| 54 | |
| 55 | let b2 = bufman.read_u8_with_cursor(cursor)? as u32; |
| 56 | // here we take all 8 bits of b2 as the highest part |
| 57 | Ok(low14 | (b2 << 14)) |
| 58 | } |
| 59 | |
| 60 | pub fn read_string(bufman: &BufferManager, cursor: u64) -> Result<String, BufIoError> { |
| 61 | let len = read_len(bufman, cursor)? as usize; |
no test coverage detected