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

Method deserialize

src/models/serializer/storage.rs:67–146  ·  view source on GitHub ↗
(
        bufman: &BufferManager,
        FileOffset(offset): FileOffset,
    )

Source from the content-addressed store, hash-verified

65 }
66
67 fn deserialize(
68 bufman: &BufferManager,
69 FileOffset(offset): FileOffset,
70 ) -> Result<Self, BufIoError> {
71 let cursor = bufman.open_cursor()?;
72 bufman.seek_with_cursor(cursor, offset as u64)?;
73
74 let variant_index = bufman.read_u8_with_cursor(cursor)?;
75
76 let storage = match variant_index {
77 0 => {
78 let mag = bufman.read_f32_with_cursor(cursor)?;
79 let len = bufman.read_u32_with_cursor(cursor)? as usize;
80 let mut quant_vec = Vec::with_capacity(len);
81
82 for _ in 0..len {
83 let el = bufman.read_u8_with_cursor(cursor)?;
84 quant_vec.push(el);
85 }
86
87 Self::UnsignedByte { mag, quant_vec }
88 }
89 1 => {
90 let resolution = bufman.read_u8_with_cursor(cursor)?;
91 let mag = bufman.read_f32_with_cursor(cursor)?;
92 let len = bufman.read_u32_with_cursor(cursor)? as usize;
93 let mut quant_vec = Vec::with_capacity(len);
94
95 for _ in 0..len {
96 let len = bufman.read_u32_with_cursor(cursor)? as usize;
97 let mut vec = Vec::with_capacity(len);
98 for _ in 0..len {
99 let el = bufman.read_u8_with_cursor(cursor)?;
100 vec.push(el);
101 }
102 quant_vec.push(vec);
103 }
104
105 Self::SubByte {
106 mag,
107 quant_vec,
108 resolution,
109 }
110 }
111 2 => {
112 let mag = bufman.read_f32_with_cursor(cursor)?;
113 let len = bufman.read_u32_with_cursor(cursor)? as usize;
114 let mut quant_vec = Vec::with_capacity(len);
115
116 for _ in 0..len {
117 let mut bytes = [0; 2];
118 bufman.read_with_cursor(cursor, &mut bytes)?;
119 let el = f16::from_le_bytes(bytes);
120 quant_vec.push(el);
121 }
122
123 Self::HalfPrecisionFP { mag, quant_vec }
124 }

Callers

nothing calls this directly

Calls 8

open_cursorMethod · 0.80
seek_with_cursorMethod · 0.80
read_u8_with_cursorMethod · 0.80
read_f32_with_cursorMethod · 0.80
read_u32_with_cursorMethod · 0.80
read_with_cursorMethod · 0.80
close_cursorMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected