MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / footer_golden_layout

Function footer_golden_layout

nodedb-vector/src/mmap_segment/reader.rs:578–605  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

576
577 #[test]
578 fn footer_golden_layout() {
579 let dir = tempfile::tempdir().unwrap();
580 let path = dir.path().join("golden.vseg");
581 let v = vec![1.0f32, 2.0, 3.0];
582 write_segment(&path, 3, &[&v], &[42]).unwrap();
583 let data = std::fs::read(&path).unwrap();
584
585 // Footer starts at file_size - FOOTER_SIZE.
586 let footer_start = data.len() - FOOTER_SIZE;
587 let footer = &data[footer_start..];
588
589 // [0..2] format_version = FORMAT_VERSION.
590 let fv = u16::from_le_bytes([footer[0], footer[1]]);
591 assert_eq!(fv, FORMAT_VERSION);
592
593 // [34..38] checksum matches body CRC32C.
594 let body = &data[..footer_start];
595 let expected_crc = crc32c::crc32c(body);
596 let stored_crc = u32::from_le_bytes([footer[34], footer[35], footer[36], footer[37]]);
597 assert_eq!(stored_crc, expected_crc);
598
599 // [38..42] footer_size = FOOTER_SIZE (46).
600 let fs = u32::from_le_bytes([footer[38], footer[39], footer[40], footer[41]]) as usize;
601 assert_eq!(fs, FOOTER_SIZE);
602
603 // [42..46] trailing magic = b"NDVS".
604 assert_eq!(&footer[42..46], b"NDVS");
605 }
606
607 #[test]
608 fn trailing_magic_corruption_rejected() {

Callers

nothing calls this directly

Calls 5

joinMethod · 0.80
write_segmentFunction · 0.70
readFunction · 0.50
pathMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected