Expand description
Analyzes binary data structures against schema definitions.
This module implements analysis of binary data structures according to a defined schema. It handles both field and group analysis, maintaining statistics about the data including:
- Bit-level statistics for compression analysis
- Value frequency distributions
- Conditional processing based on schema rules
§Core Types
SchemaAnalyzer
: Main analyzer that processes binary data.CompressionOptions
: Configuration options for the analyzer.
§Internal Types
AnalyzerFieldState
: Per-field statistics and analysis state (working state)BitStats
: Bit-level statistics for individual field positions (part of results)
§Example
use struct_compression_analyzer::{schema::Schema, analyzer::{SchemaAnalyzer, CompressionOptions}};
use anyhow::Result;
use std::fs::read_to_string;
use std::path::Path;
async fn schema_analyzer_example() -> Result<()> {
// Load schema from disk.
let schema = Schema::load_from_file(Path::new("schema.yaml"))?;
// Create analysis options
let options = CompressionOptions::default();
// Create the analyzer from the schema, creating the initial state.
let mut analyzer = SchemaAnalyzer::new(&schema, options);
// Process multiple entries
// From binary file, or wherever they may come from.
analyzer.add_entry(&[0x01, 0x02, 0x03])?;
analyzer.add_entry(&[0x04, 0x05, 0x06])?;
// Generate final analysis
let results = analyzer.generate_results()?;
Ok(())
}
§Statistics and Metrics
The analyzer tracks several key metrics:
- Bit-level statistics (zero/one counts per bit position)
- Value frequency distributions
- Field-level bit order and alignment
- Conditional processing outcomes
Structs§
- Analyzer
Field State - Intermediate statistics for a single field or group of fields
- BitStats
- Compression
Options - Options to configure the behavior of compression when analysing schemas.
- Schema
Analyzer - Analyzes binary structures against a schema definition
- Size
Estimation Parameters - Struct to encapsulate parameters for size estimation functions. Functions accept this struct return an estimated size in bytes.
Enums§
- Analysis
Error - Errors that can occur during schema analysis.
Type Aliases§
- Size
Estimator Fn - Function pointer type for size estimation functions.