Skip to content

Commit 3571766

Browse files
committed
1 parent fd51109 commit 3571766

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

v1-0-STANDARD/doc/examples.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@
7575
| `4f52443030303031` | 379 | BusinesRejectRefId | 0 | 8 | ORD00001 |
7676
| `06` | 380 | BusinessRejectReason | 8 | 1 | NotAuthorized |
7777
| `4e6f74206175...` | 58 | Text | 0 | 39 | Not authorized to trade that instrument |
78+
### Wire format of field encodings
79+
```
80+
00 50 d4 89 fe a2 24 13 09 fa 00 : P $
81+
```
82+
### Interpretation of field encodings
83+
|Wire format|Field ID|Name|Offset|Length|Interpreted value|
84+
|-----------|-------:|----|-----:|-----:|-----------------|
85+
| `0050d489fea2241309fa00` | 60 | TZTimestamp | 0 | 11 | 2013-09-17T02:30 |

v1-0-STANDARD/src/main/java/io/fixprotocol/sbe/examples/ExampleDumper.java

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.time.LocalDate;
2525
import java.time.LocalDateTime;
2626
import java.time.ZoneOffset;
27+
import java.time.format.DateTimeFormatter;
2728
import java.util.Arrays;
2829
import java.util.concurrent.TimeUnit;
2930

@@ -52,6 +53,8 @@
5253
import io.fixprotocol.sbe.examples.messages.QtyEncodingDecoder;
5354
import io.fixprotocol.sbe.examples.messages.QtyEncodingEncoder;
5455
import io.fixprotocol.sbe.examples.messages.SideEnum;
56+
import io.fixprotocol.sbe.examples.messages.TzTimestampDecoder;
57+
import io.fixprotocol.sbe.examples.messages.TzTimestampEncoder;
5558
import io.fixprotocol.sbe.util.BufferDumper;
5659

5760

