c-its-parser 2.2.0

Tools for encoding and decoding ETSI messages (GN + Transport + CAM/DENM/IVIM/SSEM/SREM/MAPEM/SPATEM)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
#[cfg(all(not(target_arch = "wasm32"), feature = "_etsi", feature = "json"))]
use c_its_parser::ItsMessage;
#[cfg(all(target_arch = "wasm32", feature = "_etsi", feature = "json"))]
use c_its_parser::JsonItsMessage;
#[cfg(all(target_arch = "wasm32", feature = "_etsi", feature = "json"))]
use wasm_bindgen_test::wasm_bindgen_test;
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[cfg(all(not(target_arch = "wasm32"), feature = "_etsi", feature = "json"))]
use geonetworking::Encode;

#[cfg(any(
    all(not(target_arch = "wasm32"), feature = "denm_2_2_1"),
    all(target_arch = "wasm32", feature = "denm_2_2_1", feature = "json")
))]
const DENM: &[u8] = &[
    0x02, 0x01, 0xe0, 0xfd, 0x1d, 0x37, 0xe7, 0x46, 0x5a, 0xa8, 0xbc, 0x80, 0x06, 0x91, 0x0d, 0x64,
    0xc9, 0x04, 0x04, 0x43, 0x59, 0x32, 0x45, 0x9d, 0x59, 0x01, 0x92, 0x07, 0x13, 0x5f, 0x21, 0x42,
    0xbe, 0x2b, 0xe0, 0x00, 0x18, 0x6a, 0x09, 0x88, 0x00, 0x50, 0x14, 0x40, 0x18, 0x03, 0x00, 0x14,
    0xfb, 0x84, 0x3f, 0x0a, 0x2f, 0xdd, 0x6b, 0xfb, 0x00, 0xc5, 0x0a, 0x06, 0x02, 0x2d, 0x29, 0x7f,
    0xf5, 0x9f, 0xff, 0xe6, 0x06, 0x80, 0x5f, 0x9c, 0x00, 0xff, 0x00, 0x0d, 0x31, 0x24, 0x04, 0x9b,
    0xe0, 0x06, 0x48, 0x02, 0xad, 0x89, 0x20, 0x13, 0x87, 0x00, 0x1b, 0xc0, 0x39, 0x4c, 0x32, 0x81,
    0x12, 0xf8, 0x01, 0xa5, 0xfe, 0xd5, 0x61, 0x44, 0x09, 0x5f, 0xc0, 0x0d, 0x2f, 0xfc, 0x93, 0x11,
    0x00, 0x15, 0xde, 0x00, 0x57, 0x7f, 0x46, 0x58, 0x06, 0x02, 0xc8, 0x6f, 0xfd, 0x1b, 0xfc, 0xce,
    0xc7, 0xd8, 0x0b, 0xb7, 0x7f, 0xd5, 0x9f, 0xcd, 0xb7, 0x0e, 0x42, 0x89, 0xfb, 0xff, 0x7b, 0x00,
    0x8f, 0x33, 0xcc, 0x05, 0x77, 0xe0, 0x04, 0x18, 0x01, 0x0d, 0x86, 0xf0, 0x17, 0x6f, 0x00, 0x19,
    0xbf, 0xee, 0xec, 0xa8, 0x03, 0xa3, 0x37, 0xfc, 0x66, 0x04, 0x1e, 0x65, 0x68, 0x10, 0xfd, 0xc0,
    0x02, 0xf0, 0x02, 0x13, 0x17, 0x40, 0x6d, 0x5e, 0x00, 0x4a, 0x7f, 0xf1, 0xd8, 0xbf, 0x01, 0x51,
    0x70, 0x03, 0x7b, 0xf8, 0x62, 0xcd, 0xf0, 0x13, 0xd7, 0x80, 0x07, 0xa0, 0x02, 0x16, 0x4a, 0x00,
    0x1f, 0xdb, 0xff, 0xd2, 0xff, 0xf8, 0xb2, 0xaa, 0x02, 0x70, 0xdf, 0xfb, 0x98, 0x00, 0xb5, 0x8e,
    0x70, 0x0f, 0x9e, 0xff, 0xb3, 0x3f, 0xff, 0xec, 0x4b, 0x81, 0x3d, 0x77, 0xff, 0x2d, 0xff, 0xb3,
    0x62, 0xe8, 0x0a, 0xf9, 0xc0, 0x00, 0x90, 0x0c, 0x1b, 0x12, 0x40, 0x78, 0x4d, 0xff, 0x12, 0x80,
    0x81, 0x19, 0xf0, 0x03, 0x81, 0x6f, 0xf7, 0xf4, 0x01, 0xcc, 0xc8, 0x28, 0x42, 0x3f, 0x7f, 0xfa,
    0xdf, 0xff, 0xe6, 0x02, 0xc0, 0x53, 0x1c, 0x02, 0x78, 0xff, 0x0a, 0xb1, 0x10, 0x06, 0x71, 0xdf,
    0xfc, 0xe7, 0xff, 0x99, 0x9f, 0xa0, 0x1d, 0xae, 0xff, 0xf4, 0x40, 0x17, 0x2c, 0xc8, 0x80, 0xc7,
    0xf8, 0x00, 0x1a, 0x00, 0xee, 0x63, 0xd8, 0x0d, 0x0a, 0xbf, 0xfe, 0x0f, 0xfd, 0xca, 0xec, 0x20,
    0x93, 0xd5, 0xff, 0x4b, 0x7f, 0xff, 0xd8, 0x97, 0x0d, 0x1a, 0xb0, 0x05, 0x33, 0xfd, 0x64, 0xc9,
    0xb8, 0x0c, 0x1d, 0x80, 0x14, 0x5f, 0xe3, 0xb6, 0x46, 0x40, 0x54, 0x5c, 0x02, 0x3c, 0xff, 0x92,
    0x2f, 0xee, 0x08, 0x83, 0xe0, 0x08, 0x18, 0x01, 0x45, 0x8e, 0x20, 0x13, 0x87, 0x00, 0x52, 0xc0,
    0x6a, 0xcb, 0x72, 0x01, 0x5d, 0xf8, 0x00, 0xa1, 0xff, 0xf7, 0x63, 0x88, 0x06, 0x71, 0xc0, 0x1d,
    0x70, 0x15, 0xd3, 0x19, 0x20, 0x57, 0x7d, 0xff, 0xf5, 0x80, 0x60, 0xd7, 0xc0, 0x01, 0x06, 0x42,
    0x04, 0x80, 0x60, 0x0c,
];

#[cfg(any(
    all(not(target_arch = "wasm32"), feature = "cam_1_4_1"),
    all(target_arch = "wasm32", feature = "cam_1_4_1", feature = "json")
))]
const CAM: &[u8] = &[
    0x02, 0x02, 0xde, 0x14, 0x0c, 0xe5, 0xc7, 0xc0, 0x40, 0x5a, 0xb2, 0x3d, 0x82, 0xce, 0x27, 0x81,
    0xe9, 0xa2, 0x78, 0x27, 0x4b, 0xc6, 0x33, 0xfa, 0x54, 0x58, 0x7c, 0xa0, 0xa2, 0x7e, 0x83, 0x02,
    0x96, 0x8a, 0x97, 0x33, 0xff, 0x82, 0x00, 0x1a, 0x10, 0x3f, 0xe0, 0x14, 0x39, 0x80, 0x10, 0x6e,
    0x00, 0x75, 0x80, 0x11, 0x58, 0xce, 0x00, 0x02, 0xf0, 0x3a, 0xdc, 0x08, 0xc4, 0xc8, 0x00, 0x01,
    0x57, 0x81, 0xd6, 0x20, 0x46, 0x96, 0x33, 0x80, 0x0a, 0xbc, 0x0e, 0xdb, 0x02, 0x39, 0x31, 0x9c,
    0x00, 0x55, 0xe0, 0x75, 0x08, 0x11, 0x85, 0x90, 0x00, 0x02, 0xaf, 0x03, 0xa0, 0xc0, 0x91, 0x2c,
    0x80, 0x00, 0x16, 0x78, 0x1c, 0x9e, 0x05, 0x65, 0x64, 0x00, 0x00, 0xc3, 0xc0, 0xe0, 0x90, 0x2d,
    0xbb, 0x19, 0xc0, 0x06, 0xde, 0x05, 0x8d, 0x81, 0x02, 0x18, 0xce, 0x00, 0x35, 0xf0, 0x15, 0x5c,
    0x00, 0x06, 0xc6, 0x70, 0x00, 0xdf, 0x80, 0x8d, 0x5f, 0xde, 0x66, 0x27, 0x00, 0x07, 0x3c, 0x04,
    0x76, 0xfd, 0x67, 0x31, 0x9c, 0x00, 0x58, 0x60, 0x41, 0x37, 0xd3, 0x15, 0x89, 0xc0, 0x06, 0xdc,
];

