24
24
import java .time .LocalDate ;
25
25
import java .time .LocalDateTime ;
26
26
import java .time .ZoneOffset ;
27
+ import java .time .format .DateTimeFormatter ;
27
28
import java .util .Arrays ;
28
29
import java .util .concurrent .TimeUnit ;
29
30
52
53
import io .fixprotocol .sbe .examples .messages .QtyEncodingDecoder ;
53
54
import io .fixprotocol .sbe .examples .messages .QtyEncodingEncoder ;
54
55
import io .fixprotocol .sbe .examples .messages .SideEnum ;
56
+ import io .fixprotocol .sbe .examples .messages .TzTimestampDecoder ;
57
+ import io .fixprotocol .sbe .examples .messages .TzTimestampEncoder ;
55
58
import io .fixprotocol .sbe .util .BufferDumper ;
56
59
57
60
@@ -111,9 +114,6 @@ public class ExampleDumper {
111
114
*/
112
115
public static final String MARKDOWN_TABLE_ROW_END = "|" ;
113
116
114
- private final MessageHeaderDecoder mhDecoder = new MessageHeaderDecoder ();
115
-
116
-
117
117
/**
118
118
* Output all examples
119
119
*
@@ -132,6 +132,7 @@ public static void main(String[] args)
132
132
dumper .dumpAll (stream );
133
133
}
134
134
135
+
135
136
private static String wireFormat (byte [] bytes , int offset , int width ) {
136
137
StringWriter writer = new StringWriter ();
137
138
for (int index = 0 ; index < width ; index ++) {
@@ -143,11 +144,13 @@ private static String wireFormat(byte[] bytes, int offset, int width) {
143
144
}
144
145
145
146
private String blockBegin = MARKDOWN_BLOCK_BEGIN ;
147
+
146
148
private String blockEnd = MARKDOWN_BLOCK_END ;
147
149
private String headingBegin = MARKDOWN_HEADING_BEGIN ;
148
150
private String headingEnd = MARKDOWN_HEADING_END ;
149
151
private String literalBegin = MARKDOWN_LITERAL_BEGIN ;
150
152
private String literalEnd = MARKDOWN_LITERAL_END ;
153
+ private final MessageHeaderDecoder mhDecoder = new MessageHeaderDecoder ();
151
154
private String tableColumnDelim = MARKDOWN_TABLE_COLUMN_DELIM ;
152
155
private String tableRowBegin = MARKDOWN_TABLE_ROW_BEGIN ;
153
156
private String tableRowEnd = MARKDOWN_TABLE_ROW_END ;
@@ -177,6 +180,13 @@ public void dumpAll(PrintStream out) throws UnsupportedEncodingException {
177
180
dump (bytes , size , out );
178
181
heading ("Interpretation" , out );
179
182
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 );
180
190
}
181
191
182
192
public int encodeBusinessMessageReject (byte bytes []) throws UnsupportedEncodingException {
@@ -258,6 +268,24 @@ public int encodeExecutionReport(byte[] bytes) throws UnsupportedEncodingExcepti
258
268
return offset ;
259
269
}
260
270
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
+
261
289
public int encodeOrderMsg (byte bytes []) throws UnsupportedEncodingException {
262
290
SofhFrameEncoder sofhEncoder = new SofhFrameEncoder ();
263
291
MessageHeaderEncoder mhEncoder = new MessageHeaderEncoder ();
@@ -472,6 +500,26 @@ public void interpretExecutionReport(byte[] bytes, int size, PrintStream out) {
472
500
473
501
}
474
502
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
+
475
523
public void interpretOrderMsg (byte [] bytes , int size , PrintStream out ) {
476
524
DirectBuffer buffer = new UnsafeBuffer (bytes );
477
525
interpretTableHeader (out );
@@ -598,6 +646,10 @@ private String decimalToString(long mantissa, int exponent) {
598
646
}
599
647
}
600
648
649
+ private void heading (String text , PrintStream out ) {
650
+ out .format ("%s%s%s\n " , headingBegin , text , headingEnd );
651
+ }
652
+
601
653
private int interpretFramingHeader (byte [] bytes , PrintStream out , DirectBuffer buffer , int offset ) {
602
654
SofhFrameDecoder sofhDecoder = new SofhFrameDecoder ();
603
655
sofhDecoder .wrap (buffer , offset );
@@ -650,10 +702,6 @@ private int interpretMessageHeader(byte[] bytes, PrintStream out) {
650
702
return mhDecoder .offset () + mhDecoder .encodedLength ();
651
703
}
652
704
653
- private void heading (String text , PrintStream out ) {
654
- out .format ("%s%s%s\n " , headingBegin , text , headingEnd );
655
- }
656
-
657
705
private void interpretRow (String wireFormat , int fieldId , String name , int offset , int length ,
658
706
String interpreted , PrintStream out ) {
659
707
out .format ("%s %s%s%s %s %s %s %s %s %d %s %d %s %s %s\n " , tableRowBegin , literalBegin ,
0 commit comments