forwardSbe Coding   Table of ContentSbe Decoding Templatesforward
Sbe Decoding Encoding Using Message Object

SBE Protocol Decoding and Encoding using Message object.

To encode a FIX message into a SBE stream, the Encoder class is used:

using FIXForge.NET.FIX;
using FIXForge.NET.FIX.SBE;

Message message = new Message();
Encoder encoder = new Encoder(xmlTemplate);

int SimpleSbeMessageTemplateId = 100;
byte[] sbeStreamChunk = new byte[1000];

uint rootLen = 0;
uint encodedLen = encoder.Encode(message, SimpleSbeMessageTemplateId, (int)encoder.SchemaVersion(), sbeStreamChunk, 0, out rootLen);

To decode a part of a SBE stream back into a FIX message, the Decoder class is used.

Please note, that it is needed to obtain three separate values for: Sbe schema version; Sbe template identifier; size of the root block of the message to decode.

Usually, the data arranged in the message header. Decoding of the header is not covered by the SBE decoder, and the header has to be decoded by separate user code.

using FIXForge.NET.FIX;
using FIXForge.NET.FIX.SBE;

Decoder decoder = new Decoder(xmlTemplate);

uint rootBlockLength = 0;
int templateId = 0;
int schemaId = 0;
int version = 0;

int offset = 0;
offset += ParseMessageHeader(encodedData, offset, ref rootBlockLength, ref templateId, ref schemaId, ref version);

if (schemaId != decoder.SchemaId())
    throw new ApplicationException("Unsupported Sbe schema.");

uint numberOfDecodedBytes = 0;
Message message = decoder.Decode(templateId, version, rootBlockLength, encodedData, offset, encodedData.Length, out numberOfDecodedBytes);