#[cfg(any(
    all(not(target_arch = "wasm32"), feature = "mapem_2_2_1"),
    all(target_arch = "wasm32", feature = "mapem_2_2_1", feature = "json")
))]
const MAPEM: &[u8] = &[
    0x02, 0x05, 0x00, 0x00, 0x30, 0x16, 0x08, 0x00, 0x03, 0x09, 0x4d, 0x83, 0x42, 0xfc, 0x9a, 0x94,
    0xef, 0xb2, 0x6b, 0x71, 0x93, 0x56, 0x0c, 0x6e, 0x32, 0x5c, 0xca, 0x00, 0x06, 0x13, 0x8a, 0x08,
    0x55, 0x8f, 0x22, 0x36, 0x71, 0x3c, 0x83, 0x27, 0x02, 0x8a, 0x24, 0x48, 0x2a, 0x48, 0x04, 0x20,
    0x00, 0x00, 0x36, 0xd0, 0x2f, 0xc0, 0xde, 0x22, 0x00, 0xb0, 0x61, 0xc1, 0x0f, 0xc0, 0x5b, 0xe4,
    0xf4, 0xc3, 0xc7, 0xab, 0xc9, 0x87, 0x83, 0x47, 0xf0, 0x02, 0xc5, 0xa0, 0x00, 0x04, 0x04, 0x40,
    0x59, 0x08, 0x08, 0x40, 0x00, 0x00, 0x2c, 0xec, 0xa2, 0x26, 0x80, 0x46, 0x0c, 0x05, 0x54, 0x66,
    0x23, 0xdd, 0x7d, 0xc2, 0x40, 0x12, 0x42, 0x20, 0x00, 0x00, 0xdb, 0x40, 0xd5, 0x00, 0xe2, 0x80,
    0x02, 0x0e, 0xce, 0x06, 0x1e, 0x01, 0x1f, 0x10, 0x2d, 0xbb, 0x76, 0xe1, 0xe6, 0xbd, 0xf8, 0x20,
    0xb0, 0x68, 0x00, 0x01, 0x02, 0x10, 0x06, 0x42, 0x22, 0x00, 0x00, 0x04, 0x9d, 0xd5, 0xc0, 0xa6,
    0x11, 0xc6, 0xf4, 0x82, 0x4e, 0x5f, 0x89, 0x20, 0x11, 0x21, 0x00, 0x00, 0x00, 0x6d, 0xa0, 0x78,
    0x7f, 0x16, 0x40, 0x01, 0x0e, 0x40, 0x7e, 0x83, 0xd4, 0x7b, 0xd9, 0x85, 0xef, 0xef, 0x06, 0x2c,
    0xd0, 0x80, 0xc0, 0x58, 0x2c, 0x00, 0x00, 0x81, 0x88, 0x02, 0xa1, 0x10, 0x00, 0x00, 0x02, 0x4e,
    0xf4, 0x1e, 0xfb, 0x09, 0xf5, 0x7c, 0xa1, 0x03, 0x4f, 0x5c, 0x90, 0x24, 0xd0, 0x80, 0x00, 0x00,
    0x36, 0x7a, 0x06, 0xad, 0xaa, 0x00, 0x08, 0x8f, 0x8e, 0x07, 0x46, 0x46, 0xf7, 0xb1, 0x08, 0x69,
    0x9b, 0xc4, 0x87, 0x39, 0x3f, 0x52, 0x0b, 0x0b, 0x80, 0x00, 0x70, 0x41, 0x00, 0xb6, 0x22, 0x00,
    0x00, 0x00, 0x4b, 0x4c, 0xea, 0xe9, 0x78, 0x1c, 0xae, 0xec, 0x43, 0xe3, 0x5d, 0x29, 0x20, 0x51,
    0xa1, 0x10, 0x00, 0x00, 0x6c, 0xe0, 0x89, 0x45, 0xd4, 0x00, 0x10, 0x94, 0x47, 0xb6, 0x22, 0x46,
    0x7c, 0x81, 0x8d, 0x51, 0xcf, 0x83, 0x13, 0x7c, 0x02, 0xc1, 0x61, 0x90, 0x00, 0x0e, 0x0a, 0x20,
    0x18, 0xc4, 0x44, 0x00, 0x00, 0x09, 0x69, 0x94, 0x1c, 0xdd, 0x83, 0xeb, 0x1c, 0x40, 0x71, 0x33,
    0xcd, 0x24, 0x17, 0x34, 0x02, 0x10, 0x00, 0x00, 0x2b, 0x38, 0x29, 0x4d, 0xdd, 0x10, 0x05, 0x51,
    0x09, 0xc4, 0x7d, 0xa3, 0x34, 0x83, 0xd8, 0xc2, 0x03, 0x1a, 0xc0, 0x43, 0x0b, 0x88, 0x10, 0xe1,
    0xbe, 0x70, 0xcd, 0x85, 0x01, 0xe0, 0x58, 0xc4, 0x00, 0x03, 0x83, 0x08, 0x0c, 0x31, 0x01, 0x08,
    0x00, 0x00, 0x05, 0xb4, 0xc6, 0x2e, 0x50, 0xc0, 0x8a, 0x88, 0x78, 0x03, 0x90, 0x0e, 0xc1, 0x77,
    0x04, 0x80, 0xea, 0x84, 0x00, 0x00, 0x02, 0xb6, 0x81, 0x01, 0xe5, 0x9d, 0x00, 0x04, 0x0f, 0xed,
    0xe6, 0x09, 0xaf, 0x4a, 0x05, 0x2f, 0x8d, 0x02, 0xee, 0xab, 0xc1, 0xe8, 0xce, 0x23, 0xe2, 0x13,
    0xb7, 0x05, 0x61, 0x68, 0x00, 0x08, 0x0e, 0xb0, 0xc4, 0x00, 0x04, 0x08, 0x04, 0x0f, 0x60, 0x40,
    0x80, 0x00, 0x00, 0x33, 0xf1, 0xf8, 0x96, 0x10, 0x00, 0x41, 0x02, 0xcc, 0x80, 0xa1, 0x00, 0x20,
    0x90, 0x41, 0x06, 0x04, 0x08, 0x00, 0x00, 0x03, 0x3e, 0xec, 0x78, 0xdd, 0x00, 0x04, 0x0f, 0xdb,
    0x38, 0x0a, 0x0f, 0x03, 0x0a, 0x04, 0x11, 0x60, 0x40, 0x80, 0x00, 0x00, 0x33, 0xe6, 0xf5, 0x9f,
    0xd0, 0x00, 0x41, 0x02, 0xcc, 0x80, 0xa1, 0x20, 0x80, 0xb0, 0x41, 0x26, 0x04, 0x08, 0x00, 0x00,
    0x03, 0x3e, 0x3d, 0x49, 0x99, 0x00, 0x04, 0x0f, 0xdb, 0x38, 0x0a, 0x11, 0x09, 0x0c, 0x04, 0x13,
    0x60, 0x40, 0x80, 0x00, 0x00, 0x33, 0xee, 0x85, 0xfb, 0x10, 0x00, 0x40, 0xce, 0x3f, 0x40, 0xa1,
    0x40, 0x50, 0xd0, 0x41, 0x46, 0x04, 0x08, 0x00, 0x00, 0x03, 0x68, 0x84, 0xde, 0x07, 0x50, 0x00,
    0x41, 0x32, 0x40, 0xc0, 0xa1, 0x30, 0x60, 0xe0,
];

