Expand description
§RustyASN
- ASN.1 Encoding for FIX Protocol
This crate provides Abstract Syntax Notation One (ASN.1) encoding support for the FIX protocol. It supports multiple encoding rules:
- BER (Basic Encoding Rules) - Self-describing, flexible
- DER (Distinguished Encoding Rules) - Canonical subset of BER
- OER (Octet Encoding Rules) - Byte-aligned, efficient
§Features
- Zero-copy decoding where possible
- Streaming support for continuous message processing
- Type-safe ASN.1 schema compilation
- Integration with
RustyFix
field types - High-performance implementation optimized for low-latency trading
§ASN.1 Schema Compilation
This crate uses a custom ASN.1 parser implementation in its build script rather than
the standard rasn-compiler
crate. This
architectural decision was made due to version compatibility issues:
§Why Custom Parser?
-
Version Incompatibility: The rasn-compiler crate has compatibility issues with rasn 0.18.x, which is used throughout the
RustyFix
project. Using rasn-compiler would require either downgrading rasn or dealing with breaking API changes. -
FIX-Specific Optimizations: The custom parser is tailored for FIX protocol message structures and generates code that integrates seamlessly with
RustyFix
’s type system and performance requirements. -
Build Stability: The custom implementation is immune to breaking changes in rasn-compiler updates, ensuring consistent builds across environments.
-
Reduced Dependencies: Eliminates rasn-compiler and its transitive dependencies, reducing build complexity and potential security surface.
§Supported ASN.1 Features
The custom parser supports the ASN.1 constructs commonly used in FIX protocol extensions:
- SEQUENCE types with optional fields and explicit tags
- ENUMERATED types with explicit discriminant values
- CHOICE types with context-specific tags
- INTEGER types with constraint annotations
- String types (
UTF8String
,PrintableString
,VisibleString
, etc.)
§Migration Path
Future migration to rasn-compiler will be considered when:
- rasn-compiler achieves stable compatibility with rasn 0.18.x+
- The
RustyFix
project upgrades to a newer rasn version - The maintenance burden of the custom parser becomes significant
For complex ASN.1 schemas requiring advanced features not implemented in the custom parser, the build script provides fallback mechanisms and clear error messages.
§Usage
use rustyasn::{Config, Encoder, Decoder, EncodingRule};
use rustyfix::Dictionary;
use std::sync::Arc;
fn example() -> Result<(), Box<dyn std::error::Error>> {
// Configure encoding
let config = Config::new(EncodingRule::OER);
let dictionary = Arc::new(Dictionary::fix44()?);
// Create encoder and decoder
let encoder = Encoder::new(config.clone(), dictionary.clone());
let decoder = Decoder::new(config, dictionary);
// Start encoding a message
let mut handle = encoder.start_message(
"D", // MsgType: NewOrderSingle
"SENDER", // SenderCompID
"TARGET", // TargetCompID
1, // MsgSeqNum
);
// Add fields and encode
handle.add_string(11, "ORDER001"); // ClOrdID
let encoded = handle.encode()?;
// Decode the message
let message = decoder.decode(&encoded)?;
println!("Decoded message type: {}", message.msg_type());
Ok(())
}
Re-exports§
pub use config::Config;
pub use config::EncodingRule;
pub use decoder::Decoder;
pub use decoder::DecoderStreaming;
pub use encoder::Encoder;
pub use encoder::EncoderHandle;
pub use error::DecodeError;
pub use error::EncodeError;
pub use error::Error;
pub use error::Result;
pub use field_types::Asn1Boolean;
pub use field_types::Asn1Bytes;
pub use field_types::Asn1FieldError;
pub use field_types::Asn1Integer;
pub use field_types::Asn1String;
pub use field_types::Asn1UInteger;
pub use generated::Asn1Field;
pub use generated::Asn1FixMessage;
pub use generated::FixFieldTag;
pub use generated::FixMessageType;
pub use message::Message;
pub use message::MessageGroup;
Modules§
- buffers
- Const generic buffer types for optimal performance.
- config
- Configuration options for ASN.1 encoding and decoding.
- decoder
- ASN.1 decoder implementation for FIX messages.
- encoder
- ASN.1 encoder implementation for FIX messages.
- error
- Error types for ASN.1 encoding and decoding operations.
- field_
types - ASN.1 field type implementations that integrate with
RustyFix
FieldType
trait. - generated
- Generated ASN.1 definitions from FIX dictionaries.
- message
- ASN.1 message implementation with
FieldMap
trait support. - schema
- ASN.1 schema definitions and FIX message type mappings.
- types
- ASN.1 type definitions and FIX field mappings.
Constants§
- FIELD_
BUFFER_ SIZE - Default buffer size for field serialization (64 bytes)
- MAX_
HEADER_ FIELDS - Maximum number of standard header fields
- MEDIUM_
FIELD_ COLLECTION_ SIZE - Size for medium field collections (16 fields)
- SMALL_
FIELD_ COLLECTION_ SIZE - Size for small field collections (8 fields)
- VERSION
- Version information for the ASN.1 encoding implementation
Traits§
- AsnType
- A trait representing any type that can represented in ASN.1.
- Decode
- A data type that can decoded from any ASN.1 format.
- Encode
- A data type that can be encoded to a ASN.1 data format.