Decode a 1–3 byte varint back to `u32`. Any bits beyond 22 are ignored.
(bufman: &FilelessBufferManager, cursor: u64)
| 57 | |
| 58 | /// Decode a 1–3 byte varint back to `u32`. Any bits beyond 22 are ignored. |
| 59 | pub fn read_len(bufman: &FilelessBufferManager, cursor: u64) -> Result<u32, BufIoError> { |
| 60 | let b0 = bufman.read_u8_with_cursor(cursor)? as u32; |
| 61 | if b0 & 0x80 == 0 { |
| 62 | return Ok(b0); |
| 63 | } |
| 64 | |
| 65 | let b1 = bufman.read_u8_with_cursor(cursor)? as u32; |
| 66 | let low14 = (b0 & 0x7F) | ((b1 & 0x7F) << 7); |
| 67 | if b1 & 0x80 == 0 { |
| 68 | return Ok(low14); |
| 69 | } |
| 70 | |
| 71 | let b2 = bufman.read_u8_with_cursor(cursor)? as u32; |
| 72 | // here we take all 8 bits of b2 as the highest part |
| 73 | Ok(low14 | (b2 << 14)) |
| 74 | } |
| 75 | |
| 76 | pub fn read_string(bufman: &FilelessBufferManager, cursor: u64) -> Result<String, BufIoError> { |
| 77 | let len = read_len(bufman, cursor)? as usize; |
no test coverage detected