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
use crate::core::{Handle, UndefinedStruct};
use crate::SMBiosStruct;
use serde::{ser::SerializeStruct, Serialize, Serializer};
use std::convert::TryInto;
use std::fmt;
use std::ops::Deref;

/// # Processor Information (Type 4)
///
/// The information in this structure defines the attributes of a single processor; a separate
/// structure instance is provided for each system processor socket/slot. For example, a system with an
/// IntelDX2™ processor would have a single structure instance while a system with an IntelSX2™ processor
/// would have a structure to describe the main CPU and a second structure to describe the 80487 co1021 processor.
///
/// NOTE One structure is provided for each processor instance in a system. For example, a system that supports up
/// to two processors includes two Processor Information structures — even if only one processor is currently
/// installed. Software that interprets the SMBIOS information can count the Processor Information structures to
/// determine the maximum possible configuration of the system.
///
/// Compliant with:
/// DMTF SMBIOS Reference Specification 3.4.0 (DSP0134)
/// Document Date: 2020-07-17
pub struct SMBiosProcessorInformation<'a> {
    parts: &'a UndefinedStruct,
}

impl<'a> SMBiosStruct<'a> for SMBiosProcessorInformation<'a> {
    const STRUCT_TYPE: u8 = 4u8;

    fn new(parts: &'a UndefinedStruct) -> Self {
        Self { parts }
    }

    fn parts(&self) -> &'a UndefinedStruct {
        self.parts
    }
}

impl<'a> SMBiosProcessorInformation<'a> {
    /// Socket reference designation
    ///
    /// EXAMPLE: "J202"
    pub fn socket_designation(&self) -> Option<String> {
        self.parts.get_field_string(0x04)
    }

    /// Processor type
    pub fn processor_type(&self) -> Option<ProcessorTypeData> {
        self.parts
            .get_field_byte(0x05)
            .map(|raw| ProcessorTypeData::from(raw))
    }

    /// Processor family
    pub fn processor_family(&self) -> Option<ProcessorFamilyData> {
        self.parts
            .get_field_byte(0x06)
            .map(|raw| ProcessorFamilyData::from(raw))
    }

    /// Processor manufacturer
    pub fn processor_manufacturer(&self) -> Option<String> {
        self.parts.get_field_string(0x07)
    }

    /// Raw processor identification data
    pub fn processor_id(&self) -> Option<&[u8; 8]> {
        // Note: There are two more levels to the design of ProcessorId to consider.
        // 1. These 8 bytes can represent one of 4 classes of processor (see 7.5.3)
        //    perhaps return an enum with 4 variants.
        // 2. Per variant the data represents specific Id information which can be
        //    accomodated in specific representative structures.
        self.parts
            .get_field_data(0x08, 0x10)
            .map(|raw| raw.try_into().expect("incorrect length"))
    }

    /// Processor version
    pub fn processor_version(&self) -> Option<String> {
        self.parts.get_field_string(0x10)
    }

    /// Voltage
    pub fn voltage(&self) -> Option<ProcessorVoltage> {
        self.parts
            .get_field_byte(0x11)
            .map(|raw| ProcessorVoltage::from(raw))
    }

    /// External clock frequency, in MHz
    ///
    /// If the value is unknown, the field is set to 0.
    pub fn external_clock(&self) -> Option<ProcessorExternalClock> {
        self.parts
            .get_field_word(0x12)
            .map(|raw| ProcessorExternalClock::from(raw))
    }

    /// Maximum processor speed (in MHz) supported
    /// by the system for this processor socket
    ///
    /// 0E9h is for a 233 MHz processor.
    ///
    /// NOTE: This field identifies a capability for the system,
    /// not the processor itself.
    pub fn max_speed(&self) -> Option<ProcessorSpeed> {
        self.parts
            .get_field_word(0x14)
            .map(|raw| ProcessorSpeed::from(raw))
    }

    /// Current speed
    ///
    /// Same format as Max Speed
    ///
    /// NOTE: This field identifies the processor's speed at
    /// system boot; the processor may support
    /// more than one speed.
    pub fn current_speed(&self) -> Option<ProcessorSpeed> {
        self.parts
            .get_field_word(0x16)
            .map(|raw| ProcessorSpeed::from(raw))
    }

    /// Status bit field
    pub fn status(&self) -> Option<ProcessorStatus> {
        self.parts
            .get_field_byte(0x18)
            .map(|raw| ProcessorStatus::from(raw))
    }

    /// Processor upgrade
    pub fn processor_upgrade(&self) -> Option<ProcessorUpgradeData> {
        self.parts
            .get_field_byte(0x19)
            .map(|raw| ProcessorUpgradeData::from(raw))
    }

    /// Handle of a [SMBiosCacheInformation] structure that
    /// defines the attributes of the primary (Level 1)
    /// cache for this processor
    ///
    /// For version 2.1 and version 2.2
    /// implementations, the value is 0FFFFh if the
    /// processor has no L1 cache. For version 2.3 and
    /// later implementations, the value is 0FFFFh if
    /// the Cache Information structure is not provided.
    pub fn l1cache_handle(&self) -> Option<Handle> {
        self.parts.get_field_handle(0x1A)
    }

    /// Handle of a [SMBiosCacheInformation] structure that
    /// defines the attributes of the primary (Level 2)
    /// cache for this processor
    ///
    /// For version 2.1 and version 2.2
    /// implementations, the value is 0FFFFh if the
    /// processor has no L2 cache. For version 2.3 and
    /// later implementations, the value is 0FFFFh if
    /// the Cache Information structure is not provided.
    pub fn l2cache_handle(&self) -> Option<Handle> {
        self.parts.get_field_handle(0x1C)
    }

    /// Handle of a [SMBiosCacheInformation] structure that
    /// defines the attributes of the primary (Level 3)
    /// cache for this processor
    ///
    /// For version 2.1 and version 2.2
    /// implementations, the value is 0FFFFh if the
    /// processor has no L3 cache. For version 2.3 and
    /// later implementations, the value is 0FFFFh if
    /// the Cache Information structure is not provided.
    pub fn l3cache_handle(&self) -> Option<Handle> {
        self.parts.get_field_handle(0x1E)
    }

    /// The serial number of this processor
    ///
    /// This value is set by the manufacturer and
    /// normally not changeable.
    pub fn serial_number(&self) -> Option<String> {
        self.parts.get_field_string(0x20)
    }

    /// The asset tag of this processor
    pub fn asset_tag(&self) -> Option<String> {
        self.parts.get_field_string(0x21)
    }

    /// The part number of this processor
    ///
    /// This value is set by the manufacturer and
    /// normally not changeable.
    pub fn part_number(&self) -> Option<String> {
        self.parts.get_field_string(0x22)
    }

    /// Number of cores per processor socket
    ///
    /// For core counts of 256 or greater, the
    /// 'core_count_2' field is set to the number of cores.
    pub fn core_count(&self) -> Option<CoreCount> {
        self.parts
            .get_field_byte(0x23)
            .map(|raw| CoreCount::from(raw))
    }

    /// Number of enabled cores per processor socket
    ///
    /// For core counts of 256 or greater, the
    /// 'cores_enabled_2' field is set to the number of enabled
    /// cores.
    pub fn cores_enabled(&self) -> Option<CoresEnabled> {
        self.parts
            .get_field_byte(0x24)
            .map(|raw| CoresEnabled::from(raw))
    }

    /// Number of threads per processor socket
    ///
    /// For thread counts of 256 or greater,
    /// 'thread_count_2' field is set to the number of
    /// threads.
    pub fn thread_count(&self) -> Option<ThreadCount> {
        self.parts
            .get_field_byte(0x25)
            .map(|raw| ThreadCount::from(raw))
    }

    /// Defines which functions the processor supports
    pub fn processor_characteristics(&self) -> Option<ProcessorCharacteristics> {
        self.parts
            .get_field_word(0x26)
            .map(|raw| ProcessorCharacteristics::from(raw))
    }

    /// Processor family 2
    pub fn processor_family_2(&self) -> Option<ProcessorFamilyData2> {
        self.parts
            .get_field_word(0x28)
            .map(|raw| ProcessorFamilyData2::from(raw))
    }

    /// Number of Cores per processor socket.
    ///
    /// Supports core counts >255. If this field is
    /// present, it holds the core count for the
    /// processor socket. 'core_count' will also hold the
    /// core count, except for core counts that are 256
    /// or greater. In that case, 'core_count' shall be set
    /// to 'CoreCount::SeeCoreCount2' and 'core_count_2' will hold the count.
    pub fn core_count_2(&self) -> Option<CoreCount2> {
        self.parts
            .get_field_word(0x2A)
            .map(|raw| CoreCount2::from(raw))
    }

    /// Number of enabled cores per processor socket.
    ///
    /// Supports core enabled counts >255. If this field
    /// is present, it holds the core enabled count for
    /// the processor socket. 'cores_enabled' will also
    /// hold the core enabled count, except for core
    /// counts that are 256 or greater. In that case,
    /// 'cores_enabled' shall be set to 'CoresEnabled::SeeCoresEnabled2'
    /// and 'cores_enabled_2' will hold the count.
    pub fn cores_enabled_2(&self) -> Option<CoresEnabled2> {
        self.parts
            .get_field_word(0x2C)
            .map(|raw| CoresEnabled2::from(raw))
    }

