1little_endian_packets
2
3custom_field SixBytes : 48 "packet/parser/test/"
4custom_field Variable "packet/parser/test/"
5
6packet Parent {
7  _fixed_ = 0x12 : 8,
8  _size_(_payload_) : 8,
9  _payload_,
10  footer : 8,
11}
12
13packet Child : Parent {
14  field_name : 16,
15}
16
17enum FourBits : 4 {
18  ONE = 1,
19  TWO = 2,
20  THREE = 3,
21  FIVE = 5,
22  TEN = 10,
23  LAZY_ME = 15,
24}
25
26packet ParentTwo {
27  _reserved_ : 4,
28  four_bits : FourBits,
29  _payload_,
30}
31
32packet ChildTwoThree : ParentTwo (four_bits = THREE) {
33  more_bits : FourBits,
34  _reserved_ : 4,
35  sixteen_bits : 16
36}
37
38packet ChildTwoTwo : ParentTwo (four_bits = TWO) {
39  more_bits : FourBits,
40  _reserved_ : 4,
41}
42
43packet ChildTwoTwoThree :ChildTwoTwo (more_bits = THREE) {
44}
45
46enum TwoBits : 2 {
47  ZERO = 0,
48  ONE = 1,
49  TWO = 2,
50  THREE = 3,
51}
52
53packet MiddleFourBits {
54  low_two : TwoBits,
55  next_four : FourBits,
56  straddle : FourBits,
57  four_more : FourBits,
58  high_two : TwoBits,
59}
60
61packet ParentWithSixBytes {
62  two_bytes : 16,
63  six_bytes : SixBytes,
64  _payload_,
65}
66
67packet ChildWithSixBytes : ParentWithSixBytes (two_bytes = 0x1234) {
68  child_six_bytes : SixBytes,
69}
70
71checksum SimpleSum : 16 "packet/parser/test/"
72
73packet ParentWithSum {
74  two_bytes : 16,
75  _checksum_start_(example_checksum),
76  sum_bytes : 16,
77  _payload_,
78  example_checksum : SimpleSum,
79}
80
81packet ChildWithSum : ParentWithSum {
82  more_bytes : 32,
83  another_byte : 8,
84}
85
86packet ChildWithNestedSum : ParentWithSum {
87  _checksum_start_(nested_checksum),
88  more_bytes : 32,
89  nested_checksum : SimpleSum,
90}
91
92packet SizedWithSum {
93  two_bytes : 16,
94  _size_(_payload_) : 8,
95  _checksum_start_(example_checksum),
96  _payload_,
97  example_checksum : SimpleSum,
98}
99
100test SizedWithSum {
101  "\x01\x02\x03\x01\x02\x03\x06\x00",
102}
103
104packet ParentSizeModifier {
105  _size_(_payload_) : 8,
106  _payload_ : [+2], // Include two_bytes in the size
107  two_bytes : 16,
108}
109
110packet ChildSizeModifier : ParentSizeModifier (two_bytes = 0x1211) {
111  more_bytes : 32,
112}
113
114packet FieldsEndWithNumbers {
115  field_1 : 16,
116  field_2 : 16,
117  field_10 : 16,
118  field_11 : 16,
119}
120
121enum ForArrays : 16 {
122  ONE = 0x0001,
123  TWO = 0x0002,
124  ONE_TWO = 0x0201,
125  TWO_THREE = 0x0302,
126  FFFF = 0xffff,
127}
128
129packet FixedArrayEnum {
130  enum_array : ForArrays[5],
131}
132
133packet SizedArrayEnum {
134  _size_(enum_array) : 16,
135  enum_array : ForArrays[],
136}
137
138test SizedArrayEnum {
139  "\x00\x00",
140  "\x02\x00\x01\x02",
141  "\x04\x00\x01\x02\x11\x12",
142  "\x06\x00\x01\x02\x11\x12\x21\x22",
143}
144
145packet CountArrayEnum {
146  _count_(enum_array) : 8,
147  enum_array : ForArrays[],
148}
149
150test CountArrayEnum {
151  "\x01\x01\x02",
152  "\x02\x01\x02\x11\x12",
153  "\x03\x01\x02\x11\x12\x21\x22",
154}
155
156packet SizedArrayCustom {
157  _size_(six_bytes_array) : 8,
158  an_extra_byte : 8,
159  six_bytes_array : SixBytes[+1],
160}
161
162packet FixedArrayCustom {
163  six_bytes_array : SixBytes[5],
164}
165
166packet CountArrayCustom {
167  _count_(six_bytes_array) : 8,
168  six_bytes_array : SixBytes[],
169}
170
171packet PacketWithFixedArraysOfBytes {
172  fixed_256bit_in_bytes : 8[32],
173  fixed_256bit_in_words : 32[8],
174}
175
176packet OneVariable {
177  one : Variable,
178}
179
180packet SizedArrayVariable {
181  _size_(variable_array) : 8,
182  variable_array : Variable[],
183}
184
185packet FixedArrayVariable {
186  variable_array : Variable[5],
187}
188
189packet CountArrayVariable {
190  _count_(variable_array) : 8,
191  variable_array : Variable[],
192}
193
194struct TwoRelatedNumbers {
195  id : 8,
196  count : 16,
197}
198
199packet OneStruct {
200  one : TwoRelatedNumbers,
201}
202
203packet TwoStructs {
204  one : TwoRelatedNumbers,
205  two : TwoRelatedNumbers,
206}
207
208packet VectorOfStruct {
209  _count_(array) : 8,
210  array : TwoRelatedNumbers[],
211}
212
213test VectorOfStruct {
214  "\x00",
215  "\x01\x01\x02\x03",
216  "\x02\x01\x02\x03\x11\x12\x13",
217  "\x03\x01\x02\x03\x11\x12\x13\x21\x22\x23",
218}
219
220packet ArrayOfStruct {
221  the_count : 8,
222  array : TwoRelatedNumbers[4],
223}
224
225struct StructWithFixedTypes {
226  four_bits : FourBits,
227  _reserved_ : 4,
228  _checksum_start_(example_checksum),
229  _fixed_ = 0xf3 : 8,
230  id : 8,
231  array : 8[3],
232  example_checksum : SimpleSum,
233  six_bytes : SixBytes,
234}
235
236packet OneFixedTypesStruct {
237  one : StructWithFixedTypes,
238}
239
240packet ArrayOfStructAndAnother {
241  _count_(array) : 8,
242  array : TwoRelatedNumbers[],
243  another : TwoRelatedNumbers,
244}
245
246packet SizedArrayOfStructAndAnother {
247  _size_(array) : 8,
248  array : TwoRelatedNumbers[],
249  another : TwoRelatedNumbers,
250}
251
252struct ArrayOfStructAndAnotherStruct {
253  _count_(array) : 8,
254  array : TwoRelatedNumbers[],
255  another : TwoRelatedNumbers,
256}
257
258struct SizedArrayOfStructAndAnotherStruct {
259  _size_(array) : 8,
260  array : TwoRelatedNumbers[],
261  another : TwoRelatedNumbers,
262}
263
264packet OneArrayOfStructAndAnotherStruct {
265  one : ArrayOfStructAndAnotherStruct,
266}
267
268packet OneSizedArrayOfStructAndAnotherStruct {
269  one : SizedArrayOfStructAndAnotherStruct,
270}
271
272group BitFieldGroup {
273  seven_bits : 7,
274  straddle : 4,
275  five_bits : 5,
276}
277
278packet BitFieldGroupPacket {
279  BitFieldGroup,
280}
281
282packet BitFieldGroupAfterPayloadPacket {
283  _payload_,
284  BitFieldGroup,
285}
286
287packet BitFieldGroupAfterUnsizedArrayPacket : BitFieldGroupAfterPayloadPacket {
288  array : 8[],
289}
290
291struct BitField {
292  seven_bits : 7,
293  straddle : 4,
294  five_bits : 5,
295}
296
297packet BitFieldPacket {
298  bit_field : BitField,
299}
300
301packet BitFieldAfterPayloadPacket {
302  _payload_,
303  bit_field : BitField,
304}
305
306packet BitFieldAfterUnsizedArrayPacket : BitFieldAfterPayloadPacket {
307  array : 8[],
308}
309
310packet BitFieldArrayPacket {
311  _size_(array): 8,
312  array : BitField[],
313}
314
315struct VersionlessStruct {
316  one_number : 8,
317}
318
319packet OneVersionlessStructPacket {
320  versionless : VersionlessStruct,
321  _payload_,
322}
323
324packet OneVersionedStructPacket : OneVersionlessStructPacket {
325  version : 8,
326  _payload_,
327}
328
329packet OneVersionOneStructPacket : OneVersionedStructPacket(version = 0x01) {
330  just_one_number : 8,
331}
332
333packet OneVersionTwoStructPacket : OneVersionedStructPacket(version = 0x02) {
334  one_number : 8,
335  another_number : 8,
336}
337
338enum StructType : 8 {
339  ZERO_BYTE = 0x00,
340  TWO_BYTE = 0x02,
341  FOUR_BYTE = 0x04,
342  AT_LEAST_FOUR_BYTE = 0x05,
343  VARIABLE = 0x06,
344}
345
346struct UnusedParentStruct {
347  struct_type : StructType,
348  _body_,
349}
350
351struct TwoByteStruct : UnusedParentStruct (struct_type = TWO_BYTE) {
352  two_bytes : 16,
353}
354
355struct FourByteStruct : UnusedParentStruct (struct_type = FOUR_BYTE) {
356  four_bytes : 32,
357}
358
359struct AtLeastFourByteStruct : UnusedParentStruct (struct_type = AT_LEAST_FOUR_BYTE) {
360  four_bytes : 32,
361  struct_type : StructType,
362  _body_,
363}
364
365struct OnlyFourByteStruct : AtLeastFourByteStruct (struct_type = ZERO_BYTE) {
366}
367
368struct SixByteStruct : AtLeastFourByteStruct (struct_type = TWO_BYTE) {
369  two_more_bytes : 16,
370}
371
372struct EightByteStruct : AtLeastFourByteStruct (struct_type = FOUR_BYTE) {
373  four_more_bytes : 32,
374}
375
376packet OneFourByteStruct {
377  one_struct : FourByteStruct,
378}
379
380packet OneGenericStruct {
381  base_struct : UnusedParentStruct,
382}
383
384packet OneGenericStructArray {
385  an_array : UnusedParentStruct[],
386}
387
388packet OneGenericStructFourArray {
389  an_array : UnusedParentStruct[4],
390}
391
392packet ParentWithOnlyFixed {
393  two_bytes : 16,
394  _body_,
395}
396
397packet OneGenericStructArrayAfterFixed : ParentWithOnlyFixed {
398  an_array : UnusedParentStruct[],
399}
400
401enum DataType : 8 {
402  ONE = 0x01,
403  TWO = 0x02,
404  THREE = 0x03,
405  FOUR = 0x04,
406  FIVE = 0x05,
407  UNUSED = 0x06,
408}
409
410struct LengthTypeValueStruct {
411  _size_(value) : 16,
412  type : DataType,
413  value : 8[+1],
414}
415
416packet OneLengthTypeValueStruct {
417  one_array : LengthTypeValueStruct[],
418}
419
420packet SizedParent {
421  _size_(payload) : 8,
422  _payload_,
423}
424
425packet OneLengthTypeValueStructPadded : SizedParent {
426  valid_bytes : 8,
427  one_array : LengthTypeValueStruct[],
428  _padding_[30],
429  after_padding : 8,
430}
431
432packet ByteSizedFields {
433  one : 8,
434  two : 16,
435  three : 24,
436  four : 32,
437  five : 40,
438  six : 48,
439  seven : 56,
440  eight : 64,
441}
442
443enum StructTypeNoZero : 4 {
444  TWO_BYTE = 0x02,
445  FOUR_BYTE = 0x04,
446  AT_LEAST_FOUR_BYTE = 0x05,
447}
448
449struct UnusedParentStructNoZero {
450  struct_type : StructTypeNoZero,
451  _reserved_ : 4,
452  length : 8,
453  _body_,
454}
455
456struct TwoByteStructNoZero : UnusedParentStructNoZero (struct_type = TWO_BYTE, length = 2) {
457  two_bytes : 16,
458}
459
460struct FourByteStructNoZero : UnusedParentStructNoZero (struct_type = FOUR_BYTE, length = 4) {
461  four_bytes : 32,
462}
463
464struct AtLeastFourByteStructNoZero : UnusedParentStructNoZero (struct_type = AT_LEAST_FOUR_BYTE) {
465  four_bytes : 32,
466  struct_type : StructTypeNoZero,
467  _body_,
468}
469
470struct EightByteStructNoZero : AtLeastFourByteStructNoZero (struct_type = FOUR_BYTE, length = 9) {
471  four_more_bytes : 32,
472}
473
474packet OneGenericStructArrayNoZero {
475  an_array : UnusedParentStructNoZero[],
476}
477
478enum BigValue: 64 {
479    MIN = 0,
480    TOO_BIG_FOR_32 = 0x0706050403020100,
481    MAX = 0xffffffffffffffff,
482}
483
484packet OneBigValue {
485  big : BigValue,
486}
487
488test OneBigValue {
489  "\x00\x00\x00\x00\x00\x00\x00\x00",
490  "\xff\xff\xff\xff\xff\xff\xff\xff",
491  "\x00\x01\x02\x03\x04\x05\x06\x07",
492}
493
494packet ArrayOfBytes {
495  _fixed_ = 8 : 8,
496  bytes : 8[],
497}
498
499test ArrayOfBytes {
500  "\x08\x01\x02\x03",
501  "\x08\x05\x04\x03\x02\x01\x00",
502  "\x08\x06\x05\x04\x03\x02\x01\x00",
503}
504
505packet ArrayOfSixteens {
506  _fixed_ = 16 : 8,
507  sixteens : 16[],
508}
509
510test ArrayOfSixteens {
511  "\x10\x01\x11\x02\x12\x03\x13",
512  "\x10\x05\x15\x04\x14\x03\x13\x02\x12\x01\x11\x00\x10",
513  "\x10\x06\x16\x05\x15\x04\x14\x03\x13\x02\x12\x01\x11\x00\x10",
514}
515
516packet ArrayOfThirtyTwo {
517  _fixed_ = 32 : 8,
518  thirtytwos : 32[],
519}
520
521test ArrayOfThirtyTwo {
522  "\x20\x01\x11\x21\x31\x02\x12\x22\x32\x03\x13\x23\x33",
523  "\x20\x05\x15\x25\x35\x04\x14\x24\x34\x03\x13\x23\x33\x02\x12\x22\x32\x01\x11\x21\x31\x00\x10\x20\x30",
524  "\x20\x06\x16\x26\x36\x05\x15\x25\x35\x04\x14\x24\x34\x03\x13\x23\x33\x02\x12\x22\x32\x01\x11\x21\x31\x00\x10\x20\x30",
525}
526
527packet Arrays {
528  _size_(bytes) : 8,
529  bytes : 8[],
530  _size_(sixteens) : 8,
531  sixteens : 16[],
532  _size_(thirtytwos) : 8,
533  thirtytwos : 32[]
534}
535
536test Arrays {
537  "\x03\x01\x02\x03\x06\x01\x11\x02\x12\x03\x13\x0C\x01\x11\x21\x31\x02\x12\x22\x32\x03\x13\x23\x33",
538  "\x06\x05\x04\x03\x02\x01\x00\x0C\x05\x15\x04\x14\x03\x13\x02\x12\x01\x11\x00\x10\x18\x05\x15\x25\x35\x04\x14\x24\x34\x03\x13\x23\x33\x02\x12\x22\x32\x01\x11\x21\x31\x00\x10\x20\x30",
539}
540