@@ -64,107 +64,63 @@ fn basic_example() -> Result<(), Box<dyn std::error::Error>> {
6464
6565 Ok (())
6666}
67-
68- #[cfg(test)]
69- mod tests {
70- use super :: * ;
71-
72- #[test]
73- fn test_basic_example () {
74- basic_example (). expect (" Basic example should work" );
75- }
76- }
7767```
7868
69+ ** Run the example** : ` cargo run --example basic_usage `
70+
7971### Streaming Decoder
8072
73+ For processing multiple messages from a continuous stream:
74+
8175``` rust
82- use rustyasn :: {Config , Encoder , DecoderStreaming , EncodingRule };
76+ use rustyasn :: {Config , DecoderStreaming , EncodingRule };
8377use rustyfix_dictionary :: Dictionary ;
8478use std :: sync :: Arc ;
8579
8680fn streaming_example () -> Result <(), Box <dyn std :: error :: Error >> {
87- // Setup
8881 let dict = Arc :: new (Dictionary :: fix44 ()? );
8982 let config = Config :: new (EncodingRule :: DER );
90-
91- // Create some test messages first using the encoder
92- let encoder = Encoder :: new (config . clone (), dict . clone ());
93- let mut test_messages = Vec :: new ();
94-
95- for seq_num in 1 ..= 3 {
96- let mut handle = encoder . start_message (" 0" , " SENDER" , " TARGET" , seq_num );
97- handle . add_string (112 , format! (" TestID_{}" , seq_num )); // TestReqID
98- let encoded = handle . encode ()? ;
99- test_messages . extend_from_slice (& encoded );
100- }
101-
102- // Now demonstrate streaming decoding
10383 let mut decoder = DecoderStreaming :: new (config , dict );
10484
10585 // Simulate feeding data in chunks (as would happen from network/file)
106- let chunk_size = test_messages . len () / 3 ; // Split into 3 chunks
107- for chunk in test_messages . chunks (chunk_size ) {
108- decoder . feed (chunk );
109-
110- // Process any complete messages that have been decoded
111- while let Ok (Some (message )) = decoder . decode_next () {
112- println! (" Received: {} from {} (seq: {})" ,
113- message . msg_type (),
114- message . sender_comp_id (),
115- message . msg_seq_num ()
116- );
117- }
86+ let data_chunk = vec! [/* your message data */ ];
87+ decoder . feed (& data_chunk );
88+
89+ // Process any complete messages that have been decoded
90+ while let Ok (Some (message )) = decoder . decode_next () {
91+ println! (" Received: {} from {} (seq: {})" ,
92+ message . msg_type (),
93+ message . sender_comp_id (),
94+ message . msg_seq_num ()
95+ );
11896 }
11997
12098 Ok (())
12199}
122-
123- #[cfg(test)]
124- mod tests {
125- use super :: * ;
126-
127- #[test]
128- fn test_streaming_example () {
129- streaming_example (). expect (" Streaming example should work" );
130- }
131- }
132100```
133101
102+ ** Run the example** : ` cargo run --example streaming_decoder `
103+
134104### Configuration Profiles
135105
136106``` rust
137107use rustyasn :: {Config , EncodingRule };
138108
139- fn configuration_examples () {
140- // Optimized for low-latency trading
141- let low_latency_config = Config :: low_latency (); // Uses OER, skips validation
142- println! (" Low latency rule: {:?}" , low_latency_config . encoding_rule);
143-
144- // Optimized for reliability and compliance
145- let high_reliability_config = Config :: high_reliability (); // Uses DER, full validation
146- println! (" High reliability rule: {:?}" , high_reliability_config . encoding_rule);
147-
148- // Custom configuration
149- let mut custom_config = Config :: new (EncodingRule :: OER );
150- custom_config . max_message_size = 16 * 1024 ; // 16KB limit
151- custom_config . enable_zero_copy = true ;
152- custom_config . validate_checksums = false ; // Disable for performance
153-
154- println! (" Custom config max size: {} bytes" , custom_config . max_message_size);
155- }
109+ // Optimized for low-latency trading
110+ let low_latency_config = Config :: low_latency (); // Uses OER, skips validation
156111
157- #[cfg(test)]
158- mod tests {
159- use super :: * ;
112+ // Optimized for reliability and compliance
113+ let high_reliability_config = Config :: high_reliability (); // Uses DER, full validation
160114
161- #[test]
162- fn test_configuration_examples () {
163- configuration_examples (); // Should run without panicking
164- }
165- }
115+ // Custom configuration
116+ let mut custom_config = Config :: new ( EncodingRule :: OER );
117+ custom_config . max_message_size = 16 * 1024 ; // 16KB limit
118+ custom_config . enable_zero_copy = true ;
119+ custom_config . validate_checksums = false ; // Disable for performance
166120```
167121
122+ ** Run the example** : ` cargo run --example configuration `
123+
168124## Performance Considerations
169125
1701261 . ** Encoding Rule Selection** :
@@ -185,40 +141,17 @@ RustyASN integrates with Simple Open Framing Header (SOFH) for message framing:
185141``` rust
186142use rustyasn :: EncodingRule ;
187143
188- // SOFH encoding type enum for demonstration (would come from rustysofh crate)
189- #[derive(Debug )]
190- enum EncodingType {
191- Asn1BER ,
192- Asn1OER ,
193- }
194-
195- fn sofh_integration_example (rule : EncodingRule ) -> EncodingType {
196- // SOFH encoding types for ASN.1
144+ // Map ASN.1 encoding rules to SOFH encoding types
145+ fn map_asn1_to_sofh (rule : EncodingRule ) -> EncodingType {
197146 match rule {
198147 EncodingRule :: BER | EncodingRule :: DER => EncodingType :: Asn1BER ,
199148 EncodingRule :: OER => EncodingType :: Asn1OER ,
200149 }
201150}
202-
203- fn main () {
204- let ber_encoding = sofh_integration_example (EncodingRule :: BER );
205- let oer_encoding = sofh_integration_example (EncodingRule :: OER );
206-
207- println! (" BER/DER uses: {:?}" , ber_encoding );
208- println! (" OER uses: {:?}" , oer_encoding );
209- }
210-
211- #[cfg(test)]
212- mod tests {
213- use super :: * ;
214-
215- #[test]
216- fn test_sofh_integration () {
217- main (); // Should run without panicking
218- }
219- }
220151```
221152
153+ ** Run the example** : ` cargo run --example sofh_integration `
154+
222155## Safety and Security
223156
224157- Maximum message size limits prevent DoS attacks
0 commit comments