    /// Number of threads per processor socket.
    ///
    /// Supports thread counts >255. If this field is
    /// present, it holds the thread count for the
    /// processor socket. 'thread_count' will also hold
    /// the thread count, except for thread counts that
    /// are 256 or greater. In that case, 'thread_count'
    /// shall be set to 'ThreadCount::SeeThreadCount2'
    /// and 'thread_count_2' will hold the count.
    pub fn thread_count_2(&self) -> Option<ThreadCount2> {
        self.parts
            .get_field_word(0x2E)
            .map(|raw| ThreadCount2::from(raw))
    }
}

impl fmt::Debug for SMBiosProcessorInformation<'_> {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<SMBiosProcessorInformation<'_>>())
            .field("header", &self.parts.header)
            .field("socket_designation", &self.socket_designation())
            .field("processor_type", &self.processor_type())
            .field("processor_family", &self.processor_family())
            .field("processor_manufacturer", &self.processor_manufacturer())
            .field("processor_id", &self.processor_id())
            .field("processor_version", &self.processor_version())
            .field("voltage", &self.voltage())
            .field("external_clock", &self.external_clock())
            .field("max_speed", &self.max_speed())
            .field("current_speed", &self.current_speed())
            .field("status", &self.status())
            .field("processor_upgrade", &self.processor_upgrade())
            .field("l1cache_handle", &self.l1cache_handle())
            .field("l2cache_handle", &self.l2cache_handle())
            .field("l3cache_handle", &self.l3cache_handle())
            .field("serial_number", &self.serial_number())
            .field("asset_tag", &self.asset_tag())
            .field("part_number", &self.part_number())
            .field("core_count", &self.core_count())
            .field("cores_enabled", &self.cores_enabled())
            .field("thread_count", &self.thread_count())
            .field(
                "processor_characteristics",
                &self.processor_characteristics(),
            )
            .field("processor_family_2", &self.processor_family_2())
            .field("core_count_2", &self.core_count_2())
            .field("cores_enabled_2", &self.cores_enabled_2())
            .field("thread_count_2", &self.thread_count_2())
            .finish()
    }
}

impl Serialize for SMBiosProcessorInformation<'_> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("SMBiosProcessorInformation", 27)?;
        state.serialize_field("header", &self.parts.header)?;
        state.serialize_field("socket_designation", &self.socket_designation())?;
        state.serialize_field("processor_type", &self.processor_type())?;
        state.serialize_field("processor_family", &self.processor_family())?;
        state.serialize_field("processor_manufacturer", &self.processor_manufacturer())?;
        state.serialize_field("processor_id", &self.processor_id())?;
        state.serialize_field("processor_version", &self.processor_version())?;
        state.serialize_field("voltage", &self.voltage())?;
        state.serialize_field("external_clock", &self.external_clock())?;
        state.serialize_field("max_speed", &self.max_speed())?;
        state.serialize_field("current_speed", &self.current_speed())?;
        state.serialize_field("status", &self.status())?;
        state.serialize_field("processor_upgrade", &self.processor_upgrade())?;
        state.serialize_field("l1cache_handle", &self.l1cache_handle())?;
        state.serialize_field("l2cache_handle", &self.l2cache_handle())?;
        state.serialize_field("l3cache_handle", &self.l3cache_handle())?;
        state.serialize_field("serial_number", &self.serial_number())?;
        state.serialize_field("asset_tag", &self.asset_tag())?;
        state.serialize_field("part_number", &self.part_number())?;
        state.serialize_field("core_count", &self.core_count())?;
        state.serialize_field("cores_enabled", &self.cores_enabled())?;
        state.serialize_field("thread_count", &self.thread_count())?;
        state.serialize_field(
            "processor_characteristics",
            &self.processor_characteristics(),
        )?;
        state.serialize_field("processor_family_2", &self.processor_family_2())?;
        state.serialize_field("core_count_2", &self.core_count_2())?;
        state.serialize_field("cores_enabled_2", &self.cores_enabled_2())?;
        state.serialize_field("thread_count_2", &self.thread_count_2())?;
        state.end()
    }
}

/// # Processor Type Data
pub struct ProcessorTypeData {
    /// Raw value
    ///
    /// _raw_ is most useful when _value_ is None.
    /// This is most likely to occur when the standard was updated but
    /// this library code has not been updated to match the current
    /// standard.
    pub raw: u8,
    /// The contained [ProcessorType] value
    pub value: ProcessorType,
}

impl fmt::Debug for ProcessorTypeData {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorTypeData>())
            .field("raw", &self.raw)
            .field("value", &self.value)
            .finish()
    }
}

impl Serialize for ProcessorTypeData {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorTypeData", 2)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("value", &self.value)?;
        state.end()
    }
}

impl fmt::Display for ProcessorTypeData {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self.value {
            ProcessorType::None => write!(f, "{}", &self.raw),
            _ => write!(f, "{:?}", &self.value),
        }
    }
}

impl Deref for ProcessorTypeData {
    type Target = ProcessorType;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

/// # Processor Type
#[derive(Serialize, Debug, PartialEq, Eq)]
pub enum ProcessorType {
    /// Other
    Other,
    /// Unknown
    Unknown,
    /// Central Processor
    CentralProcessor,
    /// Math Processor
    MathProcessor,
    /// DSP Processor
    DspProcessor,
    /// Video Processor
    VideoProcessor,
    /// A value unknown to this standard, check the raw value
    None,
}

impl From<u8> for ProcessorTypeData {
    fn from(raw: u8) -> Self {
        ProcessorTypeData {
            value: match raw {
                0x01 => ProcessorType::Other,
                0x02 => ProcessorType::Unknown,
                0x03 => ProcessorType::CentralProcessor,
                0x04 => ProcessorType::MathProcessor,
                0x05 => ProcessorType::DspProcessor,
                0x06 => ProcessorType::VideoProcessor,
                _ => ProcessorType::None,
            },
            raw,
        }
    }
}

/// # Processor Family Data
pub struct ProcessorFamilyData {
    /// Raw value
    ///
    /// _raw_ is most useful when _value_ is None.
    /// This is most likely to occur when the standard was updated but
    /// this library code has not been updated to match the current
    /// standard.
    pub raw: u8,
    /// The contained [ProcessorFamily] value
    pub value: ProcessorFamily,
}

impl fmt::Debug for ProcessorFamilyData {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorFamilyData>())
            .field("raw", &self.raw)
            .field("value", &self.value)
            .finish()
    }
}

impl Serialize for ProcessorFamilyData {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorFamilyData", 2)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("value", &self.value)?;
        state.end()
    }
}

impl fmt::Display for ProcessorFamilyData {
    /// Displays ProcessorFamily either by name or as a hex value if the name for the value is unknown.
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self.value {
            ProcessorFamily::None => write!(f, "{:#X}", &self.raw),
            _ => write!(f, "{:?}", &self.value),
        }
    }
}

impl Deref for ProcessorFamilyData {
    type Target = ProcessorFamily;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

impl From<u8> for ProcessorFamilyData {
    fn from(raw: u8) -> Self {
        ProcessorFamilyData {
            value: ProcessorFamily::from(raw as u16),
            raw,
        }
    }
}

/// # Processor Family Data #2
pub struct ProcessorFamilyData2 {
    /// Raw value
    ///
    /// _raw_ is most useful when _value_ is None.
    /// This is most likely to occur when the standard was updated but
    /// this library code has not been updated to match the current
    /// standard.
    pub raw: u16,
    /// The contained [ProcessorFamily] value
    pub value: ProcessorFamily,
}

impl fmt::Debug for ProcessorFamilyData2 {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorFamilyData2>())
            .field("raw", &self.raw)
            .field("value", &self.value)
            .finish()
    }
}

impl Serialize for ProcessorFamilyData2 {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorFamilyData2", 2)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("value", &self.value)?;
        state.end()
    }
}

impl fmt::Display for ProcessorFamilyData2 {
    /// Displays ProcessorFamily either by name or as a hex value if the name for the value is unknown.
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self.value {
            ProcessorFamily::None => write!(f, "{:#X}", &self.raw),
            _ => write!(f, "{:?}", &self.value),
        }
    }
}

