matchy-format
Unified database format orchestrating IP tries, glob patterns, and literal string matching.
Overview
This crate provides the binary format for matchy databases (.mxy files), combining three routing layers into a single memory-mapped file:
- IP trie (from matchy-ip-trie) - CIDR/IP → data offsets
- Glob patterns (from matchy-paraglob) - Pattern matching → data offsets
- Literal hash (from matchy-literal-hash) - Exact strings → data offsets
Architecture
.mxy File Format:
┌─────────────────────────────┐
│ IP Search Tree (binary trie)│ ← matchy-ip-trie
├─────────────────────────────┤
│ Data Section (deduplicated) │ ← matchy-data-format
├─────────────────────────────┤
│ MMDB_PATTERN separator │
├─────────────────────────────┤
│ Paraglob Section (optional) │ ← matchy-paraglob
│ - AC automaton │
│ - Pattern entries │
│ - Glob segments │
├─────────────────────────────┤
│ Literal Hash (optional) │ ← matchy-literal-hash
│ - 96-bit hash table │
│ - Pattern mappings │
├─────────────────────────────┤
│ MMDB Metadata │
└─────────────────────────────┘
Features
- Unified format: Single file for all data types
- Memory-mapped: Zero-copy loading
- MMDB compatible: Backward compatible with MaxMind DB format
- Builder API: High-level interface for database construction
- FormatError: Proper error type for format operations
Usage
use ;
use DataValue;
use HashMap;
let mut builder = new;
// Add IP entry
let mut data = new;
data.insert;
builder.add_entry?;
// Add pattern entry
let mut data = new;
data.insert;
builder.add_entry?;
// Build database
let db_bytes = builder.build?;
write?;
Entry Type Detection
The builder automatically detects entry types:
- IP addresses:
1.2.3.4,192.168.0.0/16,2001:db8::/32 - Literal strings:
example.com(exact match only) - Glob patterns:
*.example.com,file?.txt(wildcard matching)
Components
mmdb_builder.rs- High-level database buildermmdb/- MMDB format structuresoffset_format.rs- Binary format definitionsendian.rs- Endianness handlingmmap.rs- Memory-mapped file wrappererror.rs- FormatError type
Dependencies
matchy-ip-trie- IP address routingmatchy-paraglob- Glob pattern matchingmatchy-literal-hash- Exact string matchingmatchy-data-format- Data encoding/decodingmatchy-glob- Glob parsingmatchy-match-mode- Shared MatchMode enum