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

Method serialize

src/models/serializer/storage.rs:16–65  ·  view source on GitHub ↗
(&self, bufman: &BufferManager, cursor: u64)

Source from the content-addressed store, hash-verified

14
15impl SimpleSerialize for Storage {
16 fn serialize(&self, bufman: &BufferManager, cursor: u64) -> Result<u32, BufIoError> {
17 let start = bufman.cursor_position(cursor)? as u32;
18
19 match self {
20 Self::UnsignedByte { mag, quant_vec } => {
21 bufman.update_u8_with_cursor(cursor, 0)?;
22 bufman.update_f32_with_cursor(cursor, *mag)?;
23 bufman.update_u32_with_cursor(cursor, quant_vec.len() as u32)?;
24 for el in quant_vec {
25 bufman.update_u8_with_cursor(cursor, *el)?;
26 }
27 }
28 Self::SubByte {
29 mag,
30 quant_vec,
31 resolution,
32 } => {
33 bufman.update_u8_with_cursor(cursor, 1)?;
34 bufman.update_u8_with_cursor(cursor, *resolution)?;
35 bufman.update_f32_with_cursor(cursor, *mag)?;
36 bufman.update_u32_with_cursor(cursor, quant_vec.len() as u32)?;
37 for vec in quant_vec {
38 bufman.update_u32_with_cursor(cursor, vec.len() as u32)?;
39 for el in vec {
40 bufman.update_u8_with_cursor(cursor, *el)?;
41 }
42 }
43 }
44 Self::HalfPrecisionFP { mag, quant_vec } => {
45 bufman.update_u8_with_cursor(cursor, 2)?;
46 bufman.update_f32_with_cursor(cursor, *mag)?;
47 bufman.update_u32_with_cursor(cursor, quant_vec.len() as u32)?;
48
49 for el in quant_vec {
50 bufman.update_with_cursor(cursor, &el.to_le_bytes())?;
51 }
52 }
53 Self::FullPrecisionFP { mag, vec } => {
54 bufman.update_u8_with_cursor(cursor, 3)?;
55 bufman.update_f32_with_cursor(cursor, *mag)?;
56 bufman.update_u32_with_cursor(cursor, vec.len() as u32)?;
57
58 for el in vec {
59 bufman.update_f32_with_cursor(cursor, *el)?;
60 }
61 }
62 }
63
64 Ok(start)
65 }
66
67 fn deserialize(
68 bufman: &BufferManager,

Callers

nothing calls this directly

Calls 6

cursor_positionMethod · 0.80
update_u8_with_cursorMethod · 0.80
update_with_cursorMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected