Table of contents


To illustrate message template processing, we'll use a template for a FIX Market Data Incremental Update message, FIX message type X.

<template dictionary="1" id="1" name="MDIncRefreshSample_1">
    <string id="35" name="MessageType">
        <constant value="X"></constant>
    </string>     <string id="49" name="SenderCompID">
        <constant value="Client"></constant>
    </string>     <string id="56" name="TargetCompID">
        <constant value="Server"></constant>
    </string>     <uint32 id="34" name="MsgSeqNum"></uint32>
    <uint64 id="52" name="SendingTime"></uint64>
    <sequence name="MDEntries">
        <length id="268" name="NoMDEntries"></length>
        <uint32 id="279" name="MDUpdateAction">
            <copy value="1"></copy>
        <string id="269" name="MDEntryType">
            <copy value="0"></copy>
        <uint32 id="278" name="MDEntryID"></uint32>
        <uint32 id="48" name="SecurityID">
        <decimal id="270" name="MDEntryPx">
                <default value="-2"></default>
        <int32 id="271" name="MDEntrySize">
        <string id="37" name="OrderID"></string>
        <uint32 id="273" name="MDEntryTime">

In the sample java snippet below, we are importing the FAST message templates from an xml into a java HashMap for easy access in the rest of our application.

Map messageTemplates = new HashMap();
public void readTemplates() {
    int templateId;
    for (int i =0; i &lt; msgTemplatesCount; i++) {
        templateId = parseTemplateId();
        messageTemplates.put(templateId, new MessageTemplate(parseTemplateFields()));

The second decoding step is to identify the template ID. The following code snipping receives one FAST message, extract this message PMap, decodes the template ID, obtains the message template, and decode the message content using the template:

int templateId;
Message outputMessage;
int offset;
public Object decodeMessage(byte[] fastMessage) {
    offset = 0;
    // Get a presence map of the whole message
    presenceMap = new PresenceMap();
    offset = presenceMap.init(data, offset);
    if (presenceMap.isNextPMapBitSet()) {
        templateId = dataTypeDecoder.processUnInt32Decoding(fastMessage, offset);
    messageTemplate = templateParser.getTemplate(templateId);
    outputMessage = new Message();
    messageTemplate.decode(fastMessage, offset, presenceMap, outputMessage);

In FAST, template ID is encoded as an unsigned integer, so we decode it with the rules for this data type and get the matching template. We then use that template and the rest of the encoded data and, following the definitions within the template, generate the original message.

Let's decode templateID for FAST message 0xC0 0xA9 from section 3.1.

    • As we defined above our PMap looks like: 1100 0000. First bit is StopBit and the second bit says us that we have next FAST entry in the messsage.
      As per message template definition it is templateID. So we take the second byte and decode it as templateID.
    • Second byte is 0xA9 and its bit representation: 1010 1001.
      As this field type is "Unsigned Integer" and according to the this Data type rules, we can get its value as just removing the first bit: 0101001.
    • We convert these bits into decimal format and receive 41. So our templateID is 41.