FIX/FAST Protocol Decoder/Encoder
FAST (FIX Adapted for STreaming protocol) is a space and processing efficient encoding method for message oriented data streams.
The FAST protocol has been developed as part of the FIX Market Data Optimization Working Group. FAST data compression algorithm is designed to optimize electronic exchange of financial data, particularly for high volume, low latency data dissemination. It significantly reduces bandwidth requirements and latency between sender and receiver. FAST works especially well at improving performance during periods of peak message rates.
Technical Specification: https://www.fixtrading.org/standards/fast-online/
Supported version: 1.x.1
Usage
Add to your Cargo.toml
:
[]
= "0.3"
Serialize/Deserialize using serde
For templates defined in XML, e.g.:
Define the message types in Rust:
use ;
Some implementation guidelines:
<templates>
must be implemented asenum
;<decimal>
can be deserialized tof64
orfastlib::Decimal
(if you need to preserve original scale);<byteVector>
is aVec<u8>
and must be prefixed with#[serde(with = "serde_bytes")]
;<sequence>
is aVec<SequenceItem>
, whereSequenceItem
is astruct
;<group>
is a nestedstruct
;- fields with optional presence are
Option<...>
; - static template reference can be plain fields from the template or flattened
struct
, - dynamic template references must be
Box<Message>
with#[serde(rename = "templateRef:N")]
, whereN
is a 0-based index of the<teplateRef>
in its group.
To deserialize a message call fastlib::from_slice
, fastlib::from_buffer
, fastlib::from_bytes
or more generic fastlib::from_reader
or fastlib::from_stream
:
use Decoder;
// Create a decoder from XML templates.
let mut decoder = new_from_xml?;
// Raw data that contains one message.
let raw_data: = vec!;
// Deserialize a message.
let msg: Message = from_slice?;
To serialize a message call fastlib::to_vec
, fastlib::to_bytes
, fastlib::to_writer
, fastlib::to_stream
or fastlib::to_buffer
:
use Encoder;
// Create an encoder from XML templates.
let mut encoder = new_from_xml?;
// Message to serialize.
let msg = MDHeartbeat;
// Serialize a message.
let raw: = to_vec?;
Decode to JSON
use Decoder;
use JsonMessageFactory;
// Create a decoder from XML templates.
let mut decoder = new_from_xml?;
// Raw data that contains one message.
let raw_data: = vec!;
// Create a JSON message factory.
let mut msg = new;
// Decode the message.
decoder.decode_vec?;
println!;
Decode using own message factory
Make a new struct that implements fastlib::MessageFactory
trait:
use ;
You have to implement callbacks that will be called during message decoding:
For examples see implementation for fastlib::text::TextMessageFactory
or fastlib::text::JsonMessageFactory
but more likely you will want to construct you own message structs.
Then create a decoder from templates XML file and decode a message:
use Decoder;
// Create a decoder from XML templates.
let mut decoder = new_from_xml?;
// Raw data that contains one message.
let raw_data: = vec!;
// Create a message factory.
let mut msg = MyMessageFactory;
// Decode the message.
decoder.decode_vec?;
Examples
License
This project is licensed under the MIT license.