MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / deserialize

Method deserialize

src/structures/wal.rs:63–107  ·  view source on GitHub ↗
(data: &[u8])

Source from the content-addressed store, hash-verified

61
62impl TreeDeserialization for CommitListItem {
63 fn deserialize(data: &[u8]) -> Self {
64 let mut offset = 0;
65
66 let hash = u64::from_le_bytes(data[offset..offset + 8].try_into().unwrap());
67 offset += 8;
68 let timestamp = u64::from_le_bytes(data[offset..offset + 8].try_into().unwrap());
69 offset += 8;
70
71 let vectors_len = u64::from_le_bytes(data[offset..offset + 8].try_into().unwrap()) as usize;
72
73 offset += 8;
74
75 let mut vectors = Vec::new();
76 for _ in 0..vectors_len {
77 let mut vector = [0; QUANTIZED_VECTOR_SIZE];
78 vector.copy_from_slice(&data[offset..offset + QUANTIZED_VECTOR_SIZE]);
79 offset += QUANTIZED_VECTOR_SIZE;
80 vectors.push(vector);
81 }
82
83 let kvs_len = u64::from_le_bytes(data[offset..offset + 8].try_into().unwrap()) as usize;
84 offset += 8;
85
86 let mut kvs = Vec::new();
87 for _ in 0..kvs_len {
88 let mut sub_kvs = Vec::new();
89 let sub_kvs_len =
90 u64::from_le_bytes(data[offset..offset + 8].try_into().unwrap()) as usize;
91 offset += 8;
92 for _ in 0..sub_kvs_len {
93 let kv = KVPair::deserialize(&data[offset..]);
94 offset += kv.serialize().len();
95 sub_kvs.push(kv);
96 }
97
98 kvs.push(sub_kvs);
99 }
100
101 CommitListItem {
102 hash,
103 timestamp,
104 kvs,
105 vectors,
106 }
107 }
108}
109
110impl TreeSerialization for bool {

Callers

nothing calls this directly

Calls 3

pushMethod · 0.80
lenMethod · 0.80
serializeMethod · 0.45

Tested by

no test coverage detected