#[cfg(any(
    all(not(target_arch = "wasm32"), feature = "spatem_2_2_1"),
    all(target_arch = "wasm32", feature = "spatem_2_2_1", feature = "json")
))]
const SPATEM: &[u8] = &[
    0x02, 0x04, 0x00, 0x00, 0x30, 0x16, 0x00, 0x38, 0x4a, 0x6c, 0x1a, 0x17, 0xe4, 0xd4, 0xa7, 0x7d,
    0x93, 0x5b, 0x8c, 0x9a, 0xb0, 0x63, 0x71, 0x92, 0xe6, 0x50, 0x00, 0x30, 0x9c, 0x50, 0x40, 0x00,
    0x0e, 0xa7, 0x1d, 0x4f, 0xf0, 0x10, 0x00, 0x22, 0x8c, 0xe2, 0xf9, 0x44, 0xff, 0x63, 0x5b, 0x63,
    0x48, 0x71, 0xad, 0xb1, 0xae, 0xa1, 0xae, 0xa7, 0x80, 0x10, 0xa1, 0xb8, 0xbe, 0x29, 0x40, 0xa0,
    0xd6, 0xd8, 0xd1, 0x5c, 0x6b, 0x6c, 0x6c, 0x0c, 0x6c, 0x0d, 0xe0, 0x06, 0x28, 0x0e, 0x2d, 0xfa,
    0x68, 0xf6, 0x35, 0xb6, 0x34, 0x57, 0x1a, 0xdb, 0x1b, 0x03, 0x1b, 0x03, 0x78, 0x02, 0x0a, 0x1b,
    0x8d, 0x8b, 0x8d, 0xc0, 0x0d, 0xa7, 0x0d, 0x11, 0xc6, 0xd3, 0x86, 0xd4, 0xc6, 0xd4, 0xde, 0x00,
    0xa2, 0x8a, 0xe3, 0x5f, 0x23, 0x6c, 0x43, 0x66, 0x03, 0x43, 0x71, 0xb3, 0x01, 0xbb, 0x71, 0xba,
    0xd1, 0x80, 0x30, 0xa0, 0x38, 0xaf, 0x79, 0x86, 0x50, 0xd6, 0xd8, 0xd1, 0x5c, 0x6b, 0x6c, 0x6c,
    0x0c, 0x6c, 0x0c, 0x60, 0x0e, 0x28, 0xce, 0x35, 0xfc, 0x36, 0xce, 0x36, 0x6a, 0x34, 0x87, 0x1b,
    0x35, 0x1b, 0x44, 0x1b, 0x44, 0x78, 0x04, 0x0a, 0x1b, 0x8d, 0x8b, 0x8d, 0xc0, 0x0d, 0xa7, 0x0d,
    0x15, 0xc6, 0xd3, 0x86, 0xe3, 0xc6, 0xe1, 0x46, 0x01, 0x22, 0x80, 0xe2, 0xdf, 0xa5, 0xcd, 0x03,
    0x5b, 0x63, 0x45, 0x71, 0xad, 0xb1, 0xb1, 0xc1, 0xb0, 0xd1, 0x80,
];

#[cfg(any(
    all(not(target_arch = "wasm32"), feature = "ivim_2_2_1"),
    all(target_arch = "wasm32", feature = "ivim_2_2_1", feature = "json")
))]
const IVIM: &[u8] = &[
    0x02, 0x06, 0x00, 0x12, 0x10, 0xdc, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00, 0x88, 0x05, 0x58, 0xea,
    0xad, 0x57, 0x13, 0xd7, 0xa6, 0x4f, 0xff, 0xff, 0xfe, 0x11, 0xdb, 0xba, 0x1f, 0x08, 0xc0, 0xe1,
    0x11, 0x01, 0x40, 0x75, 0x0f, 0xe3, 0x54, 0x07, 0x48, 0xff, 0x1a, 0xc0, 0xab, 0xcf, 0xf5, 0xe2,
    0xbc, 0x30, 0x78, 0x44, 0x40, 0x2f, 0xff, 0x24, 0x11, 0x2f, 0x01, 0x29, 0x45, 0x70, 0xea, 0xf0,
    0x81, 0x60, 0x00, 0x02, 0x00, 0x04, 0x08, 0x01, 0x4e,
];

#[cfg(any(
    all(not(target_arch = "wasm32"), feature = "cpm_1"),
    all(target_arch = "wasm32", feature = "cpm_1", feature = "json")
))]
const CPM: &[u8] = &[
    0x01, 0x0e, 0xa6, 0xc0, 0x52, 0x47, 0x7a, 0x3f, 0x70, 0x0b, 0x56, 0x40, 0x27, 0x01, 0xc4, 0xd7,
    0x81, 0x62, 0xb9, 0xeb, 0x9c, 0x00, 0x06, 0xce, 0xd2, 0x83, 0xa6, 0x3e, 0xd7, 0xd0, 0x0b, 0xfe,
    0xca, 0x4c, 0xca, 0x0c, 0xcf, 0xff, 0xd0, 0x14, 0xc4, 0x40, 0x07, 0xb2, 0x10, 0x03, 0xe8, 0x19,
    0x01, 0x90, 0x32, 0x00, 0x8a, 0x03, 0xbb, 0x83, 0xe9, 0x2f, 0x94, 0xfd, 0x90, 0x65, 0x7f, 0xff,
    0xf5, 0xff, 0xff, 0xd4, 0x48, 0xfc, 0xe0, 0x0e, 0xe5, 0x00, 0x45, 0x03, 0xdd, 0xc1, 0xf5, 0x34,
    0xca, 0x7f, 0x6c, 0xb2, 0xbf, 0xff, 0xfa, 0xff, 0xff, 0xe9, 0xc1, 0xfe, 0x70, 0x07, 0x72, 0x80,
    0x22, 0x82, 0x6e, 0xe0, 0xfb, 0x55, 0x65, 0x3f, 0xb4, 0x99, 0x5f, 0xff, 0xfd, 0x7f, 0xff, 0xf6,
    0x07, 0x44, 0x10, 0x03, 0xb9, 0x40, 0x11, 0x41, 0x57, 0x70, 0x7d, 0x59, 0x32, 0x9f, 0xe7, 0xfc,
    0xaf, 0xff, 0xfe, 0xbf, 0xff, 0xfb, 0x42, 0x46, 0x88, 0x01, 0xdc, 0xa0, 0x08, 0xa1, 0x2b, 0xb8,
    0x3e, 0x25, 0x79, 0x4f, 0xe0, 0x3e, 0x57, 0xff, 0xff, 0x5f, 0xff, 0xfd, 0x2d, 0x4f, 0xce, 0x00,
    0xee, 0x50, 0x04, 0x50, 0xe5, 0xdc, 0x1f, 0x04, 0x3c, 0xa8, 0x08, 0xaf, 0x2b, 0xff, 0xff, 0xaf,
    0xff, 0xfe, 0xd4, 0x61, 0xe2, 0x00, 0x77, 0x28, 0x02, 0x08, 0x8e, 0xee, 0x0f, 0x9d, 0x56, 0x53,
    0xf3, 0x8b, 0x95, 0xff, 0xff, 0xd7, 0xff, 0xff, 0x5c, 0x23, 0xf0, 0x01, 0xb9, 0x40, 0x11, 0x5a,
    0x37, 0x70, 0x7b, 0xf5, 0xf2, 0xa0, 0x11, 0x5c, 0xaf, 0xff, 0xfe, 0xbf, 0xff, 0xfa, 0x35, 0xdf,
    0x9c, 0x01, 0xdc, 0xa0, 0x08, 0xa3, 0x5b, 0xb8, 0x3e, 0xbc, 0x19, 0x50, 0x08, 0x86, 0x57, 0xff,
    0xff, 0x5f, 0xff, 0xfd, 0x51, 0xdf, 0xce, 0x00, 0xee, 0x50, 0x04, 0x56, 0x45, 0xdc, 0x1e, 0xf1,
    0xbc, 0xa7, 0xe8, 0xa7, 0x2b, 0xff, 0xff, 0xaf, 0xff, 0xfe, 0xd4, 0x61, 0xe2, 0x00, 0x77, 0x28,
    0x02, 0x2a, 0xfa, 0xee, 0x0f, 0x82, 0x2e, 0x53, 0xfe, 0xb3, 0x95, 0xff, 0xff, 0xd7, 0xff, 0xff,
    0x4c, 0x9b, 0xf3, 0x80, 0x3b, 0x94, 0x01, 0x14, 0x33, 0x77, 0x07, 0xbb, 0xf3, 0x29, 0xf7, 0xa5,
    0xca, 0xff, 0xff, 0xeb, 0xff, 0xff, 0xac, 0x1f, 0xf9, 0xc0, 0x0d, 0xca, 0x00, 0x8a, 0x42, 0xbb,
    0x83, 0xdd, 0x55, 0x94, 0xfc, 0x49, 0xe5, 0x7f, 0xff, 0xf5, 0xff, 0xff, 0xd4, 0xe9, 0xfc, 0xe0,
    0x0e, 0xe5, 0x00, 0x45, 0x02, 0xdd, 0xc1, 0xf4, 0xf7, 0xca, 0x7e, 0xf6, 0xf2, 0xbf, 0xff, 0xfa,
    0xff, 0xff, 0xea, 0x1e, 0xfe, 0x70, 0x03, 0x72, 0x80, 0x22, 0x8f, 0xee, 0xe0, 0xf8, 0x6e, 0x65,
    0x3f, 0x98, 0x79, 0x5f, 0xff, 0xfd, 0x7f, 0xff, 0xf6, 0x25, 0x86, 0x10, 0x03, 0xb9, 0x40, 0x11,
    0x44, 0xd7, 0x70, 0x7c, 0x37, 0xb2, 0x9f, 0xef, 0x1c, 0xaf, 0xff, 0xfe, 0xbf, 0xff, 0xfb, 0x45,
    0x86, 0xc8, 0x01, 0xdc, 0xa0, 0x08, 0xa2, 0xfb, 0xb8, 0x3e, 0x08, 0xb9, 0x50, 0x04, 0x26, 0x57,
    0xff, 0xff, 0x5f, 0xff, 0xfd, 0x2a, 0xbf, 0xce, 0x00, 0xee, 0x50, 0x04, 0x52, 0x0d, 0xdc, 0x1e,
    0xfc, 0xec, 0xa7, 0xeb, 0x67, 0x2b, 0xf3, 0xdf, 0xaf, 0xc2, 0xfe, 0xd0, 0x61, 0x92, 0x00, 0x37,
    0x28, 0x02, 0x09, 0x3a, 0xee, 0x0f, 0x99, 0x3e, 0x53, 0xf2, 0xd9, 0x95, 0xff, 0xff, 0xd7, 0xff,
    0xff, 0x5c, 0x23, 0xf0, 0x01, 0xb9, 0x40, 0x10, 0x49, 0xf7, 0x70, 0x7b, 0xcf, 0x32, 0x9f, 0x72,
    0x2c, 0xaf, 0xfa, 0xfe, 0xbf, 0x31, 0xfb, 0x68, 0x29, 0x00, 0x0d, 0xca, 0x00, 0x8a, 0x4c, 0xbb,
    0x83, 0xe0, 0xff, 0x94, 0xfc, 0x5a, 0xe5, 0x7f, 0xff, 0xf5, 0xff, 0xff, 0xd3, 0x27, 0xfc, 0xe0,
    0x0e, 0xe5, 0x00, 0x41, 0x29, 0xdd, 0xc1, 0xef, 0x21, 0xca, 0x7f, 0xab, 0x72, 0xbf, 0xff, 0xfa,
    0xff, 0xff, 0xeb, 0x84, 0x7e, 0x00, 0x37, 0x28, 0x02, 0x08, 0xee, 0xee, 0x0f, 0xa1, 0x7e, 0x53,
    0xf4, 0xb3, 0x96, 0x04, 0x77, 0xd8, 0x05, 0xff, 0x43, 0xc7, 0xf0, 0x01, 0xb9, 0x40, 0x10, 0x4a,
    0x57, 0x70, 0x7d, 0x51, 0x72, 0xa0, 0x16, 0x7c, 0xaf, 0xff, 0xbe, 0xc0, 0x3c, 0xfa, 0x73, 0x9f,
    0x80, 0x0d, 0xca, 0x00, 0x82, 0x55, 0xbb, 0x83, 0xde, 0x51, 0x94, 0xff, 0x94, 0x65, 0x7f, 0xff,
    0xf5, 0xff, 0xff, 0xd6, 0x01, 0xfc, 0x00, 0x6e, 0x50, 0x04, 0x51, 0x8d, 0xdc, 0x1f, 0x16, 0xbc,
    0xa7, 0xf0, 0xaf, 0x2c, 0x1a, 0x2f, 0xaf, 0x61, 0x3e, 0xe5, 0x0b, 0x12, 0x00, 0x37, 0x28, 0xd0,
];

#[cfg(all(not(target_arch = "wasm32"), feature = "srem_2_2_1", feature = "json"))]
const SREM_PRE_OCIT: &[u8] = &[
    0x02, 0x09, 0xa6, 0x44, 0xd1, 0xdf, 0x70, 0x39, 0xec, 0xc8, 0x44, 0x00, 0x03, 0x00, 0x01, 0xec,
    0x04, 0x80, 0x10, 0x73, 0xda, 0x84, 0xd0, 0x60, 0x69, 0x91, 0x34, 0x77, 0xc0, 0x01, 0x2a, 0xb3,
    0x05, 0xf8, 0xee, 0x28, 0x8f, 0x08, 0x42, 0x00, 0x14, 0x8c, 0x00,
];

