matchy_format/
offset_format.rs

1//! Offset-based binary format for zero-copy memory mapping
2//!
3//! This module re-exports the binary format structures from `matchy-paraglob`.
4//! The canonical definitions live in `matchy-paraglob::offset_format` to ensure
5//! a single source of truth for all `#[repr(C)]` binary format structures.
6//!
7//! # What This Module Provides
8//!
9//! - `ParaglobHeader` - Main header (112 bytes, v5)
10//! - `PatternDataMapping` - Pattern-to-data offset mapping
11//! - `GlobSegmentIndex`, `GlobSegmentHeader`, `CharClassItemEncoded` - Glob segment structures
12//! - `MAGIC`, `MATCHY_FORMAT_VERSION*` - Format constants
13//! - Helper functions for reading structures from byte buffers
14//!
15//! # Why Re-exports?
16//!
17//! Binary format structures are defined once in `matchy-paraglob` and re-exported
18//! here to avoid duplication. This prevents drift between identical `#[repr(C)]`
19//! structs that must remain byte-for-byte compatible.
20
21// Re-export all binary format structures from the canonical source
22pub use matchy_paraglob::offset_format::{
23    // Helper functions
24    read_cstring,
25    read_cstring_with_len,
26    read_str_checked,
27    read_str_unchecked,
28    read_struct,
29    read_struct_slice,
30    // Glob segment structures
31    CharClassItemEncoded,
32    GlobSegmentHeader,
33    GlobSegmentIndex,
34    // Main header
35    ParaglobHeader,
36    // Pattern data mapping
37    PatternDataMapping,
38    // Format constants
39    MAGIC,
40    MATCHY_FORMAT_VERSION,
41    MATCHY_FORMAT_VERSION_V1,
42    MATCHY_FORMAT_VERSION_V2,
43    MATCHY_FORMAT_VERSION_V3,
44    MATCHY_FORMAT_VERSION_V4,
45};
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50    use std::mem;
51
52    #[test]
53    fn test_reexports_match_expected_sizes() {
54        // Verify re-exported types have expected sizes
55        assert_eq!(mem::size_of::<ParaglobHeader>(), 112);
56        assert_eq!(mem::size_of::<PatternDataMapping>(), 12);
57        assert_eq!(mem::size_of::<GlobSegmentIndex>(), 8);
58        assert_eq!(mem::size_of::<GlobSegmentHeader>(), 12);
59        assert_eq!(mem::size_of::<CharClassItemEncoded>(), 12);
60    }
61
62    #[test]
63    fn test_header_validation() {
64        let mut header = ParaglobHeader::new();
65        assert!(header.validate().is_ok());
66        assert_eq!(header.version, MATCHY_FORMAT_VERSION);
67
68        header.magic = *b"INVALID!";
69        assert!(header.validate().is_err());
70    }
71}