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

Function read_len

src/models/serializer/mod.rs:43–58  ·  view source on GitHub ↗

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

(bufman: &BufferManager, cursor: u64)

Source from the content-addressed store, hash-verified

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

Callers 3

read_stringFunction · 0.70
read_opt_stringFunction · 0.70
deserializeMethod · 0.70

Calls 1

read_u8_with_cursorMethod · 0.80

Tested by

no test coverage detected