#[cfg(all(target_arch = "wasm32", feature = "denm_2_2_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_wasm() {
    let expected_gn = r#"{"Unsecured":{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":408,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}},"payload":[7,209,0,0,2,1,224,253,29,55,231,70,90,168,188,128,6,145,13,100,201,4,4,67,89,50,69,157,89,1,146,7,19,95,33,66,190,43,224,0,24,106,9,136,0,80,20,64,24,3,0,20,251,132,63,10,47,221,107,251,0,197,10,6,2,45,41,127,245,159,255,230,6,128,95,156,0,255,0,13,49,36,4,155,224,6,72,2,173,137,32,19,135,0,27,192,57,76,50,129,18,248,1,165,254,213,97,68,9,95,192,13,47,252,147,17,0,21,222,0,87,127,70,88,6,2,200,111,253,27,252,206,199,216,11,183,127,213,159,205,183,14,66,137,251,255,123,0,143,51,204,5,119,224,4,24,1,13,134,240,23,111,0,25,191,238,236,168,3,163,55,252,102,4,30,101,104,16,253,192,2,240,2,19,23,64,109,94,0,74,127,241,216,191,1,81,112,3,123,248,98,205,240,19,215,128,7,160,2,22,74,0,31,219,255,210,255,248,178,170,2,112,223,251,152,0,181,142,112,15,158,255,179,63,255,236,75,129,61,119,255,45,255,179,98,232,10,249,192,0,144,12,27,18,64,120,77,255,18,128,129,25,240,3,129,111,247,244,1,204,200,40,66,63,127,250,223,255,230,2,192,83,28,2,120,255,10,177,16,6,113,223,252,231,255,153,159,160,29,174,255,244,64,23,44,200,128,199,248,0,26,0,238,99,216,13,10,191,254,15,253,202,236,32,147,213,255,75,127,255,216,151,13,26,176,5,51,253,100,201,184,12,29,128,20,95,227,182,70,64,84,92,2,60,255,146,47,238,8,131,224,8,24,1,69,142,32,19,135,0,82,192,106,203,114,1,93,248,0,161,255,247,99,136,6,113,192,29,112,21,211,25,32,87,125,255,245,128,96,215,192,1,6,66,4,128,96,12]}}"#;
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":408,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::denm_2_2_1::denm_pdu_description::DENM>(DENM)
            .unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_denm(&json, 221).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(expected_gn).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.geonetworking.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "denm_2_2_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_denm_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":408,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::denm_2_2_1::denm_pdu_description::DENM>(DENM)
            .unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_denm(&json, 221).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "cam_1_4_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_cam_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":164,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::cam_1_4_1::cam_pdu_descriptions::CAM>(CAM)
            .unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_cam(&json, 141).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "mapem_2_2_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_mapem_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":540,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::mapem_2_2_1::mapem_pdu_descriptions::MAPEM>(MAPEM)
            .unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_mapem(&json, 221).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "spatem_2_2_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_spatem_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":207,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::spatem_2_2_1::spatem_pdu_descriptions::SPATEM>(SPATEM)
            .unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_spatem(&json, 221).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "ivim_2_2_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_ivim_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":77,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::ivim_2_2_1::ivim_pdu_descriptions::IVIM>(IVIM)
            .unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_ivim(&json, 221).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "v2x", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_srem_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":43,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some("{\"header\":{\"protocolVersion\":2,\"messageId\":9,\"stationId\":760129084},\"srm\":{\"timeStamp\":98917,\"second\":23692,\"sequenceNumber\":87,\"requests\":[{\"request\":{\"id\":{\"id\":0},\"requestID\":0,\"requestType\":\"priorityRequestUpdate\",\"inBoundLane\":{\"approach\":0},\"outBoundLane\":{\"approach\":0}}}],\"requestor\":{\"id\":{\"stationID\":3919},\"type\":{\"role\":\"publicTransport\"},\"position\":{\"position\":{\"lat\":535485106,\"long\":99886480},\"speed\":{\"transmisson\":\"unavailable\",\"speed\":232}},\"transitStatus\":\"00\",\"transitOccupancy\":\"occupancyMed\",\"transitSchedule\":4}}}".into()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_srem(&json, 221).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "cpm_1", feature = "json"))]
#[wasm_bindgen_test]
fn round_trip_cpm_wasm() {
    let json = JsonItsMessage {
        geonetworking: Some(r#"{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":80,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[false,false,false,false,false,false,false,false],"payload_length":628,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"Unknown","reserved":[false,true,false,false,false,false,false,true,true,false],"address":[0,96,224,105,87,141]},"timestamp":542947520,"latitude":535574568,"longitude":99765648,"position_accuracy":false,"speed":680,"heading":2122},"media_dependent_data":[127,0,184,0]}}}"#.into()),
        transport: Some(r#"{"destination_port":2001,"destination_port_info":0}"#.into()),
        its: Some(rasn::jer::encode(
            &rasn::uper::decode::<c_its_parser::standards::cpm_1::cpm_pdu_descriptions::CPM>(CPM).unwrap()
        ).unwrap()),
        ..Default::default()
    };
    let encoded = c_its_parser::en::encode_cpm(&json, 131).unwrap();
    let decoded = c_its_parser::de::decode_to(
        &encoded.to_vec(),
        c_its_parser::Headers::GnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    // Ignore GeoNetworking header, because it will get wrapped in an Unsecured header, and have the payload from the rest of the message (like in [`round_trip_wasm`])
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&json.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "v2x", feature = "json"))]
#[wasm_bindgen_test]
fn decode_pcap_frame_wasm() {
    let exp_geonetworking = r#"{"Unsecured":{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":5,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[true,false,false,false,false,false,false,false],"payload_length":67,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"PassengerCar","reserved":[false,false,false,false,false,false,false,false,false,false],"address":[138,176,248,168,162,37]},"timestamp":1151018751,"latitude":535505166,"longitude":99353789,"position_accuracy":true,"speed":14,"heading":724},"media_dependent_data":[0,0,0,0]}},"payload":[7,209,0,0,2,2,156,107,199,147,38,255,64,90,178,2,65,206,38,186,215,161,134,24,96,0,54,204,208,72,45,79,160,5,168,130,152,138,127,51,255,1,255,250,0,40,51,0,0,44,2,121,2,217,173,240,3,121,96,26,104,51,205,99,240,67,44]}}"#;
    let exp_tp = r#"{"destination_port":2001,"destination_port_info":0}"#;
    let exp_etsi = r#"{"header":{"protocolVersion":2,"messageID":2,"stationID":2624309139},"cam":{"generationDeltaTime":9983,"camParameters":{"basicContainer":{"stationType":5,"referencePosition":{"latitude":535505166,"longitude":99353789,"positionConfidenceEllipse":{"semiMajorConfidence":195,"semiMinorConfidence":195,"semiMajorOrientation":0},"altitude":{"altitudeValue":12230,"altitudeConfidence":"alt-005-00"}}},"highFrequencyContainer":{"basicVehicleContainerHighFrequency":{"heading":{"headingValue":724,"headingConfidence":126},"speed":{"speedValue":11,"speedConfidence":41},"driveDirection":"unavailable","vehicleLength":{"vehicleLengthValue":42,"vehicleLengthConfidenceIndication":"unavailable"},"vehicleWidth":18,"longitudinalAcceleration":{"longitudinalAccelerationValue":-1,"longitudinalAccelerationConfidence":102},"curvature":{"curvatureValue":0,"curvatureConfidence":"onePerMeter-0-00002"},"curvatureCalculationMode":"yawRateUsed","yawRate":{"yawRateValue":0,"yawRateConfidence":"unavailable"},"accelerationControl":"00","lateralAcceleration":{"lateralAccelerationValue":0,"lateralAccelerationConfidence":102}}},"lowFrequencyContainer":{"basicVehicleContainerLowFrequency":{"vehicleRole":"default","exteriorLights":"00","pathHistory":[{"pathPosition":{"deltaLatitude":317,"deltaLongitude":1460,"deltaAltitude":-940},"pathDeltaTime":1779},{"pathPosition":{"deltaLatitude":423,"deltaLongitude":3316,"deltaAltitude":-1310},"pathDeltaTime":4300}]}}}}}"#;
    let hex = "0000480002000040000004e5480038000200c900f40200000000000000000a014cff42ff34ff34ff7f390000f7c52687ebeb050091000c177c3d3c95fa000000000000000000000088000000ffffffffffff8ab0f8a8a225ffffffffffff00882300aaaa03000000894711000501205002800043010014008ab0f8a8a225449b26ff1feb290e05ec04bd800e02d40000000007d1000002029c6bc79326ff405ab20241ce26bad7a18618600036ccd0482d4fa005a882988a7f33ff01fffa00283300002c027902d9adf00379601a6833cd63f0432ce5dc898b";
    let raw = (0..hex.len())
        .step_by(2)
        .map(|s| u8::from_str_radix(&hex[s..s + 2], 16))
        .collect::<Result<Vec<u8>, _>>()
        .unwrap();
    let decoded = c_its_parser::de::decode_to(
        &raw,
        c_its_parser::Headers::RadioTap802LlcGnBtp,
        c_its_parser::EncodingRules::JER,
    )
    .unwrap();
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&decoded.geonetworking.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(exp_geonetworking).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&decoded.its.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(exp_etsi).unwrap()
    );
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(exp_tp).unwrap()
    );
}

#[cfg(all(target_arch = "wasm32", feature = "v2x", feature = "json"))]
#[wasm_bindgen_test]
fn strip_headers_frame_wasm() {
    let expected = JsonItsMessage {
        geonetworking: Some(
            r#"{"Unsecured":{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":5,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[true,false,false,false,false,false,false,false],"payload_length":67,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"PassengerCar","reserved":[false,false,false,false,false,false,false,false,false,false],"address":[138,176,248,168,162,37]},"timestamp":1151018751,"latitude":535505166,"longitude":99353789,"position_accuracy":true,"speed":14,"heading":724},"media_dependent_data":[0,0,0,0]}},"payload":[7,209,0,0,2,2,156,107,199,147,38,255,64,90,178,2,65,206,38,186,215,161,134,24,96,0,54,204,208,72,45,79,160,5,168,130,152,138,127,51,255,1,255,250,0,40,51,0,0,44,2,121,2,217,173,240,3,121,96,26,104,51,205,99,240,67,44]}}"#.into(),
        ),
        transport: Some(
            r#"{"destination_port":2001,"destination_port_info":0}"#.into(),
        ),
        its: Some(
            r#"02029C6BC79326FF405AB20241CE26BAD7A18618600036CCD0482D4FA005A882988A7F33FF01FFFA00283300002C027902D9ADF00379601A6833CD63F0432C"#.into(),
        ),
        message_type: 2,
    };
    let hex = "0000480002000040000004e5480038000200c900f40200000000000000000a014cff42ff34ff34ff7f390000f7c52687ebeb050091000c177c3d3c95fa000000000000000000000088000000ffffffffffff8ab0f8a8a225ffffffffffff00882300aaaa03000000894711000501205002800043010014008ab0f8a8a225449b26ff1feb290e05ec04bd800e02d40000000007d1000002029c6bc79326ff405ab20241ce26bad7a18618600036ccd0482d4fa005a882988a7f33ff01fffa00283300002c027902d9adf00379601a6833cd63f0432ce5dc898b";
    let raw = (0..hex.len())
        .step_by(2)
        .map(|s| u8::from_str_radix(&hex[s..s + 2], 16))
        .collect::<Result<Vec<u8>, _>>()
        .unwrap();
    let decoded = c_its_parser::de::decode_to(
        &raw,
        c_its_parser::Headers::RadioTap802LlcGnBtp,
        c_its_parser::EncodingRules::UPER,
    )
    .unwrap();
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&expected.geonetworking.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.geonetworking.unwrap()).unwrap()
    );
    pretty_assertions::assert_eq!(expected.its, decoded.its);
    pretty_assertions::assert_eq!(
        serde_json::from_str::<serde_json::Value>(&expected.transport.unwrap()).unwrap(),
        serde_json::from_str::<serde_json::Value>(&decoded.transport.unwrap()).unwrap()
    );
}

#[cfg(all(not(target_arch = "wasm32"), feature = "v2x", feature = "json"))]
#[test]
fn decode_pcap_frame() {
    let exp_geonetworking = r#"{"Unsecured":{"basic":{"version":1,"next_header":"CommonHeader","reserved":[false,false,false,false,false,false,false,false],"lifetime":5,"remaining_hop_limit":1},"common":{"next_header":"BTPB","reserved_1":[false,false,false,false],"header_type_and_subtype":{"TopologicallyScopedBroadcast":"SingleHop"},"traffic_class":{"store_carry_forward":false,"channel_offload":false,"traffic_class_id":2},"flags":[true,false,false,false,false,false,false,false],"payload_length":67,"maximum_hop_limit":1,"reserved_2":[false,false,false,false,false,false,false,false]},"extended":{"SHB":{"source_position_vector":{"gn_address":{"manually_configured":false,"station_type":"PassengerCar","reserved":[false,false,false,false,false,false,false,false,false,false],"address":[138,176,248,168,162,37]},"timestamp":1151018751,"latitude":535505166,"longitude":99353789,"position_accuracy":true,"speed":14,"heading":724},"media_dependent_data":[0,0,0,0]}},"payload":[7,209,0,0,2,2,156,107,199,147,38,255,64,90,178,2,65,206,38,186,215,161,134,24,96,0,54,204,208,72,45,79,160,5,168,130,152,138,127,51,255,1,255,250,0,40,51,0,0,44,2,121,2,217,173,240,3,121,96,26,104,51,205,99,240,67,44]}}"#;
    let exp_tp = r#"{"destination_port":2001,"destination_port_info":0}"#;
    let exp_etsi = r#"{"header":{"protocolVersion":2,"messageID":2,"stationID":2624309139},"cam":{"generationDeltaTime":9983,"camParameters":{"basicContainer":{"stationType":5,"referencePosition":{"latitude":535505166,"longitude":99353789,"positionConfidenceEllipse":{"semiMajorConfidence":195,"semiMinorConfidence":195,"semiMajorOrientation":0},"altitude":{"altitudeValue":12230,"altitudeConfidence":"alt-005-00"}}},"highFrequencyContainer":{"basicVehicleContainerHighFrequency":{"heading":{"headingValue":724,"headingConfidence":126},"speed":{"speedValue":11,"speedConfidence":41},"driveDirection":"unavailable","vehicleLength":{"vehicleLengthValue":42,"vehicleLengthConfidenceIndication":"unavailable"},"vehicleWidth":18,"longitudinalAcceleration":{"longitudinalAccelerationValue":-1,"longitudinalAccelerationConfidence":102},"curvature":{"curvatureValue":0,"curvatureConfidence":"onePerMeter-0-00002"},"curvatureCalculationMode":"yawRateUsed","yawRate":{"yawRateValue":0,"yawRateConfidence":"unavailable"},"accelerationControl":"00","lateralAcceleration":{"lateralAccelerationValue":0,"lateralAccelerationConfidence":102}}},"lowFrequencyContainer":{"basicVehicleContainerLowFrequency":{"vehicleRole":"default","exteriorLights":"00","pathHistory":[{"pathPosition":{"deltaLatitude":317,"deltaLongitude":1460,"deltaAltitude":-940},"pathDeltaTime":1779},{"pathPosition":{"deltaLatitude":423,"deltaLongitude":3316,"deltaAltitude":-1310},"pathDeltaTime":4300}]}}}}}"#;
    let hex = "0000480002000040000004e5480038000200c900f40200000000000000000a014cff42ff34ff34ff7f390000f7c52687ebeb050091000c177c3d3c95fa000000000000000000000088000000ffffffffffff8ab0f8a8a225ffffffffffff00882300aaaa03000000894711000501205002800043010014008ab0f8a8a225449b26ff1feb290e05ec04bd800e02d40000000007d1000002029c6bc79326ff405ab20241ce26bad7a18618600036ccd0482d4fa005a882988a7f33ff01fffa00283300002c027902d9adf00379601a6833cd63f0432ce5dc898b";
    let raw = (0..hex.len())
        .step_by(2)
        .map(|s| u8::from_str_radix(&hex[s..s + 2], 16))
        .collect::<Result<Vec<u8>, _>>()
        .unwrap();
    let decoded =
        c_its_parser::de::decode(&raw, c_its_parser::Headers::RadioTap802LlcGnBtp).unwrap();
    if let ItsMessage::Cam {
        geonetworking: Some(geo),
        transport: Some(tp),
        etsi,
    } = decoded
    {
        pretty_assertions::assert_eq!(geo.encode_to_json().unwrap(), exp_geonetworking);
        pretty_assertions::assert_eq!(tp.encode_to_json().unwrap(), exp_tp);
        pretty_assertions::assert_eq!(
            serde_json::from_str::<serde_json::Value>(
                &String::from_utf8(
                    ItsMessage::Cam {
                        geonetworking: None,
                        transport: None,
                        etsi
                    }
                    .encode(c_its_parser::EncodingRules::JER)
                    .unwrap()
                )
                .unwrap()
            )
            .unwrap(),
            serde_json::from_str::<serde_json::Value>(exp_etsi).unwrap()
        );
    } else {
        panic!("Failed decode_pcap_frame!");
    }
}