impl Deref for ProcessorFamilyData2 {
    type Target = ProcessorFamily;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

impl From<u16> for ProcessorFamilyData2 {
    fn from(raw: u16) -> Self {
        ProcessorFamilyData2 {
            value: ProcessorFamily::from(raw),
            raw,
        }
    }
}
/// # Processor Family
#[derive(Serialize, Debug, PartialEq, Eq)]
pub enum ProcessorFamily {
    /// Other
    Other,
    /// Unknown
    Unknown,
    /// 8086
    I8086,
    /// 80286
    I80286,
    /// Intel386™ processor
    Intel386Processor,
    /// Intel486™ processor
    Intel486Processor,
    /// 8087
    I8087,
    /// 80287
    I80287,
    /// 80387
    I80387,
    /// 80487
    I80487,
    /// Intel® Pentium® processor
    IntelPentiumProcessor,
    /// Pentium® Pro processor
    PentiumProProcessor,
    /// Pentium® II processor
    PentiumIIProcessor,
    /// Pentium® processor with MMX™ technology
    PentiumprocessorwithMMXtechnology,
    /// Intel® Celeron® processor
    IntelCeleronProcessor,
    /// Pentium® II Xeon™ processor
    PentiumIIXeonProcessor,
    /// Pentium® III processor
    PentiumIIIProcessor,
    /// M1 Family
    M1Family,
    /// M2 Family
    M2Family,
    /// Intel® Celeron® M processor
    IntelCeleronMProcessor,
    /// Intel® Pentium® 4 HT processor
    IntelPentium4HTProcessor,
    /// AMD Duron™ Processor Family
    AMDDuronProcessorFamily,
    /// K5 Family
    K5Family,
    /// K6 Family
    K6Family,
    /// K6-2
    K62,
    /// K6-3
    K63,
    /// AMD Athlon™ Processor Family
    AMDAthlonProcessorFamily,
    /// AMD29000 Family
    AMD29000Family,
    /// K6-2+
    K62Plus,
    /// Power PC Family
    PowerPCFamily,
    /// Power PC 601
    PowerPC601,
    /// Power PC 603
    PowerPC603,
    /// Power PC 603+
    PowerPC603Plus,
    /// Power PC 604
    PowerPC604,
    /// Power PC 620
    PowerPC620,
    /// Power PC x704
    PowerPCx704,
    /// Power PC 750
    PowerPC750,
    /// Intel® Core™ Duo processor
    IntelCoreDuoProcessor,
    /// Intel® Core™ Duo mobile processor
    IntelCoreDuomobileProcessor,
    /// Intel® Core™ Solo mobile processor
    IntelCoreSolomobileProcessor,
    /// Intel® Atom™ processor
    IntelAtomProcessor,
    /// Intel® Core™ M processor
    IntelCoreMProcessor,
    /// Intel(R) Core(TM) m3 processor
    IntelCorem3Processor,
    /// Intel(R) Core(TM) m5 processor
    IntelCorem5Processor,
    /// Intel(R) Core(TM) m7 processor
    IntelCorem7Processor,
    /// Alpha Family
    AlphaFamily,
    /// Alpha 21064
    Alpha21064,
    /// Alpha 21066
    Alpha21066,
    /// Alpha 21164
    Alpha21164,
    /// Alpha 21164PC
    Alpha21164PC,
    /// Alpha 21164a
    Alpha21164a,
    /// Alpha 21264
    Alpha21264,
    /// Alpha 21364
    Alpha21364,
    /// AMD Turion™ II Ultra Dual-Core Mobile M Processor Family
    AMDTurionIIUltraDualCoreMobileMProcessorFamily,
    /// AMD Turion™ II Dual-Core Mobile M Processor Family
    AMDTurionIIDualCoreMobileMProcessorFamily,
    /// AMD Athlon™ II Dual-Core M Processor Family
    AMDAthlonIIDualCoreMProcessorFamily,
    /// AMD Opteron™ 6100 Series Processor
    AMDOpteron6100SeriesProcessor,
    /// AMD Opteron™ 4100 Series Processor
    AMDOpteron4100SeriesProcessor,
    /// AMD Opteron™ 6200 Series Processor
    AMDOpteron6200SeriesProcessor,
    /// AMD Opteron™ 4200 Series Processor
    AMDOpteron4200SeriesProcessor,
    /// AMD FX™ Series Processor
    AMDFXSeriesProcessor,
    /// MIPS Family
    MIPSFamily,
    /// MIPS R4000
    MIPSR4000,
    /// MIPS R4200
    MIPSR4200,
    /// MIPS R4400
    MIPSR4400,
    /// MIPS R4600
    MIPSR4600,
    /// MIPS R10000
    MIPSR10000,
    /// AMD C-Series Processor
    AMDCSeriesProcessor,
    /// AMD E-Series Processor
    AMDESeriesProcessor,
    /// AMD A-Series Processor
    AMDASeriesProcessor,
    /// AMD G-Series Processor
    AMDGSeriesProcessor,
    /// AMD Z-Series Processor
    AMDZSeriesProcessor,
    /// AMD R-Series Processor
    AMDRSeriesProcessor,
    /// AMD Opteron™ 4300 Series Processor
    AMDOpteron4300SeriesProcessor,
    /// AMD Opteron™ 6300 Series Processor
    AMDOpteron6300SeriesProcessor,
    /// AMD Opteron™ 3300 Series Processor
    AMDOpteron3300SeriesProcessor,
    /// AMD FirePro™ Series Processor
    AMDFireProSeriesProcessor,
    /// SPARC Family
    SPARCFamily,
    /// SuperSPARC
    SuperSPARC,
    /// microSPARC II
    MicroSparcii,
    /// microSPARC IIep
    MicroSparciiep,
    /// UltraSPARC
    UltraSPARC,
    /// UltraSPARC II
    UltraSPARCII,
    /// UltraSPARC Iii
    UltraSPARCIii,
    /// UltraSPARC III
    UltraSPARCIII,
    /// UltraSPARC IIIi
    UltraSPARCIIIi,
    /// 68040 Family
    M68040Family,
    /// 68xxx
    M68xxx,
    /// 68000
    M68000,
    /// 68010
    M68010,
    /// 68020
    M68020,
    /// 68030
    M68030,
    /// AMD Athlon(TM) X4 Quad-Core Processor Family
    AMDAthlonX4QuadCoreProcessorFamily,
    /// AMD Opteron(TM) X1000 Series Processor
    AMDOpteronX1000SeriesProcessor,
    /// AMD Opteron(TM) X2000 Series APU
    AMDOpteronX2000SeriesAPU,
    /// AMD Opteron(TM) A-Series Processor
    AMDOpteronASeriesProcessor,
    /// AMD Opteron(TM) X3000 Series APU
    AMDOpteronX3000SeriesAPU,
    /// AMD Zen Processor Family
    AMDZenProcessorFamily,
    /// Hobbit Family
    HobbitFamily,
    /// Crusoe™ TM5000 Family
    CrusoeTM5000Family,
    /// Crusoe™ TM3000 Family
    CrusoeTM3000Family,
    /// Efficeon™ TM8000 Family
    EfficeonTM8000Family,
    /// Weitek
    Weitek,
    /// Itanium™ processor
    Itaniumprocessor,
    /// AMD Athlon™ 64 Processor Family
    AMDAthlon64ProcessorFamily,
    /// AMD Opteron™ Processor Family
    AMDOpteronProcessorFamily,
    /// AMD Sempron™ Processor Family
    AMDSempronProcessorFamily,
    /// AMD Turion™ 64 Mobile Technology
    AMDTurion64MobileTechnology,
    /// Dual-Core AMD Opteron™ Processor Family
    DualCoreAMDOpteronProcessorFamily,
    /// AMD Athlon™ 64 X2 Dual-Core Processor Family
    AMDAthlon64X2DualCoreProcessorFamily,
    /// AMD Turion™ 64 X2 Mobile Technology
    AMDTurion64X2MobileTechnology,
    /// Quad-Core AMD Opteron™ Processor Family
    QuadCoreAMDOpteronProcessorFamily,
    /// Third-Generation AMD Opteron™ Processor Family
    ThirdGenerationAMDOpteronProcessorFamily,
    /// AMD Phenom™ FX Quad-Core Processor Family
    AMDPhenomFXQuadCoreProcessorFamily,
    /// AMD Phenom™ X4 Quad-Core Processor Family
    AMDPhenomX4QuadCoreProcessorFamily,
    /// AMD Phenom™ X2 Dual-Core Processor Family
    AMDPhenomX2DualCoreProcessorFamily,
    /// AMD Athlon™ X2 Dual-Core Processor Family
    AMDAthlonX2DualCoreProcessorFamily,
    /// PA-RISC Family
    PARISCFamily,
    /// PA-RISC 8500
    PARISC8500,
    /// PA-RISC 8000
    PARISC8000,
    /// PA-RISC 7300LC
    PARISC7300LC,
    /// PA-RISC 7200
    PARISC7200,
    /// PA-RISC 7100LC
    PARISC7100LC,
    /// PA-RISC 7100
    PARISC7100,
    /// V30 Family
    V30Family,
    /// Quad-Core Intel® Xeon® processor 3200 Series
    QuadCoreIntelXeonProcessor3200Series,
    /// Dual-Core Intel® Xeon® processor 3000 Series
    DualCoreIntelXeonProcessor3000Series,
    /// Quad-Core Intel® Xeon® processor 5300 Series
    QuadCoreIntelXeonProcessor5300Series,
    /// Dual-Core Intel® Xeon® processor 5100 Series
    DualCoreIntelXeonProcessor5100Series,
    /// Dual-Core Intel® Xeon® processor 5000 Series
    DualCoreIntelXeonProcessor5000Series,
    /// Dual-Core Intel® Xeon® processor LV
    DualCoreIntelXeonProcessorLV,
    /// Dual-Core Intel® Xeon® processor ULV
    DualCoreIntelXeonProcessorULV,
    /// Dual-Core Intel® Xeon® processor 7100 Series
    DualCoreIntelXeonProcessor7100Series,
    /// Quad-Core Intel® Xeon® processor 5400 Series
    QuadCoreIntelXeonProcessor5400Series,
    /// Quad-Core Intel® Xeon® processor
    QuadCoreIntelXeonProcessor,
    /// Dual-Core Intel® Xeon® processor 5200 Series
    DualCoreIntelXeonProcessor5200Series,
    /// Dual-Core Intel® Xeon® processor 7200 Series
    DualCoreIntelXeonProcessor7200Series,
    /// Quad-Core Intel® Xeon® processor 7300 Series
    QuadCoreIntelXeonProcessor7300Series,
    /// Quad-Core Intel® Xeon® processor 7400 Series
    QuadCoreIntelXeonProcessor7400Series,
    /// Multi-Core Intel® Xeon® processor 7400 Series
    MultiCoreIntelXeonProcessor7400Series,
    /// Pentium® III Xeon™ processor
    PentiumIIIXeonProcessor,
    /// Pentium® III Processor with Intel® SpeedStep™ Technology
    PentiumIIIProcessorwithIntelSpeedStepTechnology,
    /// Pentium® 4 Processor
    Pentium4Processor,
    /// Intel® Xeon® processor
    IntelXeonProcessor,
    /// AS400 Family
    AS400Family,
    /// Intel® Xeon™ processor MP
    IntelXeonProcessorMP,
    /// AMD Athlon™ XP Processor Family
    AMDAthlonXPProcessorFamily,
    /// AMD Athlon™ MP Processor Family
    AMDAthlonMPProcessorFamily,
    /// Intel® Itanium® 2 processor
    IntelItanium2Processor,
    /// Intel® Pentium® M processor
    IntelPentiumMProcessor,
    /// Intel® Celeron® D processor
    IntelCeleronDProcessor,
    /// Intel® Pentium® D processor
    IntelPentiumDProcessor,
    /// Intel® Pentium® Processor Extreme Edition
    IntelPentiumProcessorExtremeEdition,
    /// Intel® Core™ Solo Processor
    IntelCoreSoloProcessor,
    /// Intel® Core™ 2 Duo Processor
    IntelCore2DuoProcessor,
    /// Intel® Core™ 2 Solo processor
    IntelCore2SoloProcessor,
    /// Intel® Core™ 2 Extreme processor
    IntelCore2ExtremeProcessor,
    /// Intel® Core™ 2 Quad processor
    IntelCore2QuadProcessor,
    /// Intel® Core™ 2 Extreme mobile processor
    IntelCore2ExtremeMobileProcessor,
    /// Intel® Core™ 2 Duo mobile processor
    IntelCore2DuoMobileProcessor,
    /// Intel® Core™ 2 Solo mobile processor
    IntelCore2SoloMobileProcessor,
    /// Intel® Core™ i7 processor
    IntelCorei7Processor,
    /// Dual-Core Intel® Celeron® processor
    DualCoreIntelCeleronProcessor,
    /// IBM390 Family
    IBM390Family,
    /// G4
    G4,
    /// G5
    G5,
    /// ESA/390 G6
    ESA390G6,
    /// z/Architecture base
    ZArchitecturebase,
    /// Intel® Core™ i5 processor
    IntelCorei5processor,
    /// Intel® Core™ i3 processor
    IntelCorei3processor,
    /// Intel® Core™ i9 processor
    IntelCorei9processor,
    /// VIA C7™-M Processor Family
    VIAC7MProcessorFamily,
    /// VIA C7™-D Processor Family
    VIAC7DProcessorFamily,
    /// VIA C7™ Processor Family
    VIAC7ProcessorFamily,
    /// VIA Eden™ Processor Family
    VIAEdenProcessorFamily,
    /// Multi-Core Intel® Xeon® processor
    MultiCoreIntelXeonProcessor,
    /// Dual-Core Intel® Xeon® processor 3xxx Series
    DualCoreIntelXeonProcessor3xxxSeries,
    /// Quad-Core Intel® Xeon® processor 3xxx Series
    QuadCoreIntelXeonProcessor3xxxSeries,
    /// VIA Nano™ Processor Family
    VIANanoProcessorFamily,
    /// Dual-Core Intel® Xeon® processor 5xxx Series
    DualCoreIntelXeonProcessor5xxxSeries,
    /// Quad-Core Intel® Xeon® processor 5xxx Series
    QuadCoreIntelXeonProcessor5xxxSeries,
    /// Dual-Core Intel® Xeon® processor 7xxx Series
    DualCoreIntelXeonProcessor7xxxSeries,
    /// Quad-Core Intel® Xeon® processor 7xxx Series
    QuadCoreIntelXeonProcessor7xxxSeries,
    /// Multi-Core Intel® Xeon® processor 7xxx Series
    MultiCoreIntelXeonProcessor7xxxSeries,
    /// Multi-Core Intel® Xeon® processor 3400 Series
    MultiCoreIntelXeonProcessor3400Series,
    /// AMD Opteron™ 3000 Series Processor
    AMDOpteron3000SeriesProcessor,
    /// AMD Sempron™ II Processor
    AMDSempronIIProcessor,
    /// Embedded AMD Opteron™ Quad-Core Processor Family
    EmbeddedAMDOpteronQuadCoreProcessorFamily,
    /// AMD Phenom™ Triple-Core Processor Family
    AMDPhenomTripleCoreProcessorFamily,
    /// AMD Turion™ Ultra Dual-Core Mobile Processor Family
    AMDTurionUltraDualCoreMobileProcessorFamily,
    /// AMD Turion™ Dual-Core Mobile Processor Family
    AMDTurionDualCoreMobileProcessorFamily,
    /// AMD Athlon™ Dual-Core Processor Family
    AMDAthlonDualCoreProcessorFamily,
    /// AMD Sempron™ SI Processor Family
    AMDSempronSIProcessorFamily,
    /// AMD Phenom™ II Processor Family
    AMDPhenomIIProcessorFamily,
    /// AMD Athlon™ II Processor Family
    AMDAthlonIIProcessorFamily,
    /// Six-Core AMD Opteron™ Processor Family
    SixCoreAMDOpteronProcessorFamily,
    /// AMD Sempron™ M Processor Family
    AMDSempronMProcessorFamily,
    /// i860
    I860,
    /// i960
    I960,
    /// Indicator to obtain the processor family from the 'processor_family_2' field
    SeeProcessorFamily2,
    /// ARMv7
    ARMv7,
    /// ARMv8
    ARMv8,
    /// SH-3
    SH3,
    /// SH-4
    SH4,
    /// ARM
    ARM,
    /// StrongARM
    StrongARM,
    /// 6x86
    Cyrix6x86,
    /// MediaGX
    MediaGX,
    /// MII
    MII,
    /// WinChip
    WinChip,
    /// DSP
    DSP,
    /// Video Processor
    VideoProcessor,
    /// RISC-V RV32
    RISCVRV32,
    /// RISC-V RV64
    RISCVRV64,
    /// RISC-V RV128
    RISCVRV128,
    /// A value unknown to this standard, check the raw value
    None,
}

impl From<u16> for ProcessorFamily {
    fn from(raw: u16) -> Self {
        match raw {
            0x01 => ProcessorFamily::Other,
            0x02 => ProcessorFamily::Unknown,
            0x03 => ProcessorFamily::I8086,
            0x04 => ProcessorFamily::I80286,
            0x05 => ProcessorFamily::Intel386Processor,
            0x06 => ProcessorFamily::Intel486Processor,
            0x07 => ProcessorFamily::I8087,
            0x08 => ProcessorFamily::I80287,
            0x09 => ProcessorFamily::I80387,
            0x0A => ProcessorFamily::I80487,
            0x0B => ProcessorFamily::IntelPentiumProcessor,
            0x0C => ProcessorFamily::PentiumProProcessor,
            0x0D => ProcessorFamily::PentiumIIProcessor,
            0x0E => ProcessorFamily::PentiumprocessorwithMMXtechnology,
            0x0F => ProcessorFamily::IntelCeleronProcessor,
            0x10 => ProcessorFamily::PentiumIIXeonProcessor,
            0x11 => ProcessorFamily::PentiumIIIProcessor,
            0x12 => ProcessorFamily::M1Family,
            0x13 => ProcessorFamily::M2Family,
            0x14 => ProcessorFamily::IntelCeleronMProcessor,
            0x15 => ProcessorFamily::IntelPentium4HTProcessor,
            0x18 => ProcessorFamily::AMDDuronProcessorFamily,
            0x19 => ProcessorFamily::K5Family,
            0x1A => ProcessorFamily::K6Family,
            0x1B => ProcessorFamily::K62,
            0x1C => ProcessorFamily::K63,
            0x1D => ProcessorFamily::AMDAthlonProcessorFamily,
            0x1E => ProcessorFamily::AMD29000Family,
            0x1F => ProcessorFamily::K62Plus,
            0x20 => ProcessorFamily::PowerPCFamily,
            0x21 => ProcessorFamily::PowerPC601,
            0x22 => ProcessorFamily::PowerPC603,
            0x23 => ProcessorFamily::PowerPC603Plus,
            0x24 => ProcessorFamily::PowerPC604,
            0x25 => ProcessorFamily::PowerPC620,
            0x26 => ProcessorFamily::PowerPCx704,
            0x27 => ProcessorFamily::PowerPC750,
            0x28 => ProcessorFamily::IntelCoreDuoProcessor,
            0x29 => ProcessorFamily::IntelCoreDuomobileProcessor,
            0x2A => ProcessorFamily::IntelCoreSolomobileProcessor,
            0x2B => ProcessorFamily::IntelAtomProcessor,
            0x2C => ProcessorFamily::IntelCoreMProcessor,
            0x2D => ProcessorFamily::IntelCorem3Processor,
            0x2E => ProcessorFamily::IntelCorem5Processor,
            0x2F => ProcessorFamily::IntelCorem7Processor,
            0x30 => ProcessorFamily::AlphaFamily,
            0x31 => ProcessorFamily::Alpha21064,
            0x32 => ProcessorFamily::Alpha21066,
            0x33 => ProcessorFamily::Alpha21164,
            0x34 => ProcessorFamily::Alpha21164PC,
            0x35 => ProcessorFamily::Alpha21164a,
            0x36 => ProcessorFamily::Alpha21264,
            0x37 => ProcessorFamily::Alpha21364,
            0x38 => ProcessorFamily::AMDTurionIIUltraDualCoreMobileMProcessorFamily,
            0x39 => ProcessorFamily::AMDTurionIIDualCoreMobileMProcessorFamily,
            0x3A => ProcessorFamily::AMDAthlonIIDualCoreMProcessorFamily,
            0x3B => ProcessorFamily::AMDOpteron6100SeriesProcessor,
            0x3C => ProcessorFamily::AMDOpteron4100SeriesProcessor,
            0x3D => ProcessorFamily::AMDOpteron6200SeriesProcessor,
            0x3E => ProcessorFamily::AMDOpteron4200SeriesProcessor,
            0x3F => ProcessorFamily::AMDFXSeriesProcessor,
            0x40 => ProcessorFamily::MIPSFamily,
            0x41 => ProcessorFamily::MIPSR4000,
            0x42 => ProcessorFamily::MIPSR4200,
            0x43 => ProcessorFamily::MIPSR4400,
            0x44 => ProcessorFamily::MIPSR4600,
            0x45 => ProcessorFamily::MIPSR10000,
            0x46 => ProcessorFamily::AMDCSeriesProcessor,
            0x47 => ProcessorFamily::AMDESeriesProcessor,
            0x48 => ProcessorFamily::AMDASeriesProcessor,
            0x49 => ProcessorFamily::AMDGSeriesProcessor,
            0x4A => ProcessorFamily::AMDZSeriesProcessor,
            0x4B => ProcessorFamily::AMDRSeriesProcessor,
            0x4C => ProcessorFamily::AMDOpteron4300SeriesProcessor,
            0x4D => ProcessorFamily::AMDOpteron6300SeriesProcessor,
            0x4E => ProcessorFamily::AMDOpteron3300SeriesProcessor,
            0x4F => ProcessorFamily::AMDFireProSeriesProcessor,
            0x50 => ProcessorFamily::SPARCFamily,
            0x51 => ProcessorFamily::SuperSPARC,
            0x52 => ProcessorFamily::MicroSparcii,
            0x53 => ProcessorFamily::MicroSparciiep,
            0x54 => ProcessorFamily::UltraSPARC,
            0x55 => ProcessorFamily::UltraSPARCII,
            0x56 => ProcessorFamily::UltraSPARCIii,
            0x57 => ProcessorFamily::UltraSPARCIII,
            0x58 => ProcessorFamily::UltraSPARCIIIi,
            0x60 => ProcessorFamily::M68040Family,
            0x61 => ProcessorFamily::M68xxx,
            0x62 => ProcessorFamily::M68000,
            0x63 => ProcessorFamily::M68010,
            0x64 => ProcessorFamily::M68020,
            0x65 => ProcessorFamily::M68030,
            0x66 => ProcessorFamily::AMDAthlonX4QuadCoreProcessorFamily,
            0x67 => ProcessorFamily::AMDOpteronX1000SeriesProcessor,
            0x68 => ProcessorFamily::AMDOpteronX2000SeriesAPU,
            0x69 => ProcessorFamily::AMDOpteronASeriesProcessor,
            0x6A => ProcessorFamily::AMDOpteronX3000SeriesAPU,
            0x6B => ProcessorFamily::AMDZenProcessorFamily,
            0x70 => ProcessorFamily::HobbitFamily,
            0x78 => ProcessorFamily::CrusoeTM5000Family,
            0x79 => ProcessorFamily::CrusoeTM3000Family,
            0x7A => ProcessorFamily::EfficeonTM8000Family,
            0x80 => ProcessorFamily::Weitek,
            0x82 => ProcessorFamily::Itaniumprocessor,
            0x83 => ProcessorFamily::AMDAthlon64ProcessorFamily,
            0x84 => ProcessorFamily::AMDOpteronProcessorFamily,
            0x85 => ProcessorFamily::AMDSempronProcessorFamily,
            0x86 => ProcessorFamily::AMDTurion64MobileTechnology,
            0x87 => ProcessorFamily::DualCoreAMDOpteronProcessorFamily,
            0x88 => ProcessorFamily::AMDAthlon64X2DualCoreProcessorFamily,
            0x89 => ProcessorFamily::AMDTurion64X2MobileTechnology,
            0x8A => ProcessorFamily::QuadCoreAMDOpteronProcessorFamily,
            0x8B => ProcessorFamily::ThirdGenerationAMDOpteronProcessorFamily,
            0x8C => ProcessorFamily::AMDPhenomFXQuadCoreProcessorFamily,
            0x8D => ProcessorFamily::AMDPhenomX4QuadCoreProcessorFamily,
            0x8E => ProcessorFamily::AMDPhenomX2DualCoreProcessorFamily,
            0x8F => ProcessorFamily::AMDAthlonX2DualCoreProcessorFamily,
            0x90 => ProcessorFamily::PARISCFamily,
            0x91 => ProcessorFamily::PARISC8500,
            0x92 => ProcessorFamily::PARISC8000,
            0x93 => ProcessorFamily::PARISC7300LC,
            0x94 => ProcessorFamily::PARISC7200,
            0x95 => ProcessorFamily::PARISC7100LC,
            0x96 => ProcessorFamily::PARISC7100,
            0xA0 => ProcessorFamily::V30Family,
            0xA1 => ProcessorFamily::QuadCoreIntelXeonProcessor3200Series,
            0xA2 => ProcessorFamily::DualCoreIntelXeonProcessor3000Series,
            0xA3 => ProcessorFamily::QuadCoreIntelXeonProcessor5300Series,
            0xA4 => ProcessorFamily::DualCoreIntelXeonProcessor5100Series,
            0xA5 => ProcessorFamily::DualCoreIntelXeonProcessor5000Series,
            0xA6 => ProcessorFamily::DualCoreIntelXeonProcessorLV,
            0xA7 => ProcessorFamily::DualCoreIntelXeonProcessorULV,
            0xA8 => ProcessorFamily::DualCoreIntelXeonProcessor7100Series,
            0xA9 => ProcessorFamily::QuadCoreIntelXeonProcessor5400Series,
            0xAA => ProcessorFamily::QuadCoreIntelXeonProcessor,
            0xAB => ProcessorFamily::DualCoreIntelXeonProcessor5200Series,
            0xAC => ProcessorFamily::DualCoreIntelXeonProcessor7200Series,
            0xAD => ProcessorFamily::QuadCoreIntelXeonProcessor7300Series,
            0xAE => ProcessorFamily::QuadCoreIntelXeonProcessor7400Series,
            0xAF => ProcessorFamily::MultiCoreIntelXeonProcessor7400Series,
            0xB0 => ProcessorFamily::PentiumIIIXeonProcessor,
            0xB1 => ProcessorFamily::PentiumIIIProcessorwithIntelSpeedStepTechnology,
            0xB2 => ProcessorFamily::Pentium4Processor,
            0xB3 => ProcessorFamily::IntelXeonProcessor,
            0xB4 => ProcessorFamily::AS400Family,
            0xB5 => ProcessorFamily::IntelXeonProcessorMP,
            0xB6 => ProcessorFamily::AMDAthlonXPProcessorFamily,
            0xB7 => ProcessorFamily::AMDAthlonMPProcessorFamily,
            0xB8 => ProcessorFamily::IntelItanium2Processor,
            0xB9 => ProcessorFamily::IntelPentiumMProcessor,
            0xBA => ProcessorFamily::IntelCeleronDProcessor,
            0xBB => ProcessorFamily::IntelPentiumDProcessor,
            0xBC => ProcessorFamily::IntelPentiumProcessorExtremeEdition,
            0xBD => ProcessorFamily::IntelCoreSoloProcessor,
            0xBF => ProcessorFamily::IntelCore2DuoProcessor,
            0xC0 => ProcessorFamily::IntelCore2SoloProcessor,
            0xC1 => ProcessorFamily::IntelCore2ExtremeProcessor,
            0xC2 => ProcessorFamily::IntelCore2QuadProcessor,
            0xC3 => ProcessorFamily::IntelCore2ExtremeMobileProcessor,
            0xC4 => ProcessorFamily::IntelCore2DuoMobileProcessor,
            0xC5 => ProcessorFamily::IntelCore2SoloMobileProcessor,
            0xC6 => ProcessorFamily::IntelCorei7Processor,
            0xC7 => ProcessorFamily::DualCoreIntelCeleronProcessor,
            0xC8 => ProcessorFamily::IBM390Family,
            0xC9 => ProcessorFamily::G4,
            0xCA => ProcessorFamily::G5,
            0xCB => ProcessorFamily::ESA390G6,
            0xCC => ProcessorFamily::ZArchitecturebase,
            0xCD => ProcessorFamily::IntelCorei5processor,
            0xCE => ProcessorFamily::IntelCorei3processor,
            0xCF => ProcessorFamily::IntelCorei9processor,
            0xD2 => ProcessorFamily::VIAC7MProcessorFamily,
            0xD3 => ProcessorFamily::VIAC7DProcessorFamily,
            0xD4 => ProcessorFamily::VIAC7ProcessorFamily,
            0xD5 => ProcessorFamily::VIAEdenProcessorFamily,
            0xD6 => ProcessorFamily::MultiCoreIntelXeonProcessor,
            0xD7 => ProcessorFamily::DualCoreIntelXeonProcessor3xxxSeries,
            0xD8 => ProcessorFamily::QuadCoreIntelXeonProcessor3xxxSeries,
            0xD9 => ProcessorFamily::VIANanoProcessorFamily,
            0xDA => ProcessorFamily::DualCoreIntelXeonProcessor5xxxSeries,
            0xDB => ProcessorFamily::QuadCoreIntelXeonProcessor5xxxSeries,
            0xDD => ProcessorFamily::DualCoreIntelXeonProcessor7xxxSeries,
            0xDE => ProcessorFamily::QuadCoreIntelXeonProcessor7xxxSeries,
            0xDF => ProcessorFamily::MultiCoreIntelXeonProcessor7xxxSeries,
            0xE0 => ProcessorFamily::MultiCoreIntelXeonProcessor3400Series,
            0xE4 => ProcessorFamily::AMDOpteron3000SeriesProcessor,
            0xE5 => ProcessorFamily::AMDSempronIIProcessor,
            0xE6 => ProcessorFamily::EmbeddedAMDOpteronQuadCoreProcessorFamily,
            0xE7 => ProcessorFamily::AMDPhenomTripleCoreProcessorFamily,
            0xE8 => ProcessorFamily::AMDTurionUltraDualCoreMobileProcessorFamily,
            0xE9 => ProcessorFamily::AMDTurionDualCoreMobileProcessorFamily,
            0xEA => ProcessorFamily::AMDAthlonDualCoreProcessorFamily,
            0xEB => ProcessorFamily::AMDSempronSIProcessorFamily,
            0xEC => ProcessorFamily::AMDPhenomIIProcessorFamily,
            0xED => ProcessorFamily::AMDAthlonIIProcessorFamily,
            0xEE => ProcessorFamily::SixCoreAMDOpteronProcessorFamily,
            0xEF => ProcessorFamily::AMDSempronMProcessorFamily,
            0xFA => ProcessorFamily::I860,
            0xFB => ProcessorFamily::I960,
            0xFE => ProcessorFamily::SeeProcessorFamily2,
            0x100 => ProcessorFamily::ARMv7,
            0x101 => ProcessorFamily::ARMv8,
            0x102 => ProcessorFamily::SH3,
            0x103 => ProcessorFamily::SH4,
            0x104 => ProcessorFamily::ARM,
            0x105 => ProcessorFamily::StrongARM,
            0x106 => ProcessorFamily::Cyrix6x86,
            0x107 => ProcessorFamily::MediaGX,
            0x108 => ProcessorFamily::MII,
            0x109 => ProcessorFamily::WinChip,
            0x10A => ProcessorFamily::DSP,
            0x10B => ProcessorFamily::VideoProcessor,
            0x10C => ProcessorFamily::RISCVRV32,
            0x10D => ProcessorFamily::RISCVRV64,
            0x10E => ProcessorFamily::RISCVRV128,
            _ => ProcessorFamily::None,
        }
    }
}

/// #
pub struct ProcessorUpgradeData {
    /// Raw value
    ///
    /// _raw_ is most useful when _value_ is None.
    /// This is most likely to occur when the standard was updated but
    /// this library code has not been updated to match the current
    /// standard.
    pub raw: u8,
    /// The contained [ProcessorUpgrade] value
    pub value: ProcessorUpgrade,
}

impl fmt::Debug for ProcessorUpgradeData {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorUpgradeData>())
            .field("raw", &self.raw)
            .field("value", &self.value)
            .finish()
    }
}

