Module analyzer

Source
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

§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§

AnalyzerFieldState
Intermediate statistics for a single field or group of fields
BitStats
CompressionOptions
Options to configure the behavior of compression when analysing schemas.
SchemaAnalyzer
Analyzes binary structures against a schema definition
SizeEstimationParameters
Struct to encapsulate parameters for size estimation functions. Functions accept this struct return an estimated size in bytes.

Enums§

AnalysisError
Errors that can occur during schema analysis.

Type Aliases§

SizeEstimatorFn
Function pointer type for size estimation functions.