MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / deserialize

Method deserialize

graphlite/src/txn/wal.rs:207–376  ·  view source on GitHub ↗

Deserialize WAL entry from binary format

(data: &[u8])

Source from the content-addressed store, hash-verified

205
206 /// Deserialize WAL entry from binary format
207 pub fn deserialize(data: &[u8]) -> Result<Self, WALError> {
208 if data.len() < 50 {
209 // Minimum size check
210 return Err(WALError::CorruptedEntry("Entry too small".to_string()));
211 }
212
213 let mut offset = 0;
214
215 // Check magic number
216 let magic = u32::from_le_bytes([data[0], data[1], data[2], data[3]]);
217 if magic != WAL_MAGIC {
218 return Err(WALError::CorruptedEntry("Invalid magic number".to_string()));
219 }
220 offset += 4;
221
222 // Entry type
223 let entry_type = match data[offset] {
224 1 => WALEntryType::Begin,
225 2 => WALEntryType::Operation,
226 3 => WALEntryType::Commit,
227 4 => WALEntryType::Rollback,
228 _ => return Err(WALError::CorruptedEntry("Invalid entry type".to_string())),
229 };
230 offset += 1;
231
232 // Transaction ID
233 let txn_id_bytes = [
234 data[offset],
235 data[offset + 1],
236 data[offset + 2],
237 data[offset + 3],
238 data[offset + 4],
239 data[offset + 5],
240 data[offset + 6],
241 data[offset + 7],
242 ];
243 let transaction_id = TransactionId::from_u64(u64::from_le_bytes(txn_id_bytes));
244 offset += 8;
245
246 // Global sequence
247 let global_seq_bytes = [
248 data[offset],
249 data[offset + 1],
250 data[offset + 2],
251 data[offset + 3],
252 data[offset + 4],
253 data[offset + 5],
254 data[offset + 6],
255 data[offset + 7],
256 ];
257 let global_sequence = u64::from_le_bytes(global_seq_bytes);
258 offset += 8;
259
260 // Transaction sequence
261 let txn_seq_bytes = [
262 data[offset],
263 data[offset + 1],
264 data[offset + 2],

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected