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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
use crate::stdf_error::StdfError;
extern crate smart_default;
use smart_default::SmartDefault;
use std::convert::From;
macro_rules! read_optional {
($var:expr, [$func:ident($raw:expr, $pos:expr)], $min_bytes:expr) => {{
if *$pos + $min_bytes > $raw.len() {
$var = None;
return;
} else {
$var = Some([$func($raw, $pos)]);
}
}};
($var:expr, $func:ident($raw:expr, $pos:expr), $min_bytes:expr) => {{
if *$pos + $min_bytes > $raw.len() {
$var = None;
return;
} else {
$var = Some($func($raw, $pos));
}
}};
($var:expr, $func:ident($raw:expr, $pos:expr, $order:expr), $min_bytes:expr) => {{
if *$pos + $min_bytes > $raw.len() {
$var = None;
} else {
$var = Some($func($raw, $pos, $order));
}
}};
($var:expr, $func:ident($raw:expr, $pos:expr, $order:expr, $cnt:expr), $element_bytes:expr) => {{
if *$pos + $element_bytes * $cnt as usize > $raw.len() {
$var = None;
} else {
$var = Some($func($raw, $pos, $order, $cnt));
}
}};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ByteOrder {
LittleEndian,
BigEndian,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompressType {
Uncompressed,
GzipCompressed,
BzipCompressed,
ZipCompressed,
}
#[derive(SmartDefault, Debug, Clone, Copy, PartialEq, Eq)]
pub struct RecordHeader {
pub len: u16,
pub typ: u8,
pub sub: u8,
#[default(stdf_record_type::REC_INVALID)]
pub type_code: u64,
}
pub type B1 = [u8; 1];
pub type C1 = char;
pub type U1 = u8;
pub type U2 = u16;
pub type U4 = u32;
pub type U8 = u64;
pub type I1 = i8;
pub type I2 = i16;
pub type I4 = i32;
pub type R4 = f32;
pub type R8 = f64;
pub type Cn = String;
pub type Cf = String;
pub type Sn = String;
pub type Bn = Vec<u8>;
pub type Dn = Vec<u8>;
pub type KxCn = Vec<Cn>;
pub type KxSn = Vec<Sn>;
pub type KxCf = Vec<Cf>;
pub type KxU1 = Vec<U1>;
pub type KxU2 = Vec<U2>;
pub type KxU4 = Vec<U4>;
pub type KxU8 = Vec<U8>;
pub type KxR4 = Vec<R4>;
pub type KxN1 = Vec<U1>;
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub enum KxUf {
#[default]
F1(KxU1),
F2(KxU2),
F4(KxU4),
F8(KxU8),
}
#[derive(Debug, Clone, PartialEq)]
pub enum V1 {
B0,
U1(U1),
U2(U2),
U4(U4),
I1(I1),
I2(I2),
I4(I4),
R4(R4),
R8(R8),
Cn(Cn),
Bn(Bn),
Dn(Dn),
N1(U1),
Invalid,
}
pub type Vn = Vec<V1>;
pub mod stdf_record_type {
use crate::stdf_error::StdfError;
pub const REC_FAR: u64 = 1;
pub const REC_ATR: u64 = 1 << 1;
pub const REC_VUR: u64 = 1 << 2;
pub const REC_MIR: u64 = 1 << 3;
pub const REC_MRR: u64 = 1 << 4;
pub const REC_PCR: u64 = 1 << 5;
pub const REC_HBR: u64 = 1 << 6;
pub const REC_SBR: u64 = 1 << 7;
pub const REC_PMR: u64 = 1 << 8;
pub const REC_PGR: u64 = 1 << 9;
pub const REC_PLR: u64 = 1 << 10;
pub const REC_RDR: u64 = 1 << 11;
pub const REC_SDR: u64 = 1 << 12;
pub const REC_PSR: u64 = 1 << 13;
pub const REC_NMR: u64 = 1 << 14;
pub const REC_CNR: u64 = 1 << 15;
pub const REC_SSR: u64 = 1 << 16;
pub const REC_CDR: u64 = 1 << 17;
pub const REC_WIR: u64 = 1 << 18;
pub const REC_WRR: u64 = 1 << 19;
pub const REC_WCR: u64 = 1 << 20;
pub const REC_PIR: u64 = 1 << 21;
pub const REC_PRR: u64 = 1 << 22;
pub const REC_TSR: u64 = 1 << 23;
pub const REC_PTR: u64 = 1 << 24;
pub const REC_MPR: u64 = 1 << 25;
pub const REC_FTR: u64 = 1 << 26;
pub const REC_STR: u64 = 1 << 27;
pub const REC_BPS: u64 = 1 << 28;
pub const REC_EPS: u64 = 1 << 29;
pub const REC_GDR: u64 = 1 << 30;
pub const REC_DTR: u64 = 1 << 31;
pub const REC_RESERVE: u64 = 1 << 32;
pub const REC_INVALID: u64 = 1 << 33;
#[inline(always)]
pub fn get_typ_sub_from_code(code: u64) -> Result<(u8, u8), StdfError> {
match code {
REC_PTR => Ok((15, 10)),
REC_MPR => Ok((15, 15)),
REC_FTR => Ok((15, 20)),
REC_STR => Ok((15, 30)),
REC_PIR => Ok((5, 10)),
REC_PRR => Ok((5, 20)),
REC_WIR => Ok((2, 10)),
REC_WRR => Ok((2, 20)),
REC_WCR => Ok((2, 30)),
REC_GDR => Ok((50, 10)),
REC_DTR => Ok((50, 30)),
REC_FAR => Ok((0, 10)),
REC_ATR => Ok((0, 20)),
REC_VUR => Ok((0, 30)),
REC_MIR => Ok((1, 10)),
REC_MRR => Ok((1, 20)),
REC_PCR => Ok((1, 30)),
REC_HBR => Ok((1, 40)),
REC_SBR => Ok((1, 50)),
REC_PMR => Ok((1, 60)),
REC_PGR => Ok((1, 62)),
REC_PLR => Ok((1, 63)),
REC_RDR => Ok((1, 70)),
REC_SDR => Ok((1, 80)),
REC_PSR => Ok((1, 90)),
REC_NMR => Ok((1, 91)),
REC_CNR => Ok((1, 92)),
REC_SSR => Ok((1, 93)),
REC_CDR => Ok((1, 94)),
REC_TSR => Ok((10, 30)),
REC_BPS => Ok((20, 10)),
REC_EPS => Ok((20, 20)),
_ => Err(StdfError {
code: 2,
msg: "unknown type constant".to_string(),
}),
}
}
#[inline(always)]
pub fn get_code_from_typ_sub(typ: u8, sub: u8) -> u64 {
match (typ, sub) {
(15, 10) => REC_PTR,
(15, 15) => REC_MPR,
(15, 20) => REC_FTR,
(15, 30) => REC_STR,
(5, 10) => REC_PIR,
(5, 20) => REC_PRR,
(2, 10) => REC_WIR,
(2, 20) => REC_WRR,
(2, 30) => REC_WCR,
(50, 10) => REC_GDR,
(50, 30) => REC_DTR,
(0, 10) => REC_FAR,
(0, 20) => REC_ATR,
(0, 30) => REC_VUR,
(1, 10) => REC_MIR,
(1, 20) => REC_MRR,
(1, 30) => REC_PCR,
(1, 40) => REC_HBR,
(1, 50) => REC_SBR,
(1, 60) => REC_PMR,
(1, 62) => REC_PGR,
(1, 63) => REC_PLR,
(1, 70) => REC_RDR,
(1, 80) => REC_SDR,
(1, 90) => REC_PSR,
(1, 91) => REC_NMR,
(1, 92) => REC_CNR,
(1, 93) => REC_SSR,
(1, 94) => REC_CDR,
(10, 30) => REC_TSR,
(20, 10) => REC_BPS,
(20, 20) => REC_EPS,
(180 | 181, _) => REC_RESERVE,
(_, _) => REC_INVALID,
}
}
#[inline(always)]
pub fn get_rec_name_from_code(rec_type: u64) -> &'static str {
match rec_type {
REC_PTR => "PTR",
REC_MPR => "MPR",
REC_FTR => "FTR",
REC_STR => "STR",
REC_PIR => "PIR",
REC_PRR => "PRR",
REC_WIR => "WIR",
REC_WRR => "WRR",
REC_WCR => "WCR",
REC_GDR => "GDR",
REC_DTR => "DTR",
REC_FAR => "FAR",
REC_ATR => "ATR",
REC_VUR => "VUR",
REC_MIR => "MIR",
REC_MRR => "MRR",
REC_PCR => "PCR",
REC_HBR => "HBR",
REC_SBR => "SBR",
REC_PMR => "PMR",
REC_PGR => "PGR",
REC_PLR => "PLR",
REC_RDR => "RDR",
REC_SDR => "SDR",
REC_PSR => "PSR",
REC_NMR => "NMR",
REC_CNR => "CNR",
REC_SSR => "SSR",
REC_CDR => "CDR",
REC_TSR => "TSR",
REC_BPS => "BPS",
REC_EPS => "EPS",
REC_RESERVE => "ReservedRec",
_ => "InvalidRec",
}
}
#[inline(always)]
pub fn get_code_from_rec_name(rec_name: &str) -> u64 {
match rec_name {
"FAR" => REC_FAR,
"ATR" => REC_ATR,
"VUR" => REC_VUR,
"MIR" => REC_MIR,
"MRR" => REC_MRR,
"PCR" => REC_PCR,
"HBR" => REC_HBR,
"SBR" => REC_SBR,
"PMR" => REC_PMR,
"PGR" => REC_PGR,
"PLR" => REC_PLR,
"RDR" => REC_RDR,
"SDR" => REC_SDR,
"PSR" => REC_PSR,
"NMR" => REC_NMR,
"CNR" => REC_CNR,
"SSR" => REC_SSR,
"CDR" => REC_CDR,
"WIR" => REC_WIR,
"WRR" => REC_WRR,
"WCR" => REC_WCR,
"PIR" => REC_PIR,
"PRR" => REC_PRR,
"TSR" => REC_TSR,
"PTR" => REC_PTR,
"MPR" => REC_MPR,
"FTR" => REC_FTR,
"STR" => REC_STR,
"BPS" => REC_BPS,
"EPS" => REC_EPS,
"GDR" => REC_GDR,
"DTR" => REC_DTR,
_ => REC_INVALID,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum StdfRecord {
FAR(FAR),
ATR(ATR),
VUR(VUR),
MIR(MIR),
MRR(MRR),
PCR(PCR),
HBR(HBR),
SBR(SBR),
PMR(PMR),
PGR(PGR),
PLR(PLR),
RDR(RDR),
SDR(SDR),
PSR(PSR),
NMR(NMR),
CNR(CNR),
SSR(SSR),
CDR(CDR),
WIR(WIR),
WRR(WRR),
WCR(WCR),
PIR(PIR),
PRR(PRR),
TSR(TSR),
PTR(PTR),
MPR(MPR),
FTR(FTR),
STR(STR),
BPS(BPS),
EPS(EPS),
GDR(GDR),
DTR(DTR),
ReservedRec(ReservedRec),
InvalidRec(RecordHeader),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawDataElement {
pub offset: u64,
pub type_code: u64,
pub raw_data: Vec<u8>,
pub byte_order: ByteOrder,
}
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct FAR {
pub cpu_type: U1, pub stdf_ver: U1, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct ATR {
pub mod_tim: U4, pub cmd_line: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct VUR {
pub upd_nam: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct MIR {
pub setup_t: U4, pub start_t: U4, pub stat_num: U1, #[default = ' ']
pub mode_cod: C1, #[default = ' ']
pub rtst_cod: C1, #[default = ' ']
pub prot_cod: C1, #[default = 65535]
pub burn_tim: U2, #[default = ' ']
pub cmod_cod: C1, pub lot_id: Cn, pub part_typ: Cn, pub node_nam: Cn, pub tstr_typ: Cn, pub job_nam: Cn, pub job_rev: Cn, pub sblot_id: Cn, pub oper_nam: Cn, pub exec_typ: Cn, pub exec_ver: Cn, pub test_cod: Cn, pub tst_temp: Cn, pub user_txt: Cn, pub aux_file: Cn, pub pkg_typ: Cn, pub famly_id: Cn, pub date_cod: Cn, pub facil_id: Cn, pub floor_id: Cn, pub proc_id: Cn, pub oper_frq: Cn, pub spec_nam: Cn, pub spec_ver: Cn, pub flow_id: Cn, pub setup_id: Cn, pub dsgn_rev: Cn, pub eng_id: Cn, pub rom_cod: Cn, pub serl_num: Cn, pub supr_nam: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct MRR {
pub finish_t: U4, #[default = ' ']
pub disp_cod: C1, pub usr_desc: Cn, pub exc_desc: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PCR {
pub head_num: U1, pub site_num: U1, pub part_cnt: U4, #[default = 4_294_967_295]
pub rtst_cnt: U4, #[default = 4_294_967_295]
pub abrt_cnt: U4, #[default = 4_294_967_295]
pub good_cnt: U4, #[default = 4_294_967_295]
pub func_cnt: U4, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct HBR {
pub head_num: U1, pub site_num: U1, pub hbin_num: U2, pub hbin_cnt: U4, #[default = ' ']
pub hbin_pf: C1, pub hbin_nam: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct SBR {
pub head_num: U1, pub site_num: U1, pub sbin_num: U2, pub sbin_cnt: U4, #[default = ' ']
pub sbin_pf: C1, pub sbin_nam: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PMR {
pub pmr_indx: U2, #[default = 0]
pub chan_typ: U2, pub chan_nam: Cn, pub phy_nam: Cn, pub log_nam: Cn, #[default = 1]
pub head_num: U1, #[default = 1]
pub site_num: U1, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PGR {
pub grp_indx: U2, pub grp_nam: Cn, pub indx_cnt: U2, pub pmr_indx: KxU2, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PLR {
pub grp_cnt: U2, pub grp_indx: KxU2, pub grp_mode: KxU2, pub grp_radx: KxU1, pub pgm_char: KxCn, pub rtn_char: KxCn, pub pgm_chal: KxCn, pub rtn_chal: KxCn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct RDR {
pub num_bins: U2, pub rtst_bin: KxU2, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct SDR {
pub head_num: U1, pub site_grp: U1, pub site_cnt: U1, pub site_num: KxU1, pub hand_typ: Cn, pub hand_id: Cn, pub card_typ: Cn, pub card_id: Cn, pub load_typ: Cn, pub load_id: Cn, pub dib_typ: Cn, pub dib_id: Cn, pub cabl_typ: Cn, pub cabl_id: Cn, pub cont_typ: Cn, pub cont_id: Cn, pub lasr_typ: Cn, pub lasr_id: Cn, pub extr_typ: Cn, pub extr_id: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PSR {
pub cont_flg: B1, pub psr_indx: U2, pub psr_nam: Cn, pub opt_flg: B1, pub totp_cnt: U2, pub locp_cnt: U2, pub pat_bgn: KxU8, pub pat_end: KxU8, pub pat_file: KxCn, pub pat_lbl: KxCn, pub file_uid: KxCn, pub atpg_dsc: KxCn, pub src_id: KxCn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct NMR {
pub cont_flg: B1, pub totm_cnt: U2, pub locm_cnt: U2, pub pmr_indx: KxU2, pub atpg_nam: KxCn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct CNR {
pub chn_num: U2, pub bit_pos: U4, pub cell_nam: Sn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct SSR {
pub ssr_nam: Cn, pub chn_cnt: U2, pub chn_list: KxU2, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct CDR {
pub cont_flg: B1, pub cdr_indx: U2, pub chn_nam: Cn, pub chn_len: U4, pub sin_pin: U2, pub sout_pin: U2, pub mstr_cnt: U1, pub m_clks: KxU2, pub slav_cnt: U1, pub s_clks: KxU2, #[default = 255]
pub inv_val: U1, pub lst_cnt: U2, pub cell_lst: KxSn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct WIR {
pub head_num: U1, #[default = 255]
pub site_grp: U1, pub start_t: U4, pub wafer_id: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct WRR {
pub head_num: U1, #[default = 255]
pub site_grp: U1, pub finish_t: U4, pub part_cnt: U4, #[default = 4_294_967_295]
pub rtst_cnt: U4, #[default = 4_294_967_295]
pub abrt_cnt: U4, #[default = 4_294_967_295]
pub good_cnt: U4, #[default = 4_294_967_295]
pub func_cnt: U4, pub wafer_id: Cn, pub fabwf_id: Cn, pub frame_id: Cn, pub mask_id: Cn, pub usr_desc: Cn, pub exc_desc: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct WCR {
#[default = 0.0]
pub wafr_siz: R4, #[default = 0.0]
pub die_ht: R4, #[default = 0.0]
pub die_wid: R4, #[default = 0]
pub wf_units: U1, #[default = ' ']
pub wf_flat: C1, #[default(-32768)]
pub center_x: I2, #[default(-32768)]
pub center_y: I2, #[default = ' ']
pub pos_x: C1, #[default = ' ']
pub pos_y: C1, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PIR {
pub head_num: U1, pub site_num: U1, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct PRR {
pub head_num: U1, pub site_num: U1, pub part_flg: B1, pub num_test: U2, pub hard_bin: U2, #[default = 65535]
pub soft_bin: U2, #[default(-32768)]
pub x_coord: I2, #[default(-32768)]
pub y_coord: I2, #[default = 0]
pub test_t: U4, pub part_id: Cn, pub part_txt: Cn, pub part_fix: Bn, }
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct TSR {
pub head_num: U1, pub site_num: U1, #[default = ' ']
pub test_typ: C1, pub test_num: U4, #[default = 4_294_967_295]
pub exec_cnt: U4, #[default = 4_294_967_295]
pub fail_cnt: U4, #[default = 4_294_967_295]
pub alrm_cnt: U4, pub test_nam: Cn, pub seq_name: Cn, pub test_lbl: Cn, pub opt_flag: B1, pub test_tim: R4, pub test_min: R4, pub test_max: R4, pub tst_sums: R4, pub tst_sqrs: R4, }
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct PTR {
pub test_num: U4, pub head_num: U1, pub site_num: U1, pub test_flg: B1, pub parm_flg: B1, pub result: R4, pub test_txt: Cn, pub alarm_id: Cn, pub opt_flag: Option<B1>, pub res_scal: Option<I1>, pub llm_scal: Option<I1>, pub hlm_scal: Option<I1>, pub lo_limit: Option<R4>, pub hi_limit: Option<R4>, pub units: Option<Cn>, pub c_resfmt: Option<Cn>, pub c_llmfmt: Option<Cn>, pub c_hlmfmt: Option<Cn>, pub lo_spec: Option<R4>, pub hi_spec: Option<R4>, }
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct MPR {
pub test_num: U4, pub head_num: U1, pub site_num: U1, pub test_flg: B1, pub parm_flg: B1, pub rtn_icnt: U2, pub rslt_cnt: U2, pub rtn_stat: KxN1, pub rtn_rslt: KxR4, pub test_txt: Cn, pub alarm_id: Cn, pub opt_flag: Option<B1>, pub res_scal: Option<I1>, pub llm_scal: Option<I1>, pub hlm_scal: Option<I1>, pub lo_limit: Option<R4>, pub hi_limit: Option<R4>, pub start_in: Option<R4>, pub incr_in: Option<R4>, pub rtn_indx: Option<KxU2>, pub units: Option<Cn>, pub units_in: Option<Cn>, pub c_resfmt: Option<Cn>, pub c_llmfmt: Option<Cn>, pub c_hlmfmt: Option<Cn>, pub lo_spec: Option<R4>, pub hi_spec: Option<R4>, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct FTR {
pub test_num: U4, pub head_num: U1, pub site_num: U1, pub test_flg: B1, pub opt_flag: B1, pub cycl_cnt: U4, pub rel_vadr: U4, pub rept_cnt: U4, pub num_fail: U4, pub xfail_ad: I4, pub yfail_ad: I4, pub vect_off: I2, pub rtn_icnt: U2, pub pgm_icnt: U2, pub rtn_indx: KxU2, pub rtn_stat: KxN1, pub pgm_indx: KxU2, pub pgm_stat: KxN1, pub fail_pin: Dn, pub vect_nam: Cn, pub time_set: Cn, pub op_code: Cn, pub test_txt: Cn, pub alarm_id: Cn, pub prog_txt: Cn, pub rslt_txt: Cn, #[default = 255]
pub patg_num: U1, pub spin_map: Dn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct STR {
pub cont_flg: B1, pub test_num: U4, pub head_num: U1, pub site_num: U1, pub psr_ref: U2, pub test_flg: B1, pub log_typ: Cn, pub test_txt: Cn, pub alarm_id: Cn, pub prog_txt: Cn, pub rslt_txt: Cn, pub z_val: U1, pub fmu_flg: B1, pub mask_map: Dn, pub fal_map: Dn, pub cyc_cnt_t: U8, pub totf_cnt: U4, pub totl_cnt: U4, pub cyc_base: U8, pub bit_base: U4, pub cond_cnt: U2, pub lim_cnt: U2, pub cyc_size: U1, pub pmr_size: U1, pub chn_size: U1, pub pat_size: U1, pub bit_size: U1, pub u1_size: U1, pub u2_size: U1, pub u3_size: U1, pub utx_size: U1, pub cap_bgn: U2, pub lim_indx: KxU2, pub lim_spec: KxU4, pub cond_lst: KxCn, pub cyc_cnt: U2, pub cyc_ofst: KxUf, pub pmr_cnt: U2, pub pmr_indx: KxUf, pub chn_cnt: U2, pub chn_num: KxUf, pub exp_cnt: U2, pub exp_data: KxU1, pub cap_cnt: U2, pub cap_data: KxU1, pub new_cnt: U2, pub new_data: KxU1, pub pat_cnt: U2, pub pat_num: KxUf, pub bpos_cnt: U2, pub bit_pos: KxUf, pub usr1_cnt: U2, pub usr1: KxUf, pub usr2_cnt: U2, pub usr2: KxUf, pub usr3_cnt: U2, pub usr3: KxUf, pub txt_cnt: U2, pub user_txt: KxCf, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct BPS {
pub seq_name: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct EPS {}
#[derive(SmartDefault, Debug, Clone, PartialEq)]
pub struct GDR {
pub fld_cnt: U2, pub gen_data: Vn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct DTR {
pub text_dat: Cn, }
#[derive(SmartDefault, Debug, Clone, PartialEq, Eq)]
pub struct ReservedRec {
pub raw_data: Cn, }
impl RecordHeader {
#[inline(always)]
pub fn new() -> Self {
RecordHeader::default()
}
#[inline(always)]
pub fn read_from_bytes(
mut self,
raw_data: &[u8],
order: &ByteOrder,
) -> Result<Self, StdfError> {
match raw_data.len() {
0 => Err(StdfError {
code: 4,
msg: String::from("No bytes to read"),
}),
1..=3 => Err(StdfError {
code: 5,
msg: String::from("Not enough data to construct record header"),
}),
_ => {
let len_bytes = [raw_data[0], raw_data[1]];
self.len = match order {
ByteOrder::LittleEndian => u16::from_le_bytes(len_bytes),
ByteOrder::BigEndian => u16::from_be_bytes(len_bytes),
};
self.typ = raw_data[2];
self.sub = raw_data[3];
self.type_code = stdf_record_type::get_code_from_typ_sub(self.typ, self.sub);
Ok(self)
}
}
}
}
impl FAR {
#[inline(always)]
pub fn new() -> Self {
FAR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.cpu_type = read_uint8(raw_data, pos);
self.stdf_ver = read_uint8(raw_data, pos);
}
}
impl ATR {
#[inline(always)]
pub fn new() -> Self {
ATR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.mod_tim = read_u4(raw_data, pos, order);
self.cmd_line = read_cn(raw_data, pos);
}
}
impl VUR {
#[inline(always)]
pub fn new() -> Self {
VUR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.upd_nam = read_cn(raw_data, pos);
}
}
impl MIR {
#[inline(always)]
pub fn new() -> Self {
MIR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.setup_t = read_u4(raw_data, pos, order);
self.start_t = read_u4(raw_data, pos, order);
self.stat_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.mode_cod = read_uint8(raw_data, pos) as char;
}
if *pos < raw_data.len() {
self.rtst_cod = read_uint8(raw_data, pos) as char;
}
if *pos < raw_data.len() {
self.prot_cod = read_uint8(raw_data, pos) as char;
}
if *pos + 2 <= raw_data.len() {
self.burn_tim = read_u2(raw_data, pos, order);
}
if *pos < raw_data.len() {
self.cmod_cod = read_uint8(raw_data, pos) as char;
}
self.lot_id = read_cn(raw_data, pos);
self.part_typ = read_cn(raw_data, pos);
self.node_nam = read_cn(raw_data, pos);
self.tstr_typ = read_cn(raw_data, pos);
self.job_nam = read_cn(raw_data, pos);
self.job_rev = read_cn(raw_data, pos);
self.sblot_id = read_cn(raw_data, pos);
self.oper_nam = read_cn(raw_data, pos);
self.exec_typ = read_cn(raw_data, pos);
self.exec_ver = read_cn(raw_data, pos);
self.test_cod = read_cn(raw_data, pos);
self.tst_temp = read_cn(raw_data, pos);
self.user_txt = read_cn(raw_data, pos);
self.aux_file = read_cn(raw_data, pos);
self.pkg_typ = read_cn(raw_data, pos);
self.famly_id = read_cn(raw_data, pos);
self.date_cod = read_cn(raw_data, pos);
self.facil_id = read_cn(raw_data, pos);
self.floor_id = read_cn(raw_data, pos);
self.proc_id = read_cn(raw_data, pos);
self.oper_frq = read_cn(raw_data, pos);
self.spec_nam = read_cn(raw_data, pos);
self.spec_ver = read_cn(raw_data, pos);
self.flow_id = read_cn(raw_data, pos);
self.setup_id = read_cn(raw_data, pos);
self.dsgn_rev = read_cn(raw_data, pos);
self.eng_id = read_cn(raw_data, pos);
self.rom_cod = read_cn(raw_data, pos);
self.serl_num = read_cn(raw_data, pos);
self.supr_nam = read_cn(raw_data, pos);
}
}
impl MRR {
#[inline(always)]
pub fn new() -> Self {
MRR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.finish_t = read_u4(raw_data, pos, order);
if *pos < raw_data.len() {
self.disp_cod = read_uint8(raw_data, pos) as char;
}
self.usr_desc = read_cn(raw_data, pos);
self.exc_desc = read_cn(raw_data, pos);
}
}
impl PCR {
#[inline(always)]
pub fn new() -> Self {
PCR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.part_cnt = read_u4(raw_data, pos, order);
if *pos + 4 <= raw_data.len() {
self.rtst_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.abrt_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.good_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.func_cnt = read_u4(raw_data, pos, order);
}
}
}
impl HBR {
#[inline(always)]
pub fn new() -> Self {
HBR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.hbin_num = read_u2(raw_data, pos, order);
self.hbin_cnt = read_u4(raw_data, pos, order);
if *pos < raw_data.len() {
self.hbin_pf = read_uint8(raw_data, pos) as char;
}
self.hbin_nam = read_cn(raw_data, pos);
}
}
impl SBR {
#[inline(always)]
pub fn new() -> Self {
SBR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.sbin_num = read_u2(raw_data, pos, order);
self.sbin_cnt = read_u4(raw_data, pos, order);
if *pos < raw_data.len() {
self.sbin_pf = read_uint8(raw_data, pos) as char;
}
self.sbin_nam = read_cn(raw_data, pos);
}
}
impl PMR {
#[inline(always)]
pub fn new() -> Self {
PMR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.pmr_indx = read_u2(raw_data, pos, order);
if *pos + 2 <= raw_data.len() {
self.chan_typ = read_u2(raw_data, pos, order);
}
self.chan_nam = read_cn(raw_data, pos);
self.phy_nam = read_cn(raw_data, pos);
self.log_nam = read_cn(raw_data, pos);
if *pos < raw_data.len() {
self.head_num = read_uint8(raw_data, pos)
};
if *pos < raw_data.len() {
self.site_num = read_uint8(raw_data, pos)
};
}
}
impl PGR {
#[inline(always)]
pub fn new() -> Self {
PGR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.grp_indx = read_u2(raw_data, pos, order);
self.grp_nam = read_cn(raw_data, pos);
self.indx_cnt = read_u2(raw_data, pos, order);
self.pmr_indx = read_kx_u2(raw_data, pos, order, self.indx_cnt);
}
}
impl PLR {
#[inline(always)]
pub fn new() -> Self {
PLR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.grp_cnt = read_u2(raw_data, pos, order);
self.grp_indx = read_kx_u2(raw_data, pos, order, self.grp_cnt);
self.grp_mode = read_kx_u2(raw_data, pos, order, self.grp_cnt);
self.grp_radx = read_kx_u1(raw_data, pos, self.grp_cnt);
self.pgm_char = read_kx_cn(raw_data, pos, self.grp_cnt);
self.rtn_char = read_kx_cn(raw_data, pos, self.grp_cnt);
self.pgm_chal = read_kx_cn(raw_data, pos, self.grp_cnt);
self.rtn_chal = read_kx_cn(raw_data, pos, self.grp_cnt);
}
}
impl RDR {
#[inline(always)]
pub fn new() -> Self {
RDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.num_bins = read_u2(raw_data, pos, order);
self.rtst_bin = read_kx_u2(raw_data, pos, order, self.num_bins);
}
}
impl SDR {
#[inline(always)]
pub fn new() -> Self {
SDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_grp = read_uint8(raw_data, pos);
self.site_cnt = read_uint8(raw_data, pos);
self.site_num = read_kx_u1(raw_data, pos, self.site_cnt as u16);
self.hand_typ = read_cn(raw_data, pos);
self.hand_id = read_cn(raw_data, pos);
self.card_typ = read_cn(raw_data, pos);
self.card_id = read_cn(raw_data, pos);
self.load_typ = read_cn(raw_data, pos);
self.load_id = read_cn(raw_data, pos);
self.dib_typ = read_cn(raw_data, pos);
self.dib_id = read_cn(raw_data, pos);
self.cabl_typ = read_cn(raw_data, pos);
self.cabl_id = read_cn(raw_data, pos);
self.cont_typ = read_cn(raw_data, pos);
self.cont_id = read_cn(raw_data, pos);
self.lasr_typ = read_cn(raw_data, pos);
self.lasr_id = read_cn(raw_data, pos);
self.extr_typ = read_cn(raw_data, pos);
self.extr_id = read_cn(raw_data, pos);
}
}
impl PSR {
#[inline(always)]
pub fn new() -> Self {
PSR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.psr_indx = read_u2(raw_data, pos, order);
self.psr_nam = read_cn(raw_data, pos);
self.opt_flg = [read_uint8(raw_data, pos)];
self.totp_cnt = read_u2(raw_data, pos, order);
self.locp_cnt = read_u2(raw_data, pos, order);
self.pat_bgn = read_kx_u8(raw_data, pos, order, self.locp_cnt);
self.pat_end = read_kx_u8(raw_data, pos, order, self.locp_cnt);
self.pat_file = read_kx_cn(raw_data, pos, self.locp_cnt);
self.pat_lbl = read_kx_cn(raw_data, pos, self.locp_cnt);
self.file_uid = read_kx_cn(raw_data, pos, self.locp_cnt);
self.atpg_dsc = read_kx_cn(raw_data, pos, self.locp_cnt);
self.src_id = read_kx_cn(raw_data, pos, self.locp_cnt);
}
}
impl NMR {
#[inline(always)]
pub fn new() -> Self {
NMR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.totm_cnt = read_u2(raw_data, pos, order);
self.locm_cnt = read_u2(raw_data, pos, order);
self.pmr_indx = read_kx_u2(raw_data, pos, order, self.locm_cnt);
self.atpg_nam = read_kx_cn(raw_data, pos, self.locm_cnt);
}
}
impl CNR {
#[inline(always)]
pub fn new() -> Self {
CNR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.chn_num = read_u2(raw_data, pos, order);
self.bit_pos = read_u4(raw_data, pos, order);
self.cell_nam = read_sn(raw_data, pos, order);
}
}
impl SSR {
#[inline(always)]
pub fn new() -> Self {
SSR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.ssr_nam = read_cn(raw_data, pos);
self.chn_cnt = read_u2(raw_data, pos, order);
self.chn_list = read_kx_u2(raw_data, pos, order, self.chn_cnt);
}
}
impl CDR {
#[inline(always)]
pub fn new() -> Self {
CDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.cdr_indx = read_u2(raw_data, pos, order);
self.chn_nam = read_cn(raw_data, pos);
self.chn_len = read_u4(raw_data, pos, order);
self.sin_pin = read_u2(raw_data, pos, order);
self.sout_pin = read_u2(raw_data, pos, order);
self.mstr_cnt = read_uint8(raw_data, pos);
self.m_clks = read_kx_u2(raw_data, pos, order, self.mstr_cnt as u16);
self.slav_cnt = read_uint8(raw_data, pos);
self.s_clks = read_kx_u2(raw_data, pos, order, self.slav_cnt as u16);
if *pos < raw_data.len() {
self.inv_val = read_uint8(raw_data, pos);
}
self.lst_cnt = read_u2(raw_data, pos, order);
self.cell_lst = read_kx_sn(raw_data, pos, order, self.lst_cnt);
}
}
impl WIR {
#[inline(always)]
pub fn new() -> Self {
WIR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.site_grp = read_uint8(raw_data, pos);
}
self.start_t = read_u4(raw_data, pos, order);
self.wafer_id = read_cn(raw_data, pos);
}
}
impl WRR {
#[inline(always)]
pub fn new() -> Self {
WRR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.site_grp = read_uint8(raw_data, pos);
}
self.finish_t = read_u4(raw_data, pos, order);
self.part_cnt = read_u4(raw_data, pos, order);
if *pos + 4 <= raw_data.len() {
self.rtst_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.abrt_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.good_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.func_cnt = read_u4(raw_data, pos, order);
}
self.wafer_id = read_cn(raw_data, pos);
self.fabwf_id = read_cn(raw_data, pos);
self.frame_id = read_cn(raw_data, pos);
self.mask_id = read_cn(raw_data, pos);
self.usr_desc = read_cn(raw_data, pos);
self.exc_desc = read_cn(raw_data, pos);
}
}
impl WCR {
#[inline(always)]
pub fn new() -> Self {
WCR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.wafr_siz = read_r4(raw_data, pos, order);
self.die_ht = read_r4(raw_data, pos, order);
self.die_wid = read_r4(raw_data, pos, order);
self.wf_units = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.wf_flat = read_uint8(raw_data, pos) as char;
}
if *pos + 2 <= raw_data.len() {
self.center_x = read_i2(raw_data, pos, order);
}
if *pos + 2 <= raw_data.len() {
self.center_y = read_i2(raw_data, pos, order);
}
if *pos < raw_data.len() {
self.pos_x = read_uint8(raw_data, pos) as char;
}
if *pos < raw_data.len() {
self.pos_y = read_uint8(raw_data, pos) as char;
}
}
}
impl PIR {
#[inline(always)]
pub fn new() -> Self {
PIR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
}
}
impl PRR {
#[inline(always)]
pub fn new() -> Self {
PRR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.part_flg = [read_uint8(raw_data, pos)];
self.num_test = read_u2(raw_data, pos, order);
self.hard_bin = read_u2(raw_data, pos, order);
if *pos + 2 <= raw_data.len() {
self.soft_bin = read_u2(raw_data, pos, order);
}
if *pos + 2 <= raw_data.len() {
self.x_coord = read_i2(raw_data, pos, order);
}
if *pos + 2 <= raw_data.len() {
self.y_coord = read_i2(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.test_t = read_u4(raw_data, pos, order);
}
self.part_id = read_cn(raw_data, pos);
self.part_txt = read_cn(raw_data, pos);
self.part_fix = read_bn(raw_data, pos);
}
}
impl TSR {
#[inline(always)]
pub fn new() -> Self {
TSR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
if *pos < raw_data.len() {
self.test_typ = read_uint8(raw_data, pos) as char;
}
self.test_num = read_u4(raw_data, pos, order);
if *pos + 4 <= raw_data.len() {
self.exec_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.fail_cnt = read_u4(raw_data, pos, order);
}
if *pos + 4 <= raw_data.len() {
self.alrm_cnt = read_u4(raw_data, pos, order);
}
self.test_nam = read_cn(raw_data, pos);
self.seq_name = read_cn(raw_data, pos);
self.test_lbl = read_cn(raw_data, pos);
self.opt_flag = [read_uint8(raw_data, pos)];
self.test_tim = read_r4(raw_data, pos, order);
self.test_min = read_r4(raw_data, pos, order);
self.test_max = read_r4(raw_data, pos, order);
self.tst_sums = read_r4(raw_data, pos, order);
self.tst_sqrs = read_r4(raw_data, pos, order);
}
}
impl PTR {
#[inline(always)]
pub fn new() -> Self {
PTR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.test_flg = [read_uint8(raw_data, pos)];
self.parm_flg = [read_uint8(raw_data, pos)];
self.result = read_r4(raw_data, pos, order);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
read_optional!(self.opt_flag, [read_uint8(raw_data, pos)], 1);
read_optional!(self.res_scal, read_i1(raw_data, pos), 1);
read_optional!(self.llm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.hlm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.lo_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.units, read_cn(raw_data, pos), 1);
read_optional!(self.c_resfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_llmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_hlmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.lo_spec, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_spec, read_r4(raw_data, pos, order), 4);
}
}
impl MPR {
#[inline(always)]
pub fn new() -> Self {
MPR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.test_flg = [read_uint8(raw_data, pos)];
self.parm_flg = [read_uint8(raw_data, pos)];
self.rtn_icnt = read_u2(raw_data, pos, order);
self.rslt_cnt = read_u2(raw_data, pos, order);
self.rtn_stat = read_kx_n1(raw_data, pos, self.rtn_icnt);
self.rtn_rslt = read_kx_r4(raw_data, pos, order, self.rslt_cnt);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
read_optional!(self.opt_flag, [read_uint8(raw_data, pos)], 1);
read_optional!(self.res_scal, read_i1(raw_data, pos), 1);
read_optional!(self.llm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.hlm_scal, read_i1(raw_data, pos), 1);
read_optional!(self.lo_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_limit, read_r4(raw_data, pos, order), 4);
read_optional!(self.start_in, read_r4(raw_data, pos, order), 4);
read_optional!(self.incr_in, read_r4(raw_data, pos, order), 4);
read_optional!(
self.rtn_indx,
read_kx_u2(raw_data, pos, order, self.rtn_icnt),
2
);
read_optional!(self.units, read_cn(raw_data, pos), 1);
read_optional!(self.units_in, read_cn(raw_data, pos), 1);
read_optional!(self.c_resfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_llmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.c_hlmfmt, read_cn(raw_data, pos), 1);
read_optional!(self.lo_spec, read_r4(raw_data, pos, order), 4);
read_optional!(self.hi_spec, read_r4(raw_data, pos, order), 4);
}
}
impl FTR {
#[inline(always)]
pub fn new() -> Self {
FTR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.test_flg = [read_uint8(raw_data, pos)];
self.opt_flag = [read_uint8(raw_data, pos)];
self.cycl_cnt = read_u4(raw_data, pos, order);
self.rel_vadr = read_u4(raw_data, pos, order);
self.rept_cnt = read_u4(raw_data, pos, order);
self.num_fail = read_u4(raw_data, pos, order);
self.xfail_ad = read_i4(raw_data, pos, order);
self.yfail_ad = read_i4(raw_data, pos, order);
self.vect_off = read_i2(raw_data, pos, order);
self.rtn_icnt = read_u2(raw_data, pos, order);
self.pgm_icnt = read_u2(raw_data, pos, order);
self.rtn_indx = read_kx_u2(raw_data, pos, order, self.rtn_icnt);
self.rtn_stat = read_kx_n1(raw_data, pos, self.rtn_icnt);
self.pgm_indx = read_kx_u2(raw_data, pos, order, self.pgm_icnt);
self.pgm_stat = read_kx_n1(raw_data, pos, self.pgm_icnt);
self.fail_pin = read_dn(raw_data, pos, order);
self.vect_nam = read_cn(raw_data, pos);
self.time_set = read_cn(raw_data, pos);
self.op_code = read_cn(raw_data, pos);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
self.prog_txt = read_cn(raw_data, pos);
self.rslt_txt = read_cn(raw_data, pos);
if *pos < raw_data.len() {
self.patg_num = read_uint8(raw_data, pos);
}
self.spin_map = read_dn(raw_data, pos, order);
}
}
impl STR {
#[inline(always)]
pub fn new() -> Self {
STR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.cont_flg = [read_uint8(raw_data, pos)];
self.test_num = read_u4(raw_data, pos, order);
self.head_num = read_uint8(raw_data, pos);
self.site_num = read_uint8(raw_data, pos);
self.psr_ref = read_u2(raw_data, pos, order);
self.test_flg = [read_uint8(raw_data, pos)];
self.log_typ = read_cn(raw_data, pos);
self.test_txt = read_cn(raw_data, pos);
self.alarm_id = read_cn(raw_data, pos);
self.prog_txt = read_cn(raw_data, pos);
self.rslt_txt = read_cn(raw_data, pos);
self.z_val = read_uint8(raw_data, pos);
self.fmu_flg = [read_uint8(raw_data, pos)];
self.mask_map = read_dn(raw_data, pos, order);
self.fal_map = read_dn(raw_data, pos, order);
self.cyc_cnt_t = read_u8(raw_data, pos, order);
self.totf_cnt = read_u4(raw_data, pos, order);
self.totl_cnt = read_u4(raw_data, pos, order);
self.cyc_base = read_u8(raw_data, pos, order);
self.bit_base = read_u4(raw_data, pos, order);
self.cond_cnt = read_u2(raw_data, pos, order);
self.lim_cnt = read_u2(raw_data, pos, order);
self.cyc_size = read_uint8(raw_data, pos);
self.pmr_size = read_uint8(raw_data, pos);
self.chn_size = read_uint8(raw_data, pos);
self.pat_size = read_uint8(raw_data, pos);
self.bit_size = read_uint8(raw_data, pos);
self.u1_size = read_uint8(raw_data, pos);
self.u2_size = read_uint8(raw_data, pos);
self.u3_size = read_uint8(raw_data, pos);
self.utx_size = read_uint8(raw_data, pos);
self.cap_bgn = read_u2(raw_data, pos, order);
self.lim_indx = read_kx_u2(raw_data, pos, order, self.lim_cnt);
self.lim_spec = read_kx_u4(raw_data, pos, order, self.lim_cnt);
self.cond_lst = read_kx_cn(raw_data, pos, self.cond_cnt);
self.cyc_cnt = read_u2(raw_data, pos, order);
self.cyc_ofst = read_kx_uf(raw_data, pos, order, self.cyc_cnt, self.cyc_size);
self.pmr_cnt = read_u2(raw_data, pos, order);
self.pmr_indx = read_kx_uf(raw_data, pos, order, self.pmr_cnt, self.pmr_size);
self.chn_cnt = read_u2(raw_data, pos, order);
self.chn_num = read_kx_uf(raw_data, pos, order, self.chn_cnt, self.chn_size);
self.exp_cnt = read_u2(raw_data, pos, order);
self.exp_data = read_kx_u1(raw_data, pos, self.exp_cnt);
self.cap_cnt = read_u2(raw_data, pos, order);
self.cap_data = read_kx_u1(raw_data, pos, self.cap_cnt);
self.new_cnt = read_u2(raw_data, pos, order);
self.new_data = read_kx_u1(raw_data, pos, self.new_cnt);
self.pat_cnt = read_u2(raw_data, pos, order);
self.pat_num = read_kx_uf(raw_data, pos, order, self.pat_cnt, self.pat_size);
self.bpos_cnt = read_u2(raw_data, pos, order);
self.bit_pos = read_kx_uf(raw_data, pos, order, self.bpos_cnt, self.bit_size);
self.usr1_cnt = read_u2(raw_data, pos, order);
self.usr1 = read_kx_uf(raw_data, pos, order, self.usr1_cnt, self.u1_size);
self.usr2_cnt = read_u2(raw_data, pos, order);
self.usr2 = read_kx_uf(raw_data, pos, order, self.usr2_cnt, self.u2_size);
self.usr3_cnt = read_u2(raw_data, pos, order);
self.usr3 = read_kx_uf(raw_data, pos, order, self.usr3_cnt, self.u3_size);
self.txt_cnt = read_u2(raw_data, pos, order);
self.user_txt = read_kx_cf(raw_data, pos, self.txt_cnt, self.utx_size);
}
}
impl BPS {
#[inline(always)]
pub fn new() -> Self {
BPS::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.seq_name = read_cn(raw_data, pos);
}
}
impl EPS {
pub fn new() -> Self {
EPS::default()
}
pub fn read_from_bytes(&mut self, _raw_data: &[u8], _order: &ByteOrder) {}
}
impl GDR {
#[inline(always)]
pub fn new() -> Self {
GDR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
let pos = &mut 0;
self.fld_cnt = read_u2(raw_data, pos, order);
self.gen_data = read_vn(raw_data, pos, order, self.fld_cnt);
}
}
impl DTR {
#[inline(always)]
pub fn new() -> Self {
DTR::default()
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.text_dat = read_cn(raw_data, pos);
}
}
impl ReservedRec {
pub fn new() -> Self {
ReservedRec::default()
}
pub fn read_from_bytes(&mut self, raw_data: &[u8], _order: &ByteOrder) {
let pos = &mut 0;
self.raw_data = read_cn(raw_data, pos);
}
}
impl StdfRecord {
#[inline(always)]
pub fn new(rec_type: u64) -> Self {
match rec_type {
stdf_record_type::REC_PTR => StdfRecord::PTR(PTR::new()),
stdf_record_type::REC_MPR => StdfRecord::MPR(MPR::new()),
stdf_record_type::REC_FTR => StdfRecord::FTR(FTR::new()),
stdf_record_type::REC_STR => StdfRecord::STR(STR::new()),
stdf_record_type::REC_PIR => StdfRecord::PIR(PIR::new()),
stdf_record_type::REC_PRR => StdfRecord::PRR(PRR::new()),
stdf_record_type::REC_WIR => StdfRecord::WIR(WIR::new()),
stdf_record_type::REC_WRR => StdfRecord::WRR(WRR::new()),
stdf_record_type::REC_WCR => StdfRecord::WCR(WCR::new()),
stdf_record_type::REC_GDR => StdfRecord::GDR(GDR::new()),
stdf_record_type::REC_DTR => StdfRecord::DTR(DTR::new()),
stdf_record_type::REC_FAR => StdfRecord::FAR(FAR::new()),
stdf_record_type::REC_ATR => StdfRecord::ATR(ATR::new()),
stdf_record_type::REC_VUR => StdfRecord::VUR(VUR::new()),
stdf_record_type::REC_MIR => StdfRecord::MIR(MIR::new()),
stdf_record_type::REC_MRR => StdfRecord::MRR(MRR::new()),
stdf_record_type::REC_PCR => StdfRecord::PCR(PCR::new()),
stdf_record_type::REC_HBR => StdfRecord::HBR(HBR::new()),
stdf_record_type::REC_SBR => StdfRecord::SBR(SBR::new()),
stdf_record_type::REC_PMR => StdfRecord::PMR(PMR::new()),
stdf_record_type::REC_PGR => StdfRecord::PGR(PGR::new()),
stdf_record_type::REC_PLR => StdfRecord::PLR(PLR::new()),
stdf_record_type::REC_RDR => StdfRecord::RDR(RDR::new()),
stdf_record_type::REC_SDR => StdfRecord::SDR(SDR::new()),
stdf_record_type::REC_PSR => StdfRecord::PSR(PSR::new()),
stdf_record_type::REC_NMR => StdfRecord::NMR(NMR::new()),
stdf_record_type::REC_CNR => StdfRecord::CNR(CNR::new()),
stdf_record_type::REC_SSR => StdfRecord::SSR(SSR::new()),
stdf_record_type::REC_CDR => StdfRecord::CDR(CDR::new()),
stdf_record_type::REC_TSR => StdfRecord::TSR(TSR::new()),
stdf_record_type::REC_BPS => StdfRecord::BPS(BPS::new()),
stdf_record_type::REC_EPS => StdfRecord::EPS(EPS::new()),
stdf_record_type::REC_RESERVE => StdfRecord::ReservedRec(ReservedRec::new()),
_ => StdfRecord::InvalidRec(RecordHeader::new()),
}
}
#[inline(always)]
pub fn get_type(&self) -> u64 {
match &self {
StdfRecord::PTR(_) => stdf_record_type::REC_PTR,
StdfRecord::MPR(_) => stdf_record_type::REC_MPR,
StdfRecord::FTR(_) => stdf_record_type::REC_FTR,
StdfRecord::STR(_) => stdf_record_type::REC_STR,
StdfRecord::PIR(_) => stdf_record_type::REC_PIR,
StdfRecord::PRR(_) => stdf_record_type::REC_PRR,
StdfRecord::WIR(_) => stdf_record_type::REC_WIR,
StdfRecord::WRR(_) => stdf_record_type::REC_WRR,
StdfRecord::WCR(_) => stdf_record_type::REC_WCR,
StdfRecord::GDR(_) => stdf_record_type::REC_GDR,
StdfRecord::DTR(_) => stdf_record_type::REC_DTR,
StdfRecord::TSR(_) => stdf_record_type::REC_TSR,
StdfRecord::MIR(_) => stdf_record_type::REC_MIR,
StdfRecord::MRR(_) => stdf_record_type::REC_MRR,
StdfRecord::PCR(_) => stdf_record_type::REC_PCR,
StdfRecord::HBR(_) => stdf_record_type::REC_HBR,
StdfRecord::SBR(_) => stdf_record_type::REC_SBR,
StdfRecord::PMR(_) => stdf_record_type::REC_PMR,
StdfRecord::PGR(_) => stdf_record_type::REC_PGR,
StdfRecord::PLR(_) => stdf_record_type::REC_PLR,
StdfRecord::RDR(_) => stdf_record_type::REC_RDR,
StdfRecord::SDR(_) => stdf_record_type::REC_SDR,
StdfRecord::PSR(_) => stdf_record_type::REC_PSR,
StdfRecord::NMR(_) => stdf_record_type::REC_NMR,
StdfRecord::CNR(_) => stdf_record_type::REC_CNR,
StdfRecord::SSR(_) => stdf_record_type::REC_SSR,
StdfRecord::CDR(_) => stdf_record_type::REC_CDR,
StdfRecord::FAR(_) => stdf_record_type::REC_FAR,
StdfRecord::ATR(_) => stdf_record_type::REC_ATR,
StdfRecord::VUR(_) => stdf_record_type::REC_VUR,
StdfRecord::BPS(_) => stdf_record_type::REC_BPS,
StdfRecord::EPS(_) => stdf_record_type::REC_EPS,
StdfRecord::ReservedRec(_) => stdf_record_type::REC_RESERVE,
StdfRecord::InvalidRec(_) => stdf_record_type::REC_INVALID,
}
}
#[inline(always)]
pub fn is_type(&self, rec_type: u64) -> bool {
(self.get_type() & rec_type) != 0
}
#[inline(always)]
pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder) {
match self {
StdfRecord::PTR(ptr_rec) => ptr_rec.read_from_bytes(raw_data, order),
StdfRecord::MPR(mpr_rec) => mpr_rec.read_from_bytes(raw_data, order),
StdfRecord::FTR(ftr_rec) => ftr_rec.read_from_bytes(raw_data, order),
StdfRecord::STR(str_rec) => str_rec.read_from_bytes(raw_data, order),
StdfRecord::PIR(pir_rec) => pir_rec.read_from_bytes(raw_data, order),
StdfRecord::PRR(prr_rec) => prr_rec.read_from_bytes(raw_data, order),
StdfRecord::WIR(wir_rec) => wir_rec.read_from_bytes(raw_data, order),
StdfRecord::WRR(wrr_rec) => wrr_rec.read_from_bytes(raw_data, order),
StdfRecord::WCR(wcr_rec) => wcr_rec.read_from_bytes(raw_data, order),
StdfRecord::GDR(gdr_rec) => gdr_rec.read_from_bytes(raw_data, order),
StdfRecord::DTR(dtr_rec) => dtr_rec.read_from_bytes(raw_data, order),
StdfRecord::TSR(tsr_rec) => tsr_rec.read_from_bytes(raw_data, order),
StdfRecord::MIR(mir_rec) => mir_rec.read_from_bytes(raw_data, order),
StdfRecord::MRR(mrr_rec) => mrr_rec.read_from_bytes(raw_data, order),
StdfRecord::PCR(pcr_rec) => pcr_rec.read_from_bytes(raw_data, order),
StdfRecord::HBR(hbr_rec) => hbr_rec.read_from_bytes(raw_data, order),
StdfRecord::SBR(sbr_rec) => sbr_rec.read_from_bytes(raw_data, order),
StdfRecord::PMR(pmr_rec) => pmr_rec.read_from_bytes(raw_data, order),
StdfRecord::PGR(pgr_rec) => pgr_rec.read_from_bytes(raw_data, order),
StdfRecord::PLR(plr_rec) => plr_rec.read_from_bytes(raw_data, order),
StdfRecord::RDR(rdr_rec) => rdr_rec.read_from_bytes(raw_data, order),
StdfRecord::SDR(sdr_rec) => sdr_rec.read_from_bytes(raw_data, order),
StdfRecord::PSR(psr_rec) => psr_rec.read_from_bytes(raw_data, order),
StdfRecord::NMR(nmr_rec) => nmr_rec.read_from_bytes(raw_data, order),
StdfRecord::CNR(cnr_rec) => cnr_rec.read_from_bytes(raw_data, order),
StdfRecord::SSR(ssr_rec) => ssr_rec.read_from_bytes(raw_data, order),
StdfRecord::CDR(cdr_rec) => cdr_rec.read_from_bytes(raw_data, order),
StdfRecord::FAR(far_rec) => far_rec.read_from_bytes(raw_data, order),
StdfRecord::ATR(atr_rec) => atr_rec.read_from_bytes(raw_data, order),
StdfRecord::VUR(vur_rec) => vur_rec.read_from_bytes(raw_data, order),
StdfRecord::BPS(bps_rec) => bps_rec.read_from_bytes(raw_data, order),
StdfRecord::EPS(eps_rec) => eps_rec.read_from_bytes(raw_data, order),
StdfRecord::ReservedRec(reserve_rec) => reserve_rec.read_from_bytes(raw_data, order),
StdfRecord::InvalidRec(_) => (),
};
}
#[inline(always)]
pub fn read_from_bytes_with_header(
raw_data: &[u8],
order: &ByteOrder,
) -> Result<StdfRecord, StdfError> {
let header = RecordHeader::new().read_from_bytes(raw_data, order)?;
let expected_end_pos = 4 + header.len as usize;
if raw_data.len() < expected_end_pos {
return Err(StdfError {
code: 5,
msg: format!(
"Length of stdf field data ({} - 4 = {}) is less than what header specified ({})",
raw_data.len(),
raw_data.len() - 4,
header.len
),
});
}
let data_slice = &raw_data[4..expected_end_pos];
let mut rec = StdfRecord::new(header.type_code);
rec.read_from_bytes(data_slice, order);
Ok(rec)
}
}
impl RawDataElement {
#[inline(always)]
pub fn is_type(&self, rec_type: u64) -> bool {
(self.type_code & rec_type) != 0
}
}
impl From<&RawDataElement> for StdfRecord {
#[inline(always)]
fn from(raw_element: &RawDataElement) -> Self {
let mut rec = StdfRecord::new(raw_element.type_code);
rec.read_from_bytes(&raw_element.raw_data, &raw_element.byte_order);
rec
}
}
impl From<RawDataElement> for StdfRecord {
#[inline(always)]
fn from(raw_element: RawDataElement) -> Self {
let mut rec = StdfRecord::new(raw_element.type_code);
rec.read_from_bytes(&raw_element.raw_data, &raw_element.byte_order);
rec
}
}
macro_rules! read_multi_byte_num {
($num_type:ty, $length:expr, $raw:ident, $pos:expr, $order:expr, $default:expr) => {{
let pos_after_read = *$pos + $length;
if pos_after_read <= $raw.len() {
let mut tmp = [0u8; $length];
tmp.copy_from_slice(&$raw[*$pos..pos_after_read]);
*$pos = pos_after_read;
match $order {
ByteOrder::LittleEndian => <$num_type>::from_le_bytes(tmp),
ByteOrder::BigEndian => <$num_type>::from_be_bytes(tmp),
}
} else {
$default
}
}};
}
macro_rules! read_multi_element {
($count:expr, $default:expr, $func:ident($($arg:tt)+)) => {
{
if $count != 0 {
let mut value = Vec::with_capacity($count as usize);
for _ in 0..$count {
value.push( $func($($arg)+) );
}
value
} else {
vec![$default; 0]
}
}
}
}
#[inline(always)]
pub(crate) fn read_uint8(raw_data: &[u8], pos: &mut usize) -> u8 {
if *pos < raw_data.len() {
let value = (*raw_data)[*pos];
*pos += 1;
value
} else {
0
}
}
#[inline(always)]
pub(crate) fn read_u2(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> U2 {
read_multi_byte_num!(U2, 2, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_u4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> U4 {
read_multi_byte_num!(U4, 4, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_u8(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> U8 {
read_multi_byte_num!(U8, 8, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_i1(raw_data: &[u8], pos: &mut usize) -> I1 {
if *pos < raw_data.len() {
let value = (*raw_data)[*pos] as I1;
*pos += 1;
value
} else {
0
}
}
#[inline(always)]
pub(crate) fn read_i2(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> I2 {
read_multi_byte_num!(I2, 2, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_i4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> I4 {
read_multi_byte_num!(I4, 4, raw_data, pos, order, 0)
}
#[inline(always)]
pub(crate) fn read_r4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> R4 {
read_multi_byte_num!(R4, 4, raw_data, pos, order, 0.0)
}
#[inline(always)]
pub(crate) fn read_r8(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> R8 {
read_multi_byte_num!(R8, 8, raw_data, pos, order, 0.0)
}
#[inline(always)]
pub(crate) fn read_cn(raw_data: &[u8], pos: &mut usize) -> Cn {
let count = read_uint8(raw_data, pos) as usize;
let mut value = String::default();
if count != 0 {
let min_pos = std::cmp::min(*pos + count, raw_data.len());
value = bytes_to_string(&raw_data[*pos..min_pos]);
*pos = min_pos;
}
value
}
#[inline(always)]
pub(crate) fn read_sn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> Sn {
let count = read_u2(raw_data, pos, order) as usize;
let mut value = String::default();
if count != 0 {
let min_pos = std::cmp::min(*pos + count, raw_data.len());
value = bytes_to_string(&raw_data[*pos..min_pos]);
*pos = min_pos;
}
value
}
#[inline(always)]
pub(crate) fn read_cf(raw_data: &[u8], pos: &mut usize, f: u8) -> Cf {
let mut value = String::default();
if f != 0 {
let pos_after_read = *pos + (f as usize);
if pos_after_read <= raw_data.len() {
value = bytes_to_string(&raw_data[*pos..pos_after_read]);
*pos = pos_after_read;
} else {
value = bytes_to_string(&raw_data[*pos..]);
*pos = raw_data.len();
}
}
value
}
#[inline(always)]
pub(crate) fn read_bn(raw_data: &[u8], pos: &mut usize) -> Bn {
let count = read_uint8(raw_data, pos) as usize;
if count != 0 {
let min_pos = std::cmp::min(*pos + count, raw_data.len());
let data_slice = &raw_data[*pos..min_pos];
*pos = min_pos;
let mut value = vec![0u8; data_slice.len()];
value.copy_from_slice(data_slice);
value
} else {
vec![0u8; 0]
}
}
#[inline(always)]
pub(crate) fn read_dn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> Dn {
let bitcount = read_u2(raw_data, pos, order) as usize;
let bytecount = bitcount / 8 + bitcount % 8;
if bytecount != 0 {
let min_pos = std::cmp::min(*pos + bytecount, raw_data.len());
let data_slice = &raw_data[*pos..min_pos];
*pos = min_pos;
let mut value = vec![0u8; data_slice.len()];
value.copy_from_slice(data_slice);
value
} else {
vec![0u8; 0]
}
}
#[inline(always)]
pub(crate) fn read_kx_cn(raw_data: &[u8], pos: &mut usize, k: u16) -> KxCn {
read_multi_element!(k, String::new(), read_cn(raw_data, pos))
}
#[inline(always)]
pub(crate) fn read_kx_sn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxSn {
read_multi_element!(k, String::new(), read_sn(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_cf(raw_data: &[u8], pos: &mut usize, k: u16, f: u8) -> KxCf {
if k != 0 {
let mut value = Vec::with_capacity(k as usize);
for _ in 0..k {
value.push(read_cf(raw_data, pos, f));
}
value
} else {
vec!["".to_string(); 0]
}
}
#[inline(always)]
pub(crate) fn read_kx_u1(raw_data: &[u8], pos: &mut usize, k: u16) -> KxU1 {
read_multi_element!(k, 0, read_uint8(raw_data, pos))
}
#[inline(always)]
pub(crate) fn read_kx_u2(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxU2 {
read_multi_element!(k, 0, read_u2(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_u4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxU4 {
read_multi_element!(k, 0, read_u4(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_u8(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxU8 {
read_multi_element!(k, 0, read_u8(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_uf(
raw_data: &[u8],
pos: &mut usize,
order: &ByteOrder,
k: u16,
f: u8,
) -> KxUf {
if k != 0 {
match f {
1 => KxUf::F1(read_kx_u1(raw_data, pos, k)),
2 => KxUf::F2(read_kx_u2(raw_data, pos, order, k)),
4 => KxUf::F4(read_kx_u4(raw_data, pos, order, k)),
8 => KxUf::F8(read_kx_u8(raw_data, pos, order, k)),
_ => KxUf::F1(vec![0u8; 0]),
}
} else {
KxUf::F1(vec![0u8; 0])
}
}
#[inline(always)]
pub(crate) fn read_kx_r4(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> KxR4 {
read_multi_element!(k, 0.0, read_r4(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn read_kx_n1(raw_data: &[u8], pos: &mut usize, k: u16) -> KxN1 {
if k != 0 {
let bytecount = k / 2 + k % 2; let mut value = Vec::with_capacity(k as usize);
for i in 0..bytecount {
let tmp = read_uint8(raw_data, pos);
value.push(tmp & 0x0F);
if (2 * i + 1) < k {
value.push((tmp & 0xF0) >> 4);
}
}
value
} else {
vec![0u8; 0]
}
}
#[inline(always)]
pub(crate) fn read_v1(raw_data: &[u8], pos: &mut usize, order: &ByteOrder) -> V1 {
let type_byte = if (*pos as usize) < raw_data.len() {
read_uint8(raw_data, pos)
} else {
0xF
};
match type_byte {
0 => V1::B0,
1 => V1::U1(read_uint8(raw_data, pos)),
2 => V1::U2(read_u2(raw_data, pos, order)),
3 => V1::U4(read_u4(raw_data, pos, order)),
4 => V1::I1(read_i1(raw_data, pos)),
5 => V1::I2(read_i2(raw_data, pos, order)),
6 => V1::I4(read_i4(raw_data, pos, order)),
7 => V1::R4(read_r4(raw_data, pos, order)),
8 => V1::R8(read_r8(raw_data, pos, order)),
10 => V1::Cn(read_cn(raw_data, pos)),
11 => V1::Bn(read_bn(raw_data, pos)),
12 => V1::Dn(read_dn(raw_data, pos, order)),
13 => V1::N1(read_uint8(raw_data, pos) & 0x0F),
_ => V1::Invalid,
}
}
#[inline(always)]
pub(crate) fn read_vn(raw_data: &[u8], pos: &mut usize, order: &ByteOrder, k: u16) -> Vn {
read_multi_element!(k, V1::Invalid, read_v1(raw_data, pos, order))
}
#[inline(always)]
pub(crate) fn bytes_to_string(data: &[u8]) -> String {
data.iter().map(|&x| x as char).collect()
}