impl Serialize for ProcessorUpgradeData {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorUpgradeData", 2)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("value", &self.value)?;
        state.end()
    }
}

impl Deref for ProcessorUpgradeData {
    type Target = ProcessorUpgrade;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

/// #
#[derive(Serialize, Debug, PartialEq, Eq)]
pub enum ProcessorUpgrade {
    /// Other
    Other,
    /// Unknown
    Unknown,
    /// Daughter Board
    DaughterBoard,
    /// ZIF Socket
    ZIFSocket,
    /// Replaceable Piggy Back
    ReplaceablePiggyBack,
    /// No Upgrade
    NoUpgrade,
    /// LIF Socket
    LIFSocket,
    /// Slot 1
    Slot1,
    /// Slot 2
    Slot2,
    /// 370-pin socket
    PinSocket370,
    /// Slot A
    SlotA,
    /// Slot M
    SlotM,
    /// Socket 423
    Socket423,
    /// Socket A (Socket 462)
    SocketASocket462,
    /// Socket 478
    Socket478,
    /// Socket 754
    Socket754,
    /// Socket 940
    Socket940,
    /// Socket 939
    Socket939,
    /// Socket mPGA604
    SocketmPGA604,
    /// Socket LGA771
    SocketLGA771,
    /// Socket LGA775
    SocketLGA775,
    /// Socket S1
    SocketS1,
    /// Socket AM2
    SocketAM2,
    /// Socket F (1207)
    SocketF1207,
    /// Socket LGA1366
    SocketLGA1366,
    /// Socket G34
    SocketG34,
    /// Socket AM3
    SocketAM3,
    /// Socket C32
    SocketC32,
    /// Socket LGA1156
    SocketLGA1156,
    /// Socket LGA1567
    SocketLGA1567,
    /// Socket PGA988A
    SocketPGA988A,
    /// Socket BGA1288
    SocketBGA1288,
    /// Socket rPGA988B
    SocketrPGA988B,
    /// Socket BGA1023
    SocketBGA1023,
    /// Socket BGA1224
    SocketBGA1224,
    /// Socket LGA1155
    SocketLGA1155,
    /// Socket LGA1356
    SocketLGA1356,
    /// Socket LGA2011
    SocketLGA2011,
    /// Socket FS1
    SocketFS1,
    /// Socket FS2
    SocketFS2,
    /// Socket FM1
    SocketFM1,
    /// Socket FM2
    SocketFM2,
    /// Socket LGA2011-3
    SocketLGA2011_3,
    /// Socket LGA1356-3
    SocketLGA1356_3,
    /// Socket LGA1150
    SocketLGA1150,
    /// Socket BGA1168
    SocketBGA1168,
    /// Socket BGA1234
    SocketBGA1234,
    /// Socket BGA1364
    SocketBGA1364,
    /// Socket AM4
    SocketAM4,
    /// Socket LGA1151
    SocketLGA1151,
    /// Socket BGA1356
    SocketBGA1356,
    /// Socket BGA1440
    SocketBGA1440,
    /// Socket BGA1515
    SocketBGA1515,
    /// Socket LGA3647-1
    SocketLGA3647_1,
    /// Socket SP3
    SocketSP3,
    /// Socket SP3r2
    SocketSP3r23,
    /// Socket LGA2066
    SocketLGA2066,
    /// Socket BGA1392
    SocketBGA1392,
    /// Socket BGA1510
    SocketBGA1510,
    /// Socket BGA1528
    SocketBGA1528,
    /// Socket LGA4189
    SocketLGA4189,
    /// Socket LGA1200
    SocketLGA1200,
    /// A value unknown to this standard, check the raw value
    None,
}

impl From<u8> for ProcessorUpgradeData {
    fn from(raw: u8) -> Self {
        ProcessorUpgradeData {
            value: match raw {
                0x01 => ProcessorUpgrade::Other,
                0x02 => ProcessorUpgrade::Unknown,
                0x03 => ProcessorUpgrade::DaughterBoard,
                0x04 => ProcessorUpgrade::ZIFSocket,
                0x05 => ProcessorUpgrade::ReplaceablePiggyBack,
                0x06 => ProcessorUpgrade::NoUpgrade,
                0x07 => ProcessorUpgrade::LIFSocket,
                0x08 => ProcessorUpgrade::Slot1,
                0x09 => ProcessorUpgrade::Slot2,
                0x0A => ProcessorUpgrade::PinSocket370,
                0x0B => ProcessorUpgrade::SlotA,
                0x0C => ProcessorUpgrade::SlotM,
                0x0D => ProcessorUpgrade::Socket423,
                0x0E => ProcessorUpgrade::SocketASocket462,
                0x0F => ProcessorUpgrade::Socket478,
                0x10 => ProcessorUpgrade::Socket754,
                0x11 => ProcessorUpgrade::Socket940,
                0x12 => ProcessorUpgrade::Socket939,
                0x13 => ProcessorUpgrade::SocketmPGA604,
                0x14 => ProcessorUpgrade::SocketLGA771,
                0x15 => ProcessorUpgrade::SocketLGA775,
                0x16 => ProcessorUpgrade::SocketS1,
                0x17 => ProcessorUpgrade::SocketAM2,
                0x18 => ProcessorUpgrade::SocketF1207,
                0x19 => ProcessorUpgrade::SocketLGA1366,
                0x1A => ProcessorUpgrade::SocketG34,
                0x1B => ProcessorUpgrade::SocketAM3,
                0x1C => ProcessorUpgrade::SocketC32,
                0x1D => ProcessorUpgrade::SocketLGA1156,
                0x1E => ProcessorUpgrade::SocketLGA1567,
                0x1F => ProcessorUpgrade::SocketPGA988A,
                0x20 => ProcessorUpgrade::SocketBGA1288,
                0x21 => ProcessorUpgrade::SocketrPGA988B,
                0x22 => ProcessorUpgrade::SocketBGA1023,
                0x23 => ProcessorUpgrade::SocketBGA1224,
                0x24 => ProcessorUpgrade::SocketLGA1155,
                0x25 => ProcessorUpgrade::SocketLGA1356,
                0x26 => ProcessorUpgrade::SocketLGA2011,
                0x27 => ProcessorUpgrade::SocketFS1,
                0x28 => ProcessorUpgrade::SocketFS2,
                0x29 => ProcessorUpgrade::SocketFM1,
                0x2A => ProcessorUpgrade::SocketFM2,
                0x2B => ProcessorUpgrade::SocketLGA2011_3,
                0x2C => ProcessorUpgrade::SocketLGA1356_3,
                0x2D => ProcessorUpgrade::SocketLGA1150,
                0x2E => ProcessorUpgrade::SocketBGA1168,
                0x2F => ProcessorUpgrade::SocketBGA1234,
                0x30 => ProcessorUpgrade::SocketBGA1364,
                0x31 => ProcessorUpgrade::SocketAM4,
                0x32 => ProcessorUpgrade::SocketLGA1151,
                0x33 => ProcessorUpgrade::SocketBGA1356,
                0x34 => ProcessorUpgrade::SocketBGA1440,
                0x35 => ProcessorUpgrade::SocketBGA1515,
                0x36 => ProcessorUpgrade::SocketLGA3647_1,
                0x37 => ProcessorUpgrade::SocketSP3,
                0x38 => ProcessorUpgrade::SocketSP3r23,
                0x39 => ProcessorUpgrade::SocketLGA2066,
                0x3A => ProcessorUpgrade::SocketBGA1392,
                0x3B => ProcessorUpgrade::SocketBGA1510,
                0x3C => ProcessorUpgrade::SocketBGA1528,
                0x3D => ProcessorUpgrade::SocketLGA4189,
                0x3E => ProcessorUpgrade::SocketLGA1200,
                _ => ProcessorUpgrade::None,
            },
            raw,
        }
    }
}

/// # Processor Characteristics
#[derive(PartialEq, Eq)]
pub struct ProcessorCharacteristics {
    /// Raw value
    pub raw: u16,
}

impl Deref for ProcessorCharacteristics {
    type Target = u16;

