RustyASN
Abstract Syntax Notation One (ASN.1) encoding support for the RustyFix FIX protocol implementation.
Features
- Multiple encoding rules: BER, DER, OER
- Zero-copy decoding where possible
- Streaming support for continuous message processing
- Type-safe ASN.1 schema compilation
- High-performance implementation optimized for low-latency trading
- Integration with RustyFix field types and dictionaries
Supported Encoding Rules
- BER (Basic Encoding Rules) - Self-describing, flexible format
- DER (Distinguished Encoding Rules) - Canonical subset of BER, deterministic encoding
- OER (Octet Encoding Rules) - Byte-aligned, balance between efficiency and simplicity
Usage
Add to your Cargo.toml:
[]
= "0.7.4"
Basic Encoding/Decoding
use ;
use Dictionary;
use Arc;
Run the example: cargo run --example basic_usage
Streaming Decoder
For processing multiple messages from a continuous stream:
use ;
use Dictionary;
use Arc;
Run the example: cargo run --example streaming_decoder
Configuration Profiles
use ;
// Optimized for low-latency trading
let low_latency_config = low_latency; // Uses OER, skips validation
// Optimized for reliability and compliance
let high_reliability_config = high_reliability; // Uses DER, full validation
// Custom configuration
let mut custom_config = new;
custom_config.max_message_size = 16 * 1024; // 16KB limit
custom_config.enable_zero_copy = true;
custom_config.validate_checksums = false; // Disable for performance
Run the example: cargo run --example configuration
Performance Considerations
-
Encoding Rule Selection:
- OER: Most compact of supported rules, best for low-latency
- DER: Deterministic, best for audit trails
- BER: Most flexible, larger size
-
Zero-Copy Operations: Enable with
config.enable_zero_copy = true -
Buffer Management: Pre-allocate buffers for streaming operations
-
Validation: Disable checksum validation in low-latency scenarios
Integration with SOFH
RustyASN integrates with Simple Open Framing Header (SOFH) for message framing:
use EncodingRule;
// Map ASN.1 encoding rules to SOFH encoding types
Run the example: cargo run --example sofh_integration
Safety and Security
- Maximum message size limits prevent DoS attacks
- Recursion depth limits prevent stack overflow
- Input validation for all field types
- Safe parsing of untrusted input
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.