Framing and message headers
Each SBE message contains two headers: Simple Open Framing Header (SOFH) and message header. These headers contain service information required to successfully decode SBE message.
Simple Open Framing Header (SOFH)
This header usually includes two fields: an encoding method signature and the total message size. The exact format and data types of these fields vary by venue. The OnixS SBE toolset offers a set of classes to help you construct specifications for such headers.
Specifying of the SOFH for message handling
The SOFH specification is always used when the MessageSchema instance is created. The specification can be used implicitly (it is deprecated way, but it still can be used), or explicitly (the recommended way).
Implicit SOFH specification
When using the SOFH specification implicitly, only two variants are available: the CME MD3 SOFH and the SBE standard header.
The SBE standard header is used by default:
// Standard SBE header
MessageSchema schema = new MessageSchema(ParseUtil.parse(new File("SbeTemplate.xml")));
Also, it can be specified by the flag:
// Standard SBE header
MessageSchema schema = new MessageSchema(ParseUtil.parse(new File("SbeTemplate.xml")), false);
The CME MDP3 SOFH usage can be specified by setting of the constructor second parameter to true:
// MDP3 SOFH
MessageSchema schema = new MessageSchema(ParseUtil.parse(new File("CmeTemplate.xml")), true);
Explicit SOFH specification
You must explicitly specify the SOFH specification when using the MessageSchema constructor. In the example below, the B3 SBE header specification is used. (See the next chapter for a list of predefined SOFH specifications.)
// Custom header
MessageSchema schema = new MessageSchema(ParseUtil.parse(new File("B3Template.xml")),
FramingHeaderPolicy.getCustomPolicy(FramingHeaderSpecification.B3_FRAMING_HEADER));
Predefined SOFH specifications
The OnixS SBE toolset contains a set of SOFHs for widely known venues.
| Name | Description |
|---|---|
| SBE_BE_FRAMING_HEADER | Standard SBE header in big-endian format. |
| B3_FRAMING_HEADER | B3 SBE header. |
| CMEILINK3_FRAMING_HEADER | CME iLink3 SBE header. |
| CMEMDP3_FRAMING_HEADER | CME MDP3 SBE header. |
Creating of custom SOFH
To create your own SOFH specification, ensure the following information is clearly defined:
- Which fields are included in the SOFH;
- The byte order for each field.
Additionally, adhere to these limitations:
- The SOFH may contain only two fields: one for the message size and an optional field for byte order specification.
- The SOFH must not include any additional non-standard or user-defined fields.
For example, consider an SOFH with the following structure:
- SOFH byte order: little-endian;
- Field 1: frame length, 2-byte unsigned integer;
- Field 2: standard 2-byte SBE byte order marker.
In this case, the SOFH specification should look like:
public final static FramingHeaderSpecification MY_FRAMING_HEADER = new FramingHeaderSpecification(
// Size field specification
new FramingHeaderSpecification.FieldSpecification(
0, // Offset in the header
2, // Size of the field
false, // Unsigned
MessageSchema.Endianess.LittleEndian // Byte order of this field
),
// Message byte order marker specification
new FramingHeaderSpecification.EndianessFieldSpecification(
2, // Offset in the header
2, // Size of the field
false, // Unsigned
MessageSchema.Endianess.LittleEndian, // Byte order of the field
FramingHeaderSpecification.SBE_1_0_LE_LITTLEENDIAN_SIGN, // Mark for little-endian byte order of the message.
FramingHeaderSpecification.SBE_1_0_LE_BIGENDIAN_SIGN // Mark for big-endian byte order of the message.
)
);
Please note the following details:
- The field order is explicitly defined by the field offset parameters in the constructors of the relevant objects.
- The byte order marker field should have two variants: one for little-endian SBE messages and one for big-endian messages.
- The byte order of the header itself is specified explicitly and is independent of the SBE message's byte order.
This SOFH specification must be used in the MessageSchema constructor:
// Custom header
MessageSchema schema = new MessageSchema(ParseUtil.parse(new File("MyTemplate.xml")),
FramingHeaderPolicy.getCustomPolicy(MY_FRAMING_HEADER));
Message header
The message header precedes the message content and contains service information necessary for message analysis. The SBE standard defines the names and semantics of specific fields within the header, and its exact structure must be specified in the SBE template. Additionally, the OnixS SBE toolset allows you to extend the message header by adding user-defined fields.
If the message header contains only standard fields, they are handled automatically, requiring no additional user code for message encoding or decoding. However, if the message header is extended with user-defined fields, those fields must be updated separately in your code. The most appropriate APIs for this are Stateless composite or Access via virtual fields.
The ByteDecoder class consistently produces a binary packet with all headers correctly attached and initialized.
Java SBE Decoder