    fn deref(&self) -> &Self::Target {
        &self.raw
    }
}

impl From<u16> for ProcessorCharacteristics {
    fn from(raw: u16) -> Self {
        ProcessorCharacteristics { raw }
    }
}

impl ProcessorCharacteristics {
    /// Bit 1 Unknown
    pub fn unknown(&self) -> bool {
        self.raw & 0x0002 == 0x0002
    }

    /// Bit 2 64-bit Capable
    pub fn bit_64capable(&self) -> bool {
        self.raw & 0x0004 == 0x0004
    }

    /// Bit 3 Multi-Core
    pub fn multi_core(&self) -> bool {
        self.raw & 0x0008 == 0x0008
    }

    /// Bit 4 Hardware Thread
    pub fn hardware_thread(&self) -> bool {
        self.raw & 0x0010 == 0x0010
    }

    /// Bit 5 Execute Protection
    pub fn execute_protection(&self) -> bool {
        self.raw & 0x0020 == 0x0020
    }

    /// Bit 6 Enhanced Virtualization
    pub fn enhanced_virtualization(&self) -> bool {
        self.raw & 0x0040 == 0x0040
    }

    /// Bit 7 Power/Performance Control
    pub fn power_performance_control(&self) -> bool {
        self.raw & 0x0080 == 0x0080
    }

