forwardFAST Coding   Table of ContentFAST Coding Templatesforward
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 FIXForge.NET.FIX.FAST namespace.

Encoding FIX Messages

To encode a FIX message into a FAST stream the Encoder class has to be used:

Example
C#
using FIXForge.NET.FIX;
using FIXForge.NET.FIX.FAST;

const bool encodeEachMessageIndependently = true;

Encoder encoder = new Encoder(ProtocolVersion.FIX44, fastTemplates, encodeEachMessageIndependently);

const int templateIdentifier = 88;

byte[] fastStreamChunk = encoder.Encode(fixMessage, templateIdentifier);
VB
Imports FIXForge.NET.FIX
Imports FIXForge.NET.FIX.FAST

Dim fastEncoder As Encoder = New Encoder(ProtocolVersion.FIX44, fastTemplates, true)

Dim templateIdentifier As Integer = 88

Dim fastStreamChunk() As Byte = fastEncoder.Encode(fixMessage, templateIdentifier)
Decoding FIX Messages

To decode a part of a FAST stream back into a FIX message the Decoder class must be used.

Example
C#
using FIXForge.NET.FIX;
using FIXForge.NET.FIX.FAST;

const bool decodeEachMessageIndependently = true;

Decoder decoder = new Decoder(ProtocolVersion.FIX44, fastTemplates, decodeEachMessageIndependently, InputDataTraits.CompleteMessagesOnly);

Message fixMessage = decoder.Decode(fastStreamChunk);
VB
Imports FIXForge.NET.FIX
Imports FIXForge.NET.FIX.FAST

Dim decodeEachMessageIndependently As Boolean = True;

Dim fastDecoder As Decoder = New Decoder(ProtocolVersion.FIX44, fastTemplates, decodeEachMessageIndependently, InputDataTraits.CompleteMessagesOnly)

Dim fixMessage As Message = fastDecoder.Decode(fastStreamChunk)
Decoding FIX Messages using dialect-independent mode

To decode a part of a FAST stream back into a FIX message, the Decoder class must be used. Dialect-independent mode doesn't need to specify FIX dialect explicitly, only FAST template content is enough. The dialect is generated inside of the decoder and it is accessible through the Dialect property.

Example
C#
using FIXForge.NET.FIX;
using FIXForge.NET.FIX.FAST;

const bool decodeEachMessageIndependently = true;

Decoder decoder = new Decoder(fastTemplates, decodeEachMessageIndependently, InputDataTraits.CompleteMessagesOnly);

Message fixMessage = decoder.Decode(fastStreamChunk);

Dialect dialectUsed = decoder.Dialect;
VB
Imports FIXForge.NET.FIX
Imports FIXForge.NET.FIX.FAST

Dim decodeEachMessageIndependently As Boolean = True;

Dim fastDecoder As Decoder = New Decoder(fastTemplates, decodeEachMessageIndependently, InputDataTraits.CompleteMessagesOnly)

Dim fixMessage As Message = fastDecoder.Decode(fastStreamChunk)

Dim dialectUsed As Dialect = decoder.Dialect;
Decoding FIX Messages using reusable message

To decode a part of a FAST stream back into a FIX message, the Decoder class must be used. There are few methods which allow to reuse of existing FIX message, all the ones have input parameter of the Message. This message should be created before the call and will be used to receive the decoded content. If the message contains some data, it will be automatically cleared at the begin of the decoding.

When the decoding completed successfully, the decoder returns a reference to the input message, which will be updated in accordance with the input binary data. If there is not enough data, the null value will be returned, and the state of input the message will be undefined. This happens because fields of the message are decoded one by one, and if decoding is not completed, only decoded fields will appear at the message. Such "partially decoded" message should not be treated as correct FIX message, but can be reused for another decoding.

Example
C#
using FIXForge.NET.FIX;
using FIXForge.NET.FIX.FAST;

Message fixMessage = /* Create the message by some allowed way */;

const bool decodeEachMessageIndependently = true;

Decoder decoder = new Decoder(fastTemplates, decodeEachMessageIndependently, InputDataTraits.CompleteMessagesOnly);

if (decoder.Decode(fastStreamChunk, fixMessage) == null)
{
    // Another portion of data should be read,
    // and decoding attempt should be repeated.
}
else
{
    // Use fixMessage
}
VB
Imports FIXForge.NET.FIX
Imports FIXForge.NET.FIX.FAST

Message fixMessage = 'Create the message by some allowed way

Dim decodeEachMessageIndependently As Boolean = True;

Dim fastDecoder As Decoder = New Decoder(fastTemplates, decodeEachMessageIndependently, InputDataTraits.CompleteMessagesOnly)

If Nothing = fastDecoder.Decode(fastStreamChunk, fixMessage) Then
    ' Another portion of data should be read,
    ' and decoding attempt should be repeated.
Else
    ' Use fixMessage
End If

Dim dialectUsed As Dialect = decoder.Dialect;