MCPcopy Create free account
hub / github.com/cosdata/cosdata / read_len

Function read_len

src/models/wal.rs:59–74  ·  view source on GitHub ↗

Decode a 1–3 byte varint back to `u32`. Any bits beyond 22 are ignored.

(bufman: &FilelessBufferManager, cursor: u64)

Source from the content-addressed store, hash-verified

57
58/// Decode a 1–3 byte varint back to `u32`. Any bits beyond 22 are ignored.
59pub 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
76pub fn read_string(bufman: &FilelessBufferManager, cursor: u64) -> Result<String, BufIoError> {
77 let len = read_len(bufman, cursor)? as usize;

Callers 3

read_stringFunction · 0.70
read_opt_stringFunction · 0.70
readMethod · 0.70

Calls 1

read_u8_with_cursorMethod · 0.80

Tested by

no test coverage detected