SBE: variable-length data fields
Learn how SBE encodes variable-length strings and raw byte payloads as length-prefixed data fields, why they must sit last in a message or group entry, and how they behave across versions.
Simple Binary Encoding (SBE) is the FIX Trading Community's binary format for low-latency market data and order entry (how an SBE message is laid out). SBE achieves fast decoding by placing fixed-size fields—prices, quantities, timestamps—at constant byte offsets known from the schema. Real trading messages still carry values whose byte length changes from message to message, such as ticker symbols (BTCUSDT vs ETHBTC), client order ids, or nested binary payloads (variable-sized data and lists).
SBE encodes those values as variable-length data fields (<data> in the XML schema): an unsigned length prefix immediately followed by that many bytes. This page explains how SBE declares data fields as two-part composites, why they must always sit after all fixed fields and repeating groups, and what to watch for when schemas evolve.
Seeing data fields in Binance's SBE samples
In TradesStreamEvent (bundled Binance Spot Streams sample), symbol sits at the very end after the trades repeating group. The Market Data Visualizer lays out every data field as empty (0 payload bytes), so each Data row's size equals its length prefix (1 byte for varString8).
| Offset | Size | Name | Type | Presence | Since |
|---|---|---|---|---|---|
| 0 | 18 | TradesStreamEvent | block | 0 | |
| 0 | 8 | eventTime | utcTimestampUs | required | 0 |
| 8 | 8 | transactTime | utcTimestampUs | required | 0 |
| 16 | 1 | priceExponent | exponent8 | required | 0 |
| 17 | 1 | qtyExponent | exponent8 | required | 0 |
| 18 | 6 | trades | group groupSizeEncoding | 0 | |
| 18 | 2 | .blockLength | uint16 | ||
| 20 | 4 | .numInGroup | uint32 | ||
| 24 | 25 | [0] | entry | ||
| 24 | 8 | .id | tradeId | required | 0 |
| 32 | 8 | .price | mantissa64 | required | 0 |
| 40 | 8 | .qty | mantissa64 | required | 0 |
| 48 | 1 | .isBuyerMaker | enum boolEnum | required | 0 |
| — | 0 | .isBestMatch | const enum boolEnum | constant | 0 |
| 49 | 1 | symbol | data varString8 | 0 |
Open the symbol data field in the Market Data Visualizer's layout
Data fields also appear inside repeating group entries—for example, commissionAsset inside each fills entry of NewOrderFullResponse in the bundled Binance Spot API sample—and can carry raw binary blobs such as a nested SBE message (result of type messageData in WebSocketResponse).
The length prefix
A data field's type is a two-member composite:
length: unsigned integer giving the payload byte count.varData: the payload bytes, declared withlength="0"to mean variable length.
The schema chooses the width of length to fit the data. In Binance's schemas, short strings such as symbol use varString8 (1-byte uint8 length + UTF-8 bytes), whereas WebSocketResponse/result uses messageData (4-byte uint32 length + raw bytes). Always inspect the composite instead of assuming a width.
Open varString8 in the Market Data Visualizer
Why data fields come last
Both at the message root and inside each repeating group entry, SBE requires fixed-size fields first, repeating groups second, and data fields last. Putting data fields last keeps every fixed-size field at a constant schema offset; if a fixed field followed a data field, its offset would shift on every message.
The tradeoff is sequential reading: in NewOrderAckResponse (which has two trailing data fields, symbol then clientOrderId), a decoder must read symbol's length prefix and skip its bytes before it can reach clientOrderId. Generated decoders enforce reading groups and data fields in schema order.
Data fields and versions
Newer schema versions may only append new data fields after existing ones at the same level, marked with sinceVersion (schema versioning).
- At the end of a message: safe—older decoders stop after the data fields they know.
- Inside a group entry: safe only if the group's dimension header includes
numVarDataFields(the message header). Without that count, an older decoder cannot skip the unknown data field to find the next entry.
What to check when decoding
- Check the width of
lengthin the schema's data composite (uint8,uint16, oruint32) and itscharacterEncoding. - Always read data fields strictly in schema order—never seek ahead by a fixed offset after the first data field.
- Validate
lengthagainst the remaining buffer or framing length before readingvarData.
See how an SBE message is laid out for how data fields fit into the full message.
Sources
- https://www.fixtrading.org/standards/sbe/
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding/blob/master/v1-0-STANDARD/doc/02FieldEncoding.md
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding/blob/master/v1-0-STANDARD/doc/03MessageStructure.md
- https://github.com/real-logic/simple-binary-encoding/wiki/FIX-SBE-XML-Primer
Reviewed by Structure on 2026-11-24. Last changed 2026-11-23.