    /// Bit 8 128-bit Capable
    pub fn bit_128capable(&self) -> bool {
        self.raw & 0x0100 == 0x0100
    }

    /// Bit 9 Arm64 SoC ID
    pub fn arm_64soc_id(&self) -> bool {
        self.raw & 0x200 == 0x200
    }
}

impl fmt::Debug for ProcessorCharacteristics {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorCharacteristics>())
            .field("raw", &self.raw)
            .field("unknown", &self.unknown())
            .field("bit_64capable", &self.bit_64capable())
            .field("multi_core", &self.multi_core())
            .field("hardware_thread", &self.hardware_thread())
            .field("execute_protection", &self.execute_protection())
            .field("enhanced_virtualization", &self.enhanced_virtualization())
            .field(
                "power_performance_control",
                &self.power_performance_control(),
            )
            .field("bit_128capable", &self.bit_128capable())
            .field("arm_64soc_id", &self.arm_64soc_id())
            .finish()
    }
}

impl Serialize for ProcessorCharacteristics {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorCharacteristics", 10)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("unknown", &self.unknown())?;
        state.serialize_field("bit_64capable", &self.bit_64capable())?;
        state.serialize_field("multi_core", &self.multi_core())?;
        state.serialize_field("hardware_thread", &self.hardware_thread())?;
        state.serialize_field("execute_protection", &self.execute_protection())?;
        state.serialize_field("enhanced_virtualization", &self.enhanced_virtualization())?;
        state.serialize_field(
            "power_performance_control",
            &self.power_performance_control(),
        )?;
        state.serialize_field("bit_128capable", &self.bit_128capable())?;
        state.serialize_field("arm_64soc_id", &self.arm_64soc_id())?;
        state.end()
    }
}