@@ -111,9 +114,6 @@ public class ExampleDumper {
111114
*/
112115
public static final String MARKDOWN_TABLE_ROW_END = "|";
113116

114-
private final MessageHeaderDecoder mhDecoder = new MessageHeaderDecoder();
115-
116-
117117
/**
118118
* Output all examples
119119
*
@@ -132,6 +132,7 @@ public static void main(String[] args)
132132
dumper.dumpAll(stream);
133133
}
134134

135+
135136
private static String wireFormat(byte[] bytes, int offset, int width) {
136137
StringWriter writer = new StringWriter();
137138
for (int index = 0; index < width; index++) {
@@ -143,11 +144,13 @@ private static String wireFormat(byte[] bytes, int offset, int width) {
143144
}
144145

145146
private String blockBegin = MARKDOWN_BLOCK_BEGIN;
147+
146148
private String blockEnd = MARKDOWN_BLOCK_END;
147149
private String headingBegin = MARKDOWN_HEADING_BEGIN;
148150
private String headingEnd = MARKDOWN_HEADING_END;
149151
private String literalBegin = MARKDOWN_LITERAL_BEGIN;
150152
private String literalEnd = MARKDOWN_LITERAL_END;
153+
private final MessageHeaderDecoder mhDecoder = new MessageHeaderDecoder();
151154
private String tableColumnDelim = MARKDOWN_TABLE_COLUMN_DELIM;
152155
private String tableRowBegin = MARKDOWN_TABLE_ROW_BEGIN;
153156
private String tableRowEnd = MARKDOWN_TABLE_ROW_END;
@@ -177,6 +180,13 @@ public void dumpAll(PrintStream out) throws UnsupportedEncodingException {
177180
dump(bytes, size, out);
178181
heading("Interpretation", out);
179182
interpretBusinessMessageReject(bytes, size, out);
183+
184+
Arrays.fill(bytes, (byte) 0);
185+
size = encodeFieldEncodings(bytes);
186+
heading("Wire format of field encodings", out);
187+
dump(bytes, size, out);
188+
heading("Interpretation of field encodings", out);
189+
interpretFieldEncodings(bytes, size, out);
180190
}
181191

182192
public int encodeBusinessMessageReject(byte bytes[]) throws UnsupportedEncodingException {
@@ -258,6 +268,24 @@ public int encodeExecutionReport(byte[] bytes) throws UnsupportedEncodingExcepti
258268
return offset;
259269
}
260270

271+
public int encodeFieldEncodings(byte[] bytes) {
272+
TzTimestampEncoder tzEncoder = new TzTimestampEncoder();
273+
MutableDirectBuffer buffer = new UnsafeBuffer(bytes);
274+
int offset = 0;
275+
tzEncoder.wrap(buffer, offset);
276+
LocalDateTime dateTime = LocalDateTime.of(2013, 9, 17, 8, 30);
277+
long time = TimeUnit.SECONDS.toNanos(dateTime.toEpochSecond(ZoneOffset.UTC));
278+
tzEncoder.time(time);
279+
short unit = 9; // nanoseconds
280+
tzEncoder.unit(unit);
281+
byte timezoneHour = -6;
282+
tzEncoder.timezoneHour(timezoneHour);
283+
short timezoneMinute = 0;
284+
tzEncoder.timezoneMinute(timezoneMinute);
285+
offset += tzEncoder.encodedLength();
286+
return offset;
287+
}
288+
261289
public int encodeOrderMsg(byte bytes[]) throws UnsupportedEncodingException {
262290
SofhFrameEncoder sofhEncoder = new SofhFrameEncoder();
263291
MessageHeaderEncoder mhEncoder = new MessageHeaderEncoder();
@@ -472,6 +500,26 @@ public void interpretExecutionReport(byte[] bytes, int size, PrintStream out) {
472500

473501
}
474502

503+
public void interpretFieldEncodings(byte[] bytes, int size, PrintStream out) {
504+
DirectBuffer buffer = new UnsafeBuffer(bytes);
505+
interpretTableHeader(out);
506+
int offset = 0;
507+
TzTimestampDecoder tzDecoder = new TzTimestampDecoder();
508+
tzDecoder.wrap(buffer, offset);
509+
long time = tzDecoder.time();
510+
byte hours = tzDecoder.timezoneHour();
511+
short minutes = tzDecoder.timezoneMinute();
512+
long epochSeconds = TimeUnit.NANOSECONDS.toSeconds(time);
513+
int nanoOfSecond = (int) (time % 1000000000L);
514+
LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(epochSeconds, nanoOfSecond , ZoneOffset.ofHoursMinutes(hours, minutes));
515+
interpretRow(
516+
wireFormat(bytes, offset,
517+
tzDecoder.encodedLength()),
518+
NewOrderSingleDecoder.transactTimeId(), "TZTimestamp",
519+
offset,
520+
tzDecoder.encodedLength(), localDateTime.toString(), out);
521+
}
522+
475523
public void interpretOrderMsg(byte[] bytes, int size, PrintStream out) {
476524
DirectBuffer buffer = new UnsafeBuffer(bytes);
477525
interpretTableHeader(out);
@@ -598,6 +646,10 @@ private String decimalToString(long mantissa, int exponent) {
598646
}
599647
}
600648

649+
private void heading(String text, PrintStream out) {
650+
out.format("%s%s%s\n", headingBegin, text, headingEnd);
651+
}
652+
601653
private int interpretFramingHeader(byte[] bytes, PrintStream out, DirectBuffer buffer, int offset) {
602654
SofhFrameDecoder sofhDecoder = new SofhFrameDecoder();
603655
sofhDecoder.wrap(buffer, offset);
@@ -650,10 +702,6 @@ private int interpretMessageHeader(byte[] bytes, PrintStream out) {
650702
return mhDecoder.offset() + mhDecoder.encodedLength();
651703
}
652704

653-
private void heading(String text, PrintStream out) {
654-
out.format("%s%s%s\n", headingBegin, text, headingEnd);
655-
}
656-
657705
private void interpretRow(String wireFormat, int fieldId, String name, int offset, int length,
658706
String interpreted, PrintStream out) {
659707
out.format("%s %s%s%s %s %s %s %s %s %d %s %d %s %s %s\n", tableRowBegin, literalBegin,

v1-0-STANDARD/src/main/resources/Examples.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ xsi:schemaLocation="http://fixprotocol.io/2016/sbe sbe.xsd">
3737
<type name="mantissa" primitiveType="int32"/>
3838
<type name="exponent" presence="constant" primitiveType="int8">0</type>
3939
</composite>
40+
<composite name="tzTimestamp" semanticType="TZTimestamp">
41+
<type name="time" primitiveType="uint64" />
42+
<type name="unit" primitiveType="uint8" />
43+
<!-- Sign of timezone offset is on hour subfield -->
44+
<type name="timezoneHour" primitiveType="int8" minValue="-12" maxValue="14" />
45+
<type name="timezoneMinute" primitiveType="uint8" maxValue="59" />
46+
</composite>
4047
<enum name="businessRejectReasonEnum" encodingType="intEnumEncoding">
4148
<validValue name="Other">0</validValue>
4249
<validValue name="UnknownID">1</validValue>
@@ -108,4 +115,7 @@ xsi:schemaLocation="http://fixprotocol.io/2016/sbe sbe.xsd">
108115
<field name="Price" id="44" type="optionalDecimalEncoding" offset="38" semanticType="Price"/>
109116
<field name="StopPx" id="99" type="optionalDecimalEncoding" offset="46" semanticType="Price"/>
110117
</sbe:message>
118+
<sbe:message name="FieldEncodings" id="999">
119+
<field name="TzTimestamp" id="999" type="tzTimestamp"/>
120+
</sbe:message>
111121
</sbe:messageSchema>

v2-0-RC2/src/main/resources/Examples.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2017/sbe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" package="Examples" id="91" version="0" byteOrder="littleEndian" xsi:schemaLocation="http://fixprotocol.io/2017/sbe ../../../../../fix-simple-binary-encoding/v2-0-RC2/resources/xsd/sbe-2.0rc2.xsd">
2+
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2017/sbe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" package="Examples" id="91" version="0" byteOrder="littleEndian" xsi:schemaLocation="http://fixprotocol.io/2017/sbe sbe-2.0rc2.xsd">
33
<types>
44
<type name="date" primitiveType="uint16"/>
55
<type name="enumEncoding" primitiveType="char"/>

0 commit comments

Comments
 (0)