# SBE: reading the XML message schema

> Learn how an SBE XML message schema declares byte order, reusable types, presence and null rules, messages and schema versions—and how each XML element maps to wire bytes.

Page: https://structure.fi/guides/sbe-schema-file/

Simple Binary Encoding (SBE) is the FIX Trading Community's binary wire format used by exchanges and trading systems for low-latency market data and order entry ([how an SBE message is laid out](https://structure.fi/guides/sbe-message-layout/)). Because SBE wire bytes carry no field names or tags, every decoder—generated or dynamic—starts from the venue's XML **message schema**.

Reading that XML file tells you the byte order, message header, type encodings, null rules, field order, and version history. This page maps each XML element to what actually appears on the wire, using Binance's bundled Spot Streams (`binance_stream_1_0_sbe.xml`) and Spot API (`binance_spot_3_6_sbe.xml`) schemas.

## A schema at a glance

Open the bundled Binance Spot Streams schema in the Market Data Visualizer to compare its root attributes and the `TradesStreamEvent` declaration below with the XML elements described here.

[Open the Binance streams schema attributes in the Market Data Visualizer](https://structure.fi/tools/market-data-visualizer/app/#open?sample=binance-stream&place=detail&guide=sbe-schema-file&section=block-4)

TradesStreamEvent in the Binance Spot Streams SBE schema, as the Market Data Visualizer's text view writes it:

```text
TradesStreamEvent :: message @10000 {
    eventTime:     utcTimestampUs;  @1
    transactTime:  utcTimestampUs;  @2
    priceExponent: exponent8;       @3
    qtyExponent:   exponent8;       @4
    trades:        group            @100 {
        id:           tradeId;                        @1
        price:        mantissa64;                     @2
        qty:          mantissa64;                     @3
        isBuyerMaker: boolEnum;                       @4
        isBestMatch:  boolEnum const = boolEnum.True; @5
    }
    symbol:        data varString8; @200
}
```

## The schema element

The root `<messageSchema>` element sets protocol-wide properties:

- `package`: namespace/package name for generated code (`spot_stream` here; `spot_sbe` in Spot API).
- `id`: numeric schema id carried in every header's `schemaId` (`1` for streams, `3` for Spot API).
- `version`: schema version carried in every header's `version` (`0` for streams, `6` for Spot API 3.6).
- `byteOrder`: `littleEndian` (default) or `bigEndian` ([endianness](https://structure.fi/guides/binary-message/#endianness)).
- `headerType`: [composite](#composites) used as the [message header](https://structure.fi/guides/sbe-message-header/) (defaults to `messageHeader`).

Schemas can split shared types into separate files using XInclude (`xi:include`). Open included files in the same project alongside the root schema or the app reports [IncludeNotProvided](https://structure.fi/tools/market-data-visualizer/guides/problem-codes.md#includenotprovided).

## Types

`<types>` defines every reusable type in four forms:

### Simple types

`<type>` wraps an SBE primitive (`char`, `int8`–`int64`, `uint8`–`uint64`, `float`, `double`) with optional attributes: `length` (fixed array), `minValue` / `maxValue`, `nullValue` ([presence and null values](#presence-and-null-values)), and `presence="constant"` (schema-only, 0 wire bytes). In Binance's schemas, `mantissa64` wraps `int64`:

### Composites

`<composite>` packs multiple members back to back into one inline type—used for decimal prices ([precision, scale and exponent](https://structure.fi/guides/prices-and-times-as-integers/#precision-scale-and-exponent)), repeating-group dimension headers (`groupSizeEncoding`, see [variable-sized data and lists](https://structure.fi/guides/variable-sized-data/#sbe-count-prefixed-groups-and-length-prefixed-data)), [variable-length data](https://structure.fi/guides/sbe-variable-length-data/) headers (`varString8`, `messageData`), and `messageHeader`:

### Enums

`<enum>` maps named values to a `char` or unsigned integer `encodingType`. In Binance's schemas, `boolEnum` encodes 2 values (`False`, `True`) as `uint8`:

### Sets

`<set>` defines a bit field over an unsigned integer, where each `<choice>` names a bit position and multiple choices may be active together. In the Spot API schema, `orderTypes` packs 8 choices into a `uint16` with `Market` at bit `0`:

## Messages

Each `<message>` has a unique `id` (sent as `templateId` in the header) and declares its members in strict wire order:

1. `<field>`: fixed-size root-block fields ([how an SBE message is laid out](https://structure.fi/guides/sbe-message-layout/)).
2. `<group>`: repeating groups ([variable-sized data and lists](https://structure.fi/guides/variable-sized-data/#sbe-count-prefixed-groups-and-length-prefixed-data)), each with its own fields, nested groups, and data.
3. `<data>`: [variable-length data](https://structure.fi/guides/sbe-variable-length-data/) fields.

A `<field>` requires `name`, `id`, and `type`. Its `id` is its FIX tag number—never written on the wire, and it does not determine byte order or offset. Offsets follow XML declaration order unless a field explicitly sets `offset`.

### Presence and null values

Every SBE field or type declares a `presence` attribute:

- `required` (default): always carries a valid value, never a null value.
- `optional`: may be empty, which a reserved null value says while the field still takes its full byte width ([null values](https://structure.fi/guides/binary-message/#null-values)).
- `constant`: fixed in the schema (often referencing an enum value via `valueRef`, like `isBestMatch` in `TradesStreamEvent/trades`); takes zero bytes on the wire.

When an optional type declares no `nullValue`, SBE reserves one end of its primitive's range: the minimum for signed integers (`−128` for `int8`, `−2^31` for `int32`, `−2^63` for `int64`), the maximum for unsigned integers (`255` for `uint8`, `65535` for `uint16`, `2^32 − 1` for `uint32`), `0` for `char`, a quiet `NaN` for `float` and `double`, and a mantissa of `−2^63` for a 64-bit decimal. Any type can set its own with `nullValue` (B3 Binary UMDF sets `nullValue="0"` on several integer types), so a decoder reads each type's null value from the schema instead of assuming the defaults. In the Binance Spot API sample, `orderListId` in `NewOrderAckResponse` is optional:

## Versions and sinceVersion

Backward-compatible schema updates append new fields, groups, or data after existing ones and tag each addition with `sinceVersion` (and retired items with `deprecated`, keeping them on the wire during migration). While `binance_stream_1_0_sbe.xml` is at version `0`, `binance_spot_3_6_sbe.xml` is at version `6` and uses `sinceVersion` extensively—such as `subscriptionId` (`sinceVersion="1"`) on `BalanceUpdateEvent`. See [schema versioning](https://structure.fi/guides/schema-versioning/) for how decoders handle version mismatches using `version` and `blockLength`.

[Open subscriptionId and its sinceVersion in the Market Data Visualizer](https://structure.fi/tools/market-data-visualizer/app/#open?sample=binance-spot&node=m601%2Ff5&place=detail&guide=sbe-schema-file&section=block-45)

## What to check when reading a schema

- Check `<messageSchema>` first for `byteOrder`, `headerType`, `id`, and `version`, plus any `xi:include` files you must load alongside it.
- Ignore field `id` numbers when computing offsets; only XML order, explicit `offset`, and `presence="constant"` affect wire positions.
- Inspect each type's `nullValue` and `presence` rather than relying on SBE defaults.

## Sources

- https://www.fixtrading.org/what-is-the-fix-protocol/
- https://www.fixtrading.org/standards/sbe/
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding/blob/master/v1-0-STANDARD/doc/04MessageSchema.md
- https://github.com/FIXTradingCommunity/fix-simple-binary-encoding/blob/master/v1-0-STANDARD/doc/05SchemaExtensionMechanism.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.
