FIX SBE XML Primer (original) (raw)

FIX/SBE uses an XML format to specify messages, headers, and other elements. The system is typed and users can create new types from primitives. In this section, we will discuss the practical aspects of the XML specification. For details, please see the FIX/SBE specification. An example schema can be found here. An XSD for SBE specifications can be found here.

messageSchema Element

The messageSchema element is the root document in XML. It contains primarily all types and messages specified. This element has the following attributes:

An example messageSchema element would be:

<messageSchema package="uk.co.real_logic.sbe.examples"
               id="777"
               semanticVersion="5.2"
               description="Code generation unit test support"
               byteOrder="littleEndian">

A messageSchema holds two main components. a list of <types> and a list of <message> elements.

types Element

The types block holds various types created <type>, <set>, <enum>, and <composite>.

Primitive Types

All encoding and decoding for SBE is centered around a set of basic primitive types. These are the primitive types.

type Element

Types can be created by name and by composing a set of builtin primitive types. The <type>element has the following attributes.

An few examples of the use of <type> are below:

<type name="ModelYear" primitiveType="uint16" semanticType="ModelYear"/>
<type name="VehicleCode" primitiveType="char" length="6" semanticType="VehicleCode"/>
<type name="someNumbers" primitiveType="int32" length="5" semanticType="SomeArray"/>

enum Element

Enumerations use the <enum> element. This element contains the valid values for the enum. The element has the following attributes:

<validValue> elements are contained within the <enum> to hold the information about the values. Each element has the following attributes: name and description. The contents of the <validValue> element contains the value itself.

Examples of the use of <enum> are below:

<enum name="BooleanType" encodingType="uint8" semanticType="Boolean">
    <validValue name="FALSE">0</validValue>
    <validValue name="TRUE">1</validValue>
</enum>

<enum name="Model" encodingType="char" semanticType="Model">
    <validValue name="A">A</validValue>
    <validValue name="B">B</validValue>
    <validValue name="C">C</validValue>
</enum>

set Element

Bit sets use the <set> element. This element contains the choice values for the bit set. The element has the following attributes:

<choice> elements are contained within the <set> to hold the information about the values. Each element has the following attributes: name and description. The contents of the <choice> element contains the bit position of that choice. I.e. 0 means bit position 0, 1 means bit position 1, etc.

Examples of the use of <set> are below:

<set name="OptionalExtras" encodingType="uint8" semanticType="Extras">
    <choice name="sunRoof">0</choice>
    <choice name="sportsPack">1</choice>
    <choice name="cruiseControl">2</choice>
</set>

composite Element

A composite is a structure of encoded types. The encoding is in the order of declaration. Some composite elements are used for message header declaration as well as variable length field encoding and group dimension encoding. The <composite> element has the following attributes.

Examples of the use of <composite> are below:

<composite name="messageHeader" description="Message identifiers and length of message root">
    <type name="blockLength" primitiveType="uint16"/>
    <type name="templateId" primitiveType="uint16"/>
    <type name="schemaId" primitiveType="uint16"/>
    <type name="version" primitiveType="uint16"/>
</composite>

<composite name="Booster">
    <enum name="BoostType" encodingType="char">
        <validValue name="TURBO">T</validValue>
        <validValue name="SUPERCHARGER">S</validValue>
        <validValue name="NITROUS">N</validValue>
        <validValue name="KERS">K</validValue>
    </enum>
    <type name="horsePower" primitiveType="uint8"/>
</composite>

<composite name="Engine" semanticType="Engine">
    <type name="capacity" primitiveType="uint16"/>
    <type name="numCylinders" primitiveType="uint8"/>
    <type name="maxRpm" primitiveType="uint16" presence="constant">9000</type>
    <type name="manufacturerCode" primitiveType="char" length="3"/>
    <type name="fuel" primitiveType="char" presence="constant">Petrol</type>
    <ref name="booster" type="Booster"/>
</composite>

The messageHeader composite is treated as the header for all messages included in the message schema.

A member of a composite can reference another type, with the ref tag, to include it for reuse.

message Element

Message elements contain the fields, repeating groups, and variable length data. The order of <field>, <group>, and <data> within each message is very important as it is used to lay the data out in a message. All <field> declarations must precede all <group> and <data> elements. All <group> elements must precede all <data> elements. This ordering ensures that all fixed length fields are at the front of the message. Followed by repeating groups and then followed by variable length data. A <message> element itself has the following attributes:

An example <message> use is below:

<message name="Car" id="1" description="Description of a basic Car">

field Element

Field elements designate the fixed size fields of a message. A <field> element has the following attributes:

Examples of the use of <field> are below:

<field name="serialNumber" id="1" type="uint32" semanticType="SerialNumber"/>
<field name="modelYear" id="2" type="ModelYear"/>
<field name="available" id="3" type="BooleanType"/>
<field name="code" id="4" type="Model"/>
<field name="someNumbers" id="5" type="someNumbers"/>
<field name="vehicleCode" id="6" type="VehicleCode"/>
<field name="extras" id="7" type="OptionalExtras"/>
<field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C"/>
<field name="engine" id="9" type="Engine"/>

group Element

Group elements designate a repeating group in a message. Each group contains one or more <field> elements. In addition, the group dimensions must have been declared as a composite type. <group> elements may be nested arbitrarily deep. A <group> element has the following attributes:

When numInGroup type is set to uint8, a group element may contain up to 256 entities. This type can be set to uint16 in order for the group to contain up to 65,536 entities. A group cannot contain more than 65,536 entities.

Examples of the use of <field> are below:

<composite name="groupSizeEncoding" description="Repeating group dimensions" >
     <type name="blockLength" primitiveType="uint16"/>
     <type name="numInGroup" primitiveType="uint8" semanticType="NumInGroup"/>
</composite>

<group name="fuelFigures" id="9" dimensionType="groupSizeEncoding">
     <field name="speed" id="10" type="uint16"  semanticType="int"/>
     <field name="mpg" id="11" type="float" semanticType="int"/>
</group>

A nested repeating group example is below:

<group name="performanceFigures" id="12" dimensionType="groupSizeEncoding">
    <field name="octaneRating" id="13" type="uint8" semanticType="RON"/>
    <group name="acceleration" id="14" dimensionType="groupSizeEncoding">
         <field name="mph" id="15" type="uint16"  semanticType="int"/>
         <field name="seconds" id="16" type="float" semanticType="int"/>
    </group>
</group>

data Element

Data elements designate the variable length fields of a message. The data is encoded as a length followed by the variable data. This type must have been declared as a composite type in a specific way. A <data> element has the following attributes:

Examples of the use of <data> are below:

<composite name="varDataEncoding">
    <type name="length" primitiveType="uint16" semanticType="Length"/>
    <type name="varData" primitiveType="uint16" length="0" characterEncoding="UTF-8"/>
</composite>

<data name="make" id="17" type="varDataEncoding" semanticType="Make"/>
<data name="model" id="18" type="varDataEncoding" semanticType="Model"/>