#[test]
#[cfg(all(
    not(target_arch = "wasm32"),
    any(
        feature = "denm_2_2_1",
        feature = "cam_1_4_1",
        feature = "mapem_2_2_1",
        feature = "spatem_2_2_1",
        feature = "ivim_2_2_1",
        feature = "cpm_1"
    )
))]
fn round_trip() {
    let messages = [
        #[cfg(feature = "denm_2_2_1")]
        DENM,
        #[cfg(feature = "cam_1_4_1")]
        CAM,
        #[cfg(feature = "mapem_2_2_1")]
        MAPEM,
        #[cfg(feature = "spatem_2_2_1")]
        SPATEM,
        #[cfg(feature = "ivim_2_2_1")]
        IVIM,
        #[cfg(feature = "cpm_1")]
        CPM,
    ];
    for message in messages {
        let uper_decoded = c_its_parser::de::decode(message, c_its_parser::Headers::None).unwrap();

        // Encode to all encoding rules
        let _uper_encoded = uper_decoded
            .clone()
            .encode(c_its_parser::EncodingRules::UPER)
            .unwrap();
        let xer_encoded = uper_decoded
            .clone()
            .encode(c_its_parser::EncodingRules::XER)
            .unwrap();
        let jer_encoded = uper_decoded
            .clone()
            .encode(c_its_parser::EncodingRules::JER)
            .unwrap();

        // Decode from XER and JER (UPER done already)
        let xer_decoded =
            c_its_parser::de::decode(&xer_encoded, c_its_parser::Headers::None).unwrap();
        let jer_decoded =
            c_its_parser::de::decode(&jer_encoded, c_its_parser::Headers::None).unwrap();

        pretty_assertions::assert_eq!(uper_decoded, xer_decoded);
        pretty_assertions::assert_eq!(uper_decoded, jer_decoded);
    }
}

#[cfg(all(not(target_arch = "wasm32"), feature = "srem_2_2_1", feature = "json"))]
#[test]
fn test_srem_versions() {
    // decode "old" SREM without OCIT extension
    {
        let srem_pre_ocit_jer = "{\"header\":{\"messageId\":9,\"protocolVersion\":2,\"stationId\":2789528031},\"srm\":{\"requestor\":{\"id\":{\"stationID\":2789528031},\"position\":{\"heading\":21040,\"position\":{\"elevation\":0,\"lat\":536037063,\"long\":100312642}},\"type\":{\"role\":\"basicVehicle\"}},\"requests\":[{\"minute\":29658,\"request\":{\"id\":{\"id\":123},\"inBoundLane\":{\"lane\":1},\"requestID\":1,\"requestType\":\"priorityRequest\"},\"second\":34000}],\"second\":37000,\"sequenceNumber\":0,\"timeStamp\":29657}}";

        let uper_decoded =
            c_its_parser::de::decode(SREM_PRE_OCIT, c_its_parser::Headers::None).unwrap();

        // Encode to all encoding rules
        let _uper_encoded = uper_decoded
            .clone()
            .encode(c_its_parser::EncodingRules::UPER)
            .unwrap();
        let xer_encoded = uper_decoded
            .clone()
            .encode(c_its_parser::EncodingRules::XER)
            .unwrap();
        let jer_encoded = uper_decoded
            .clone()
            .encode(c_its_parser::EncodingRules::JER)
            .unwrap();

        // Decode from XER and JER (UPER done already)
        let xer_decoded =
            c_its_parser::de::decode(&xer_encoded, c_its_parser::Headers::None).unwrap();
        let jer_decoded =
            c_its_parser::de::decode(&jer_encoded, c_its_parser::Headers::None).unwrap();

        pretty_assertions::assert_eq!(uper_decoded, xer_decoded);
        pretty_assertions::assert_eq!(uper_decoded, jer_decoded);

        // compare JER with known good value
        let jer_decoded =
            c_its_parser::de::decode(srem_pre_ocit_jer.as_bytes(), c_its_parser::Headers::None)
                .unwrap();
        pretty_assertions::assert_eq!(uper_decoded, jer_decoded);

        pretty_assertions::assert_eq!(
            serde_json::from_str::<serde_json::Value>(srem_pre_ocit_jer).unwrap(),
            serde_json::from_slice::<serde_json::Value>(&jer_encoded).unwrap()
        );
    }

    // round-trip SREM with OCIT extension
    {
        let srem_ocit_empty_jer = "{\"header\":{\"protocolVersion\":2,\"messageId\":9,\"stationId\":760129084},\"srm\":{\"timeStamp\":98917,\"second\":23692,\"sequenceNumber\":87,\"requests\":[{\"request\":{\"id\":{\"id\":0},\"requestID\":0,\"requestType\":\"priorityRequestUpdate\",\"inBoundLane\":{\"approach\":0},\"outBoundLane\":{\"approach\":0}}}],\"requestor\":{\"id\":{\"stationID\":3919},\"type\":{\"role\":\"publicTransport\"},\"position\":{\"position\":{\"lat\":535485106,\"long\":99886480},\"speed\":{\"transmisson\":\"unavailable\",\"speed\":232}},\"transitStatus\":\"00\",\"transitOccupancy\":\"occupancyMed\",\"transitSchedule\":4}}}";

        let decoded =
            c_its_parser::de::decode(srem_ocit_empty_jer.as_bytes(), c_its_parser::Headers::None)
                .unwrap();
        let encoded = decoded.encode(c_its_parser::EncodingRules::JER).unwrap();

        pretty_assertions::assert_eq!(
            serde_json::from_str::<serde_json::Value>(srem_ocit_empty_jer).unwrap(),
            serde_json::from_slice::<serde_json::Value>(&encoded).unwrap()
        );
    }
}

#[cfg(all(not(target_arch = "wasm32"), feature = "mapem_2_2_1"))]
#[test]
fn test_mapem_versions() {
    // test XER which uses old CDD
    {
        let xer_string = include_str!("files/mapem-cdd_1_3_1.xml");

        let decoded =
            c_its_parser::de::decode(xer_string.as_bytes(), c_its_parser::Headers::None).unwrap();
        let _re_encoded = decoded.encode(c_its_parser::EncodingRules::XER).unwrap();

        // don't check if XER is equal since it's expected to have different capitalization of messageId and stationID
    }
    // test XER which uses current CDD
    {
        let xer_string = include_str!("files/mapem-cdd_2_2_1.xml");

        let decoded =
            c_its_parser::de::decode(xer_string.as_bytes(), c_its_parser::Headers::None).unwrap();
        let re_encoded = decoded.encode(c_its_parser::EncodingRules::XER).unwrap();

        pretty_assertions::assert_eq!(
            xmltree::Element::parse(xer_string.as_bytes()).unwrap(),
            xmltree::Element::parse(re_encoded.as_slice()).unwrap(),
        );
    }
}

