Skip to content

Commit b6b8df0

Browse files
authored
Merge pull request #67 from donmendelson/issue65
Alignment of var data and repeating groups #65
2 parents 16918dd + f1878d2 commit b6b8df0

File tree

5 files changed

+141
-44
lines changed

5 files changed

+141
-44
lines changed

v2-0-RC1/doc/01Introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,4 @@ Representation of dates and times
185185
Securities and related financial instruments - Codes for exchanges and
186186
market identification (MIC)
187187

188-
XML 1.1 schema standards are located here [W3C XML Schema](http://www.w3.org/XML/Schema.html#dev)
188+
[W3C XML Schema version 1.1](https://www.w3.org/TR/2006/REC-xml11-20060816/)

v2-0-RC1/doc/03MessageStructure.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Message Structure
44
Message Framing
55
------------------------------------------------------------------------------------------------------------------------------------------------------------
66

7-
SBE messages have no defined message delimiter. Version 2.0 of SBE makes it possible to walk the elements of a message to determine its limit, even when the message has been extended. Nevertheless, since internal framing depends on a correct starting point and not encountering malformed messages, it may be desirable to use an external framing protocol when used with transports that do not preserve message boundaries, such as when they are transmitted on a streaming
7+
SBE messages have no defined message delimiter. SBE makes it possible to walk the elements of a message to determine its limit, even when the message has been extended. Nevertheless, since internal framing depends on a correct starting point and not encountering malformed messages, it may be desirable to use an external framing protocol when used with transports that do not preserve message boundaries, such as when they are transmitted on a streaming
88
session protocol or when persisting messages in storage.
99

1010
### Simple Open Framing Header
@@ -78,7 +78,7 @@ The fields of the SBE message header are:
7878
Block length is specified in a message schema, but it is also serialized
7979
on the wire. By default, block length is set to the sum of the sizes of
8080
body fields in the message. However, it may be increased to force
81-
padding at the end of block. See section 3.3.3.3 below.
81+
padding at the end of block. See [Padding](#padding-at-end-of-a-message-or-group).
8282

8383
### Message header schema
8484

@@ -87,7 +87,7 @@ position as shown below. Each of these fields must be encoded as an
8787
unsigned integer type. The encoding must carry the name "messageHeader".
8888

8989
The message header is encoded in the same byte order as the message
90-
body, as specified in a message schema. See section 4.3.1.
90+
body, as specified in a message schema. See section 4.
9191

9292
Recommended message header encoding
9393

@@ -120,9 +120,9 @@ for blockLength.
120120

121121
The total space reserved for the root level of the message not counting
122122
any repeating groups or variable-length fields. (Repeating groups have
123-
their own block length; see section 3.4 below. Length of a
123+
their own block length; see [Group block length](#group-block-length) below. Length of a
124124
variable-length Data field is given by its corresponding Length field;
125-
see section 2.7.3 above.) Block length only represents message body
125+
see section 2.) Block length only represents message body
126126
fields; it does not include the length of the message header itself,
127127
which is a fixed size.
128128

@@ -134,18 +134,18 @@ schema.
134134

135135
### Template ID
136136

137-
The identifier of a message type in a message schema. See section 4.5.2
138-
below for schema attributes of a message.
137+
The identifier of a message type in a message schema. See section 4
138+
for schema attributes of a message.
139139

140140
### Schema ID
141141

142-
The identifier of a message schema. See section 4.3.1 below for schema
142+
The identifier of a message schema. See section 4 for schema
143143
attributes.
144144

145145
### Schema version
146146

147147
The version number of the message schema that was used to encode a
148-
message. See section 4.3.1 below for schema attributes.
148+
message. See section 4 for schema attributes.
149149

150150
### Number of repeating groups
151151

@@ -227,6 +227,8 @@ would cause fields to overlap.
227227
Extra octets specified for padding should never be interpreted as
228228
business data. They should be filled with binary zeros.
229229

230+
The offset attribute is mutually exclusive with alignment; see below.
231+
230232
Example of fields with specified offsets
231233

232234
```xml
@@ -247,6 +249,29 @@ Example of fields with specified offsets
247249
| OrderQty | 4 | 1 | 16 |
248250
| Symbol | 8 | 0 | 20 |
249251

252+
#### Field byte alignment
253+
As an alternative to specifying a field's offset from the start of a block, its byte alignment may be specified. If specified, the start of a field should reside at an offset from the start of the buffer that is the next multiple of the alignment attribute. If the offset without alignment would not be a multiple of the alignment attribute, then the buffer is padded with octets to that multiple. The padding should be set to binary zeroes.
254+
255+
The alignment attribute is mutually exclusive with offset.
256+
257+
If neither offset nor alignment attributes are set, then a field is positioned at the next available octet in a buffer without padding.
258+
259+
Computation of padding and effective offset is as follows, where effective-offset is the resulting position in the buffer:
260+
261+
```
262+
padding = (alignment - (unaligned-offset modulo alignment)) modulo alignment
263+
effective-offset = unaligned-offset + padding
264+
```
265+
266+
Example of fields with alignment that is equivalent to the offset example above:
267+
268+
```xml
269+
<field name="ClOrdID" id="11" type="string14" semanticType="String"/>
270+
<field name="Side" id="54" type="char" semanticType="char"/>
271+
<field name="OrderQty" id="38" type="intQty32" alignment="4" semanticType="Qty"/>
272+
<field name="Symbol" id="55" type="string8" alignment="4" semanticType="String"/>
273+
```
274+
250275
#### Padding at end of a message or group
251276

252277
In order to force messages or groups to align on byte boundaries or map
@@ -308,6 +333,12 @@ fields. (Length of a variable-length Data field is given by its corresponding
308333
Length field.) Block length only represents message body fields; it does not
309334
include the length of the group dimension itself, which is a fixed size.
310335

336+
### Byte alignment of a group entry
337+
338+
If byte alignment of a repeating group is specified, the start of the first field of each entry should reside at an offset from the start of the buffer that is the next multiple of the alignment attribute. If the offset without alignment would not be a multiple of the alignment attribute, then the buffer is padded with octets to that multiple. The padding should be set to binary zeroes.
339+
340+
If byte alignment is not specified for a group, then no padding is introduced to align entries.
341+
311342
### Padding at end of a group entry
312343

313344
By default, the space reserved for an entry is the sum of a group’s
@@ -322,7 +353,7 @@ each entry and should be set to zeroes by encoders. The blockLength
322353
value does not include the group dimensions itself.
323354

324355
Note that padding will only result in deterministic alignment if the
325-
repeating group contains no variable-length fields.
356+
repeating group contains no variable-length fields. Therefore, the alignment attribute is a more direct solution to that need.
326357

327358
### Entry counter
328359

@@ -507,7 +538,7 @@ finally, variable-length data fields.
507538
Message structure validation
508539
--------------------------------------------------------------------------------------------------------------------------
509540

510-
Aside from message schema validations (see section 4.8 below), these
541+
Aside from message schema validations (see section 4), these
511542
validations apply to message structure.
512543

513544
If a message structure violation is detected on a received message, the

v2-0-RC1/doc/04MessageSchema.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ XML schema for SBE message schemas
55
---------
66
See [sbe.xsd](../resources/sbe.xsd) for the normative XML Schema Definition (XSD) for SBE.
77

8+
The SBE schema is defined with W3C XML Schema Definition Language (XSD) version 1.1.
9+
810

911
XML namespace
1012
-----------------------------------------------------------------------------------------------------------
@@ -379,6 +381,10 @@ The `name` and `id` attributes are required. The first is a display name for
379381
a message, while the latter is a unique numeric identifier, commonly
380382
called template ID.
381383

384+
### Byte alignment
385+
386+
By default, a message starts at the first available byte of buffer. However, if desired, it may be aligned to a boundary by specifying the `alignment` attribute to improve performance on certain platforms. If specified, the start of the message should reside in the buffer at the next multiple of the alignment attribute. For example, if `alignment=4` then the message should start at the next address that is a multiple of 4.
387+
382388
### Reserved space
383389

384390
By default, message size is the sum of its field lengths. However, a
@@ -415,6 +421,7 @@ that they are encoded on the wire.
415421
| semanticType | Documents value of FIX MsgType for a message | token | optional | Listed in FIX specifications |
416422
| sinceVersion | Documents the version of a schema in which a message was added | nonNegativeInteger | default = 0 | |
417423
| deprecated | Documents the version of a schema in which a message was deprecated. It should no longer be sent but is documented for back-compatibility. | nonnegativeInteger | optional | Must be less than or equal to the version of the message schema. |
424+
| alignment | Controls byte alignment of the start of a message in its buffer| positiveInteger | optional | |
418425

419426
Note that there need not be a one-to-one relationship between message
420427
template (identified by `id` attribute) and `semanticType` attribute. You
@@ -442,7 +449,8 @@ These are the common attributes of all field types.
442449
| id | Unique field identifier (FIX tag) | unsignedShort | required | |
443450
| description | Documentation | string | optional | |
444451
| type | Encoding type name, one of simple type, composite type or enumeration. | string | required | Must match the name attribute of a simple `<type>`, `<composite>` encoding type, `<enum>` or `<set>`. |
445-
| offset | Offset to the start of the field within a message or repeating group entry. By default, the offset is the sum of preceding field sizes, but it may be increased to effect byte alignment. | unsignedInt | optional | Must be greater than or equal to the sum of preceding field sizes. |
452+
| offset | Offset to the start of the field within a message or repeating group entry. By default, the offset is the sum of preceding field sizes, but it may be increased to effect byte alignment. | unsignedInt | optional | Must be greater than or equal to the sum of preceding field sizes. Mutually exclusive with alignment |
453+
| alignment | Controls byte alignment of the start of a field in its buffer| positiveInteger | optional | Mutually exclusive with offset |
446454
| presence | Field presence | enumeration | Default = required | required = field value is required; not tested for null. optional = field value may be null. constant = constant value not sent on wire. |
447455
| valueRef | Constant value of a field as a valid value of an enumeration | qualifiedName\_t | optional Valid only if presence= ”constant” | If provided, the qualified name must match the name attribute of a `<validValue>` within an `<enum>` |
448456
| sinceVersion | The version of a message schema in which this field was added. | InonnegativeInteger | default=0 | Must not be greater than version attribute of `<messageSchema>` element. |
@@ -487,7 +495,7 @@ The number of members of each type is unbound.
487495
| id | Unique group identifier | unsignedShort | required | |
488496
| description | Documentation | string | optional | |
489497
| dimensionType | Dimensions of the repeating group | symbolicName\_t | default = groupSizeEncoding | If specified, must be greater than or equal to the sum of field lengths. |
490-
498+
| alignment | Controls byte alignment of the start of each group instance in its buffer| positiveInteger | optional | |
491499
`<group>` element inherits attributes of blockType. See `<message>`
492500
above.
493501

v2-0-RC1/doc/05SchemaExtensionMechanism.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Compatibility is only ensured under these conditions:
2424

2525
- Existing fields cannot change data type or move within a message.
2626

27+
- Message and repeating group byte alignment may not change.
28+
2729
- A repeating group may be added after existing groups at the root level or nested within another repeating group.
2830

2931
- A variable-length data field may be added after existing variable-length data at the root level or within a repeating group.

0 commit comments

Comments
 (0)