use rustyasn::{Config, Decoder, Encoder, EncodingRule};
use rustyfix_dictionary::Dictionary;
use std::sync::Arc;
fn main() -> Result<(), Box<dyn std::error::Error>> {
basic_example()
}
fn basic_example() -> Result<(), Box<dyn std::error::Error>> {
let dict = Arc::new(Dictionary::fix44()?);
let config = Config::new(EncodingRule::DER);
let encoder = Encoder::new(config.clone(), dict.clone());
let decoder = Decoder::new(config, dict);
let mut handle = encoder.start_message(
"D", "SENDER001", "TARGET001", 1, );
handle
.add_string(11, "CL001") .add_string(55, "EUR/USD") .add_int(54, 1) .add_uint(38, 1_000_000) .add_string(52, "20240101-12:00:00");
let encoded = handle.encode()?;
println!("Encoded message size: {} bytes", encoded.len());
let decoded = decoder.decode(&encoded)?;
println!("Decoded message type: {}", decoded.msg_type());
println!("Symbol: {:?}", decoded.get_string(55));
println!("ClOrdID: {:?}", decoded.get_string(11));
assert_eq!(decoded.msg_type(), "D");
assert_eq!(decoded.get_string(55), Some("EUR/USD".to_string()));
assert_eq!(decoded.get_string(11), Some("CL001".to_string()));
println!("✓ Basic encoding/decoding successful!");
Ok(())
}