/// # Processor Voltage
#[derive(Serialize, Debug)]
pub enum ProcessorVoltage {
    /// Current Processor Voltage
    CurrentVolts(f32),
    /// Processor Supported Voltages
    SupportedVolts(ProcessorSupportedVoltages),
}

impl From<u8> for ProcessorVoltage {
    fn from(raw: u8) -> Self {
        if raw & 0b1000_0000 == 0b1000_0000 {
            ProcessorVoltage::CurrentVolts((raw & 0b0111_1111) as f32 / 10.0)
        } else {
            ProcessorVoltage::SupportedVolts(ProcessorSupportedVoltages::from(raw))
        }
    }
}

/// # Processor Supported Voltages
#[derive(PartialEq, Eq)]
pub struct ProcessorSupportedVoltages {
    /// Raw value
    pub raw: u8,
}

impl Deref for ProcessorSupportedVoltages {
    type Target = u8;

    fn deref(&self) -> &Self::Target {
        &self.raw
    }
}

impl From<u8> for ProcessorSupportedVoltages {
    fn from(raw: u8) -> Self {
        debug_assert_eq!(raw, raw & 0b0111_1111);
        ProcessorSupportedVoltages { raw }
    }
}

impl ProcessorSupportedVoltages {
    /// Bit 0 – 5V
    pub fn volts_5_0(&self) -> bool {
        self.raw & 0x01 == 0x01
    }

    /// Bit 1 – 3.3V
    pub fn volts_3_3(&self) -> bool {
        self.raw & 0x02 == 0x02
    }

    /// Bit 2 – 2.9V
    pub fn volts_2_9(&self) -> bool {
        self.raw & 0x04 == 0x04
    }

    /// Available Voltages
    pub fn voltages(&self) -> Vec<f32> {
        let mut result = Vec::new();

        if self.volts_2_9() {
            result.push(2.9);
        }

        if self.volts_3_3() {
            result.push(3.3);
        }

        if self.volts_5_0() {
            result.push(5.0);
        }

        result
    }
}

impl fmt::Debug for ProcessorSupportedVoltages {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorSupportedVoltages>())
            .field("raw", &self.raw)
            .field("voltages", &self.voltages().as_slice())
            .finish()
    }
}

impl Serialize for ProcessorSupportedVoltages {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorSupportedVoltages", 2)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("voltages", &self.voltages().as_slice())?;
        state.end()
    }
}

/// External Clock Frequency in MHz
#[derive(Serialize, Debug)]
pub enum ProcessorExternalClock {
    /// The value is unknown
    Unknown,
    /// External Clock Frequency in MHz
    MHz(u16),
}

impl From<u16> for ProcessorExternalClock {
    fn from(raw: u16) -> Self {
        match raw {
            0 => ProcessorExternalClock::Unknown,
            _ => ProcessorExternalClock::MHz(raw),
        }
    }
}

/// Processor Speed in MHz
#[derive(Serialize, Debug)]
pub enum ProcessorSpeed {
    /// The value is unknown
    Unknown,
    /// The Processor Speed in MHz
    MHz(u16),
}

impl From<u16> for ProcessorSpeed {
    fn from(raw: u16) -> Self {
        match raw {
            0 => ProcessorSpeed::Unknown,
            _ => ProcessorSpeed::MHz(raw),
        }
    }
}

/// # Processor Socket and CPU Status
#[derive(PartialEq, Eq)]
pub struct ProcessorStatus {
    /// Raw value
    pub raw: u8,
}

impl Deref for ProcessorStatus {
    type Target = u8;

    fn deref(&self) -> &Self::Target {
        &self.raw
    }
}

impl From<u8> for ProcessorStatus {
    fn from(raw: u8) -> Self {
        ProcessorStatus { raw }
    }
}

impl ProcessorStatus {
    /// CPU Socket Populated
    pub fn socket_populated(&self) -> bool {
        self.raw & 0b0100_0000 == 0b0100_0000
    }

    /// CPU Status
    pub fn cpu_status(&self) -> CpuStatus {
        CpuStatus::from(self.raw)
    }
}

impl fmt::Debug for ProcessorStatus {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct(std::any::type_name::<ProcessorStatus>())
            .field("raw", &self.raw)
            .field("socket_populated", &self.socket_populated())
            .field("cpu_status", &self.cpu_status())
            .finish()
    }
}

impl Serialize for ProcessorStatus {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let mut state = serializer.serialize_struct("ProcessorStatus", 3)?;
        state.serialize_field("raw", &self.raw)?;
        state.serialize_field("socket_populated", &self.socket_populated())?;
        state.serialize_field("cpu_status", &self.cpu_status())?;
        state.end()
    }
}

/// CPU Status
#[derive(Serialize, Debug, PartialEq, Eq)]
pub enum CpuStatus {
    /// 0h – Unknown
    Unknown,
    /// 1h – CPU Enabled
    Enabled,
    /// 2h – CPU Disabled by User through BIOS Setup
    UserDisabled,
    /// 3h – CPU Disabled By BIOS (POST Error)
    BiosDisabled,
    /// 4h – CPU is Idle, waiting to be enabled.
    Idle,
    /// 7h – Other
    Other,
    /// A value unknown to this standard, check the raw value
    None,
}