#[cfg(all(not(target_arch = "wasm32"), feature = "ivim_2_2_1"))]
#[test]
fn segment() {
    use c_its_parser::standards::cdd_2_2_1::etsi_its_cdd::{
        DeltaLatitude,
        DeltaLongitude,
        LaneWidth,
    };
    use c_its_parser::standards::ivim_2_2_1::ivi;

    let expected = xmltree::Element::parse(include_str!("files/segment.xml").as_bytes()).unwrap();
    let decoded = ivi::Segment::new(
        ivi::PolygonalLine::deltaPositions(ivi::DeltaPositions(vec![
            ivi::DeltaPosition::new(DeltaLatitude(937), DeltaLongitude(-917)),
            ivi::DeltaPosition::new(DeltaLatitude(933), DeltaLongitude(-458)),
            ivi::DeltaPosition::new(DeltaLatitude(1375), DeltaLongitude(-323)),
        ])),
        Some(LaneWidth(350)),
    );
    let re_encoded =
        xmltree::Element::parse(rasn::xer::encode(&decoded).unwrap().as_slice()).unwrap();
    pretty_assertions::assert_eq!(expected, re_encoded);
}

#[cfg(all(not(target_arch = "wasm32"), feature = "ivim_2_2_1"))]
#[test]
fn ivim_xer_impl() {
    let expected =
        xmltree::Element::parse(include_str!("files/ivim_xer_impl_ivi.xml").as_bytes()).unwrap();
    let decoded = c_its_parser::de::decode(
        &[
            0x02, 0x06, 0x00, 0x12, 0x10, 0xdc, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00, 0x88, 0x05,
            0x58, 0xea, 0xad, 0x57, 0x13, 0xd7, 0xa6, 0x4f, 0xff, 0xff, 0xfe, 0x11, 0xdb, 0xba,
            0x1f, 0x08, 0xc0, 0xe1, 0x11, 0x01, 0x40, 0x75, 0x0f, 0xe3, 0x54, 0x07, 0x48, 0xff,
            0x1a, 0xc0, 0xab, 0xcf, 0xf5, 0xe2, 0xbc, 0x30, 0x78, 0x44, 0x40, 0x2f, 0xff, 0x24,
            0x11, 0x2f, 0x01, 0x29, 0x45, 0x70, 0xea, 0xf0, 0x81, 0x60, 0x00, 0x02, 0x00, 0x04,
            0x08, 0x01, 0x4e,
        ],
        c_its_parser::Headers::None,
    )
    .unwrap();
    let re_encoded = xmltree::Element::parse(
        decoded
            .encode(c_its_parser::EncodingRules::XER)
            .unwrap()
            .as_slice(),
    )
    .unwrap();
    pretty_assertions::assert_eq!(expected, re_encoded);
}

#[cfg(all(not(target_arch = "wasm32"), feature = "ivim_2_1_1"))]
#[test]
fn xer_to_xer() {
    let expected_bytes = include_str!("files/xer_to_xer_ivi.xml").as_bytes();
    let expected_xml = xmltree::Element::parse(expected_bytes).unwrap();
    let decoded = c_its_parser::de::decode(expected_bytes, c_its_parser::Headers::None).unwrap();
    let re_encoded = xmltree::Element::parse(
        decoded
            .encode(c_its_parser::EncodingRules::XER)
            .unwrap()
            .as_slice(),
    )
    .unwrap();
    pretty_assertions::assert_eq!(expected_xml, re_encoded);
}

#[cfg(all(not(target_arch = "wasm32"), feature = "ivim_2_1_1"))]
#[test]
fn xer_to_uper() {
    let expected = &[
        0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0xba, 0x50, 0x00, 0xc8, 0x00, 0x01, 0x90, 0x15, 0xbd,
        0xce, 0x3a, 0x64, 0x05, 0x2a, 0xc9, 0x55, 0xd9, 0x01, 0x5b, 0xdc, 0xdd, 0x94, 0x20, 0x15,
        0x0d, 0x3f, 0xd0, 0x5c, 0x3b, 0xc1, 0x8b, 0x40, 0x04, 0x00, 0x40, 0x03, 0x6e, 0xe8, 0x40,
        0x41, 0x00, 0x02, 0x57, 0xfc, 0x06, 0x63, 0x15, 0x92, 0xa3, 0xe9, 0x3f, 0x1a, 0x72, 0xde,
        0xed, 0xe9, 0xae, 0x9d, 0xf4, 0x03, 0xba, 0xbc, 0x4f, 0x70, 0x29, 0xa1, 0x11, 0x77, 0xf8,
        0xb9, 0x8e, 0x97, 0x52, 0x33, 0x95, 0x38, 0x71, 0x6b, 0xd9, 0x52, 0xb6, 0xdf, 0xc3, 0x99,
        0xae, 0x69, 0xbb, 0xd9, 0xdf, 0xde, 0x80, 0x07, 0xa5, 0x41, 0x66, 0x6d, 0x7a, 0xbd, 0x76,
        0x5e, 0x5f, 0xb2, 0x66, 0xe6, 0x00, 0x9c, 0x0d, 0x36, 0x66, 0xed, 0xcd, 0x64, 0x65, 0xd7,
        0x1d, 0xde, 0x3e, 0x3d, 0xa7, 0xed, 0xca, 0x62, 0xcc, 0x1f, 0xf7, 0x36, 0x30, 0xb6, 0x10,
        0x40, 0x18, 0xff, 0xff, 0xbf, 0xff, 0xed, 0xfc, 0x89, 0xa5, 0xa8, 0xe3, 0xbd, 0x9d, 0x25,
        0x8e, 0x77, 0x0a, 0x03, 0xd2, 0xe9, 0x59, 0x22, 0x17, 0xee, 0xb3, 0x42, 0x41, 0xfc, 0xec,
        0xfb, 0xa6, 0x42, 0xce, 0xfb, 0xb2, 0x9e, 0xa4, 0xf4, 0x6c, 0x30, 0x9a, 0x6f, 0x86, 0x3b,
        0x65, 0x4a, 0xfb, 0x76, 0x3a, 0xa9, 0x8f, 0xdd, 0x43, 0xda, 0x89, 0x7f, 0xc0, 0x66, 0x31,
        0x41, 0x08, 0x00, 0xfa, 0x3a, 0xaf, 0x8f, 0x45, 0xa7, 0x2d, 0xf9, 0x85, 0xba, 0xc8, 0x8f,
        0x9f, 0xbd, 0xaf, 0xe5, 0xfa, 0x59, 0xdb, 0x3b, 0x1f, 0xb0, 0x9d, 0xb7, 0x50, 0x7b, 0xcb,
        0xbb, 0xca, 0xcf, 0xd9, 0x5d, 0xbf, 0xb3, 0xfe, 0xc8, 0xe2, 0x15, 0x84, 0x20, 0x08, 0x00,
        0x20, 0x02, 0xa2, 0x22, 0x82, 0x64, 0x04, 0x4a, 0x10, 0x10, 0x4a, 0x8c, 0xae, 0x6e, 0x84,
        0x05, 0xe4, 0x0a, 0x6e, 0x8e, 0x4c, 0x2e, 0x8c, 0xac, 0xed, 0x2c, 0xa4, 0x09, 0xce, 0x45,
        0xc4, 0x08, 0x25, 0xa6, 0x64, 0x18, 0x73, 0x8c, 0x4c, 0xae, 0x4d, 0x8c, 0x2e, 0x6e, 0x8e,
        0xad, 0xcc, 0xe4, 0x0c, 0x8c, 0xae, 0x44, 0x08, 0x48, 0x28, 0x44, 0x06, 0x87, 0x24, 0x08,
        0x2a, 0x61, 0x44, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x09, 0x6a, 0x65, 0xaa, 0xec, 0x2d, 0x8c,
        0x8c, 0x2e, 0xa1, 0x44, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
        0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
        0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x08, 0x00, 0x21, 0x08, 0x15, 0x11, 0x14, 0x13, 0x1e,
    ];
    // This string can't be in one line, because of new lines in the free text
    let decoded = c_its_parser::de::decode(
        include_str!("files/xer_to_uper_ivi.xml").as_bytes(),
        c_its_parser::Headers::None,
    )
    .unwrap();
    let re_encoded = decoded.encode(c_its_parser::EncodingRules::UPER).unwrap();

    pretty_assertions::assert_eq!(expected, re_encoded.as_slice());
}