Encoding And Decoding Data Using FAST
FAST (FIX Adapted for Streaming) is a binary encoding method for message-oriented data streams.
FAST-related classes can be found in the OnixS.Fix.Fast
namespace.
Encoding FIX Messages
To encode a FIX message into a FAST stream, use the Encoder class.
For example:
const bool encodeEachMessageIndependently = true;
Encoder encoder = new Encoder(fastTemplateStream, ProtocolVersion.Fix44.ToDictionary(), encodeEachMessageIndependently);
const int templateIdentifier = 88;
byte[] fastStreamChunk = encoder.Encode(fixMessage, templateIdentifier);
Decoding FIX Messages
To decode a part of a FAST stream back into a FIX message, use the Decoder class.
For example:
const bool decodeEachMessageIndependently = true;
var decoder = new Decoder(fastTemplateStream, ProtocolVersion.Fix44.ToDictionary(), decodeEachMessageIndependently);
Message fixMessage = decoder.Decode(fastStreamChunk);
Decoding FIX Messages Sequentially
To decode a sequence of FIX messages, use the DecodeResult class. Its instance receives data that are used to calculate the position of the next decoding operation in the input data chunk.
Note
The DecodeResult instance is cleaned up during the decoding operation and filled with the new data.
For example:
const bool decodeEachMessageIndependently = true;
var decoder = new Decoder(fastTemplateStream, ProtocolVersion.Fix44.ToDictionary(), decodeEachMessageIndependently);
DecodeResult decodeResult = new DecodeResult();
// Decode the first message in the chunk:
decoder.Decode(decodeResult, fastStreamChunk, initialOffset);
Message fixMessage0 = decodeResult.FixMessage;
// Decode the next message:
decoder.Decode(decodeResult, fastStreamChunk, decodeResult.NewOffset);
Message fixMessage1 = decodeResult.FixMessage;
Decoding FIX Messages Using Automatically Generated Dictionaries
It is possible to generate the FIX dictionary directly from the FAST template. To accomplish this task, use the DictionaryBuilder class.
The generated dictionary can be used for Decoder and Encoder in the same manner as built-in dictionaries. Once passed to the appropriate constructor, the dictionary becomes accessible via the FixDictionary property.
For example:
IMessageInfoDictionary generatedDictionary = DictionaryBuilder.BuildDictionary(ProtocolVersion.Fix44.ToDictionary(), fastTemplateStream);
const bool decodeEachMessageIndependently = true;
Decoder decoder = new(fastTemplateStream, generatedDictionary, decodeEachMessageIndependently);
Message fixMessage = decoder.Decode(fastStreamChunk);
IMessageInfoDictionary activeDictionary = decoder.FixDictionary;