impl From<u8> for CpuStatus {
    fn from(raw: u8) -> Self {
        match raw & 0b0000_0111 {
            0 => CpuStatus::Unknown,
            1 => CpuStatus::Enabled,
            2 => CpuStatus::UserDisabled,
            3 => CpuStatus::BiosDisabled,
            4 => CpuStatus::Idle,
            7 => CpuStatus::Other,
            _ => CpuStatus::None,
        }
    }
}

/// Processor Core Count
#[derive(Serialize, Debug)]
pub enum CoreCount {
    /// The value is unknown
    Unknown,
    /// Number of cores per processor socket
    Count(u8),
    /// For core counts of 256 or greater the 'core_count_2' field
    /// is set to the number of cores.
    SeeCoreCount2,
}

impl From<u8> for CoreCount {
    fn from(raw: u8) -> Self {
        match raw {
            0 => CoreCount::Unknown,
            0xFF => CoreCount::SeeCoreCount2,
            _ => CoreCount::Count(raw),
        }
    }
}

/// Processor Core Count #2
#[derive(Serialize, Debug)]
pub enum CoreCount2 {
    /// The value is unknown
    Unknown,
    /// Number of cores per processor socket
    Count(u16),
    /// Reserved (0xFFFF)
    Reserved,
}

impl From<u16> for CoreCount2 {
    fn from(raw: u16) -> Self {
        match raw {
            0 => CoreCount2::Unknown,
            0xFFFF => CoreCount2::Reserved,
            _ => CoreCount2::Count(raw),
        }
    }
}

/// Processor Cores Enabled
#[derive(Serialize, Debug)]
pub enum CoresEnabled {
    /// The value is unknown
    Unknown,
    /// Number of cores enabled
    Count(u8),
    /// For core counts of 256 or greater the 'cores_enabled_2' field
    /// is set to the number of enabled cores.
    SeeCoresEnabled2,
}

impl From<u8> for CoresEnabled {
    fn from(raw: u8) -> Self {
        match raw {
            0 => CoresEnabled::Unknown,
            0xFF => CoresEnabled::SeeCoresEnabled2,
            _ => CoresEnabled::Count(raw),
        }
    }
}

/// Processor Cores Enabled #2
#[derive(Serialize, Debug)]
pub enum CoresEnabled2 {
    /// The value is unknown
    Unknown,
    /// Number of cores enabled
    Count(u16),
    /// Reserved (0xFFFF)
    Reserved,
}

impl From<u16> for CoresEnabled2 {
    fn from(raw: u16) -> Self {
        match raw {
            0 => CoresEnabled2::Unknown,
            0xFFFF => CoresEnabled2::Reserved,
            _ => CoresEnabled2::Count(raw),
        }
    }
}

/// Processor Thread Count
#[derive(Serialize, Debug)]
pub enum ThreadCount {
    /// The value is unknown
    Unknown,
    /// Number of threads per processor socket
    Count(u8),
    /// For thread counts of 256 or greater the 'thread_count_2' field
    /// is set to the number of cores.
    SeeThreadCount2,
}

impl From<u8> for ThreadCount {
    fn from(raw: u8) -> Self {
        match raw {
            0 => ThreadCount::Unknown,
            0xFF => ThreadCount::SeeThreadCount2,
            _ => ThreadCount::Count(raw),
        }
    }
}

/// Processor Thread Count #2
#[derive(Serialize, Debug)]
pub enum ThreadCount2 {
    /// The value is unknown
    Unknown,
    /// Number of threads per processor socket
    Count(u16),
    /// Reserved (0xFFFF)
    Reserved,
}

impl From<u16> for ThreadCount2 {
    fn from(raw: u16) -> Self {
        match raw {
            0 => ThreadCount2::Unknown,
            0xFFFF => ThreadCount2::Reserved,
            _ => ThreadCount2::Count(raw),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn unit_test() {
        let struct_type4 = vec![
            0x04, 0x30, 0x56, 0x00, 0x01, 0x03, 0xB3, 0x02, 0x54, 0x06, 0x05, 0x00, 0xFF, 0xFB,
            0xEB, 0xBF, 0x03, 0x90, 0x64, 0x00, 0x3C, 0x0F, 0x10, 0x0E, 0x41, 0x01, 0x53, 0x00,
            0x54, 0x00, 0x55, 0x00, 0x00, 0x04, 0x00, 0x06, 0x06, 0x0C, 0xFC, 0x00, 0xB3, 0x00,
            0x06, 0x00, 0x06, 0x00, 0x0C, 0x00, 0x43, 0x50, 0x55, 0x30, 0x00, 0x49, 0x6E, 0x74,
            0x65, 0x6C, 0x28, 0x52, 0x29, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F, 0x72, 0x61, 0x74,
            0x69, 0x6F, 0x6E, 0x00, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x28, 0x52, 0x29, 0x20, 0x58,
            0x65, 0x6F, 0x6E, 0x28, 0x52, 0x29, 0x20, 0x57, 0x2D, 0x32, 0x31, 0x33, 0x33, 0x20,
            0x43, 0x50, 0x55, 0x20, 0x40, 0x20, 0x33, 0x2E, 0x36, 0x30, 0x47, 0x48, 0x7A, 0x00,
            0x55, 0x4E, 0x4B, 0x4E, 0x4F, 0x57, 0x4E, 0x00, 0x00,
        ];

        let parts = UndefinedStruct::new(&struct_type4);
        let test_struct = SMBiosProcessorInformation::new(&parts);

        assert_eq!(test_struct.socket_designation(), Some("CPU0".to_string()));
        assert_eq!(
            *test_struct.processor_type().unwrap(),
            ProcessorType::CentralProcessor
        );
        assert_eq!(
            *test_struct.processor_family().unwrap(),
            ProcessorFamily::IntelXeonProcessor
        );
        assert_eq!(
            test_struct.processor_manufacturer(),
            Some("Intel(R) Corporation".to_string())
        );
        assert_eq!(
            test_struct.processor_id(),
            Some(&[0x54u8, 0x06, 0x05, 0x00, 0xFF, 0xFB, 0xEB, 0xBF])
        );
        assert_eq!(
            test_struct.processor_version(),
            Some("Intel(R) Xeon(R) W-2133 CPU @ 3.60GHz".to_string())
        );
        match test_struct.voltage().unwrap() {
            ProcessorVoltage::CurrentVolts(volts) => assert_eq!(volts, 1.6),
            ProcessorVoltage::SupportedVolts(_) => panic!("expected current volts"),
        }
        match test_struct.external_clock().unwrap() {
            ProcessorExternalClock::MHz(mhz) => assert_eq!(mhz, 100),
            ProcessorExternalClock::Unknown => panic!("expected MHz"),
        }
        match test_struct.max_speed().unwrap() {
            ProcessorSpeed::MHz(mhz) => assert_eq!(mhz, 3900),
            ProcessorSpeed::Unknown => panic!("expected MHz"),
        }
        match test_struct.current_speed().unwrap() {
            ProcessorSpeed::MHz(mhz) => assert_eq!(mhz, 3600),
            ProcessorSpeed::Unknown => panic!("expected MHz"),
        }
        let processor_status = test_struct.status().unwrap();
        assert!(processor_status.socket_populated());
        assert_eq!(processor_status.cpu_status(), CpuStatus::Enabled);
        assert_eq!(
            *test_struct.processor_upgrade().unwrap(),
            ProcessorUpgrade::Other
        );
        assert_eq!(*test_struct.l1cache_handle().unwrap(), 83);
        assert_eq!(*test_struct.l2cache_handle().unwrap(), 84);
        assert_eq!(*test_struct.l3cache_handle().unwrap(), 85);
        assert_eq!(test_struct.serial_number(), None);
        assert_eq!(test_struct.asset_tag(), Some("UNKNOWN".to_string()));
        assert_eq!(test_struct.part_number(), None);
        match test_struct.core_count().unwrap() {
            CoreCount::Count(number) => assert_eq!(number, 6),
            CoreCount::Unknown => panic!("expected number"),
            CoreCount::SeeCoreCount2 => panic!("expected number"),
        }
        match test_struct.cores_enabled().unwrap() {
            CoresEnabled::Count(number) => assert_eq!(number, 6),
            CoresEnabled::Unknown => panic!("expected number"),
            CoresEnabled::SeeCoresEnabled2 => panic!("expected number"),
        }
        match test_struct.thread_count().unwrap() {
            ThreadCount::Count(number) => assert_eq!(number, 12),
            ThreadCount::Unknown => panic!("expected number"),
            ThreadCount::SeeThreadCount2 => panic!("expected number"),
        }
        assert_eq!(
            test_struct.processor_characteristics(),
            Some(ProcessorCharacteristics::from(252))
        );
        assert_eq!(
            *test_struct.processor_family_2().unwrap(),
            ProcessorFamily::IntelXeonProcessor
        );

        match test_struct.core_count_2().unwrap() {
            CoreCount2::Count(number) => assert_eq!(number, 6),
            CoreCount2::Unknown => panic!("expected number"),
            CoreCount2::Reserved => panic!("expected number"),
        }
        match test_struct.cores_enabled_2().unwrap() {
            CoresEnabled2::Count(number) => assert_eq!(number, 6),
            CoresEnabled2::Unknown => panic!("expected number"),
            CoresEnabled2::Reserved => panic!("expected number"),
        }
        match test_struct.thread_count_2().unwrap() {
            ThreadCount2::Count(number) => assert_eq!(number, 12),
            ThreadCount2::Unknown => panic!("expected number"),
            ThreadCount2::Reserved => panic!("expected number"),
        }
    }
}