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
use modular_bitfield::prelude::*;
use byte::{
ctx::*,
self,
TryRead,
BytesExt,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SlotIdentification {
pub expansion_slot: ExpansionSlot,
pub chassis_number: u8,
}
impl<'a> TryRead<'a, Endian> for SlotIdentification {
fn try_read(bytes: &'a [u8], endian: Endian) -> byte::Result<(Self, usize)> {
let offset = &mut 0;
let si = SlotIdentification {
expansion_slot: bytes.read_with::<u8>(offset, endian)?.into(),
chassis_number: bytes.read_with::<u8>(offset, endian)?,
};
Ok((si, *offset))
}
}
#[bitfield(bits = 8)]
#[repr(u8)]
pub struct ExpansionSlotProto {
expansion_slots_provided: B5,
first_in_chassis: bool,
rsvdp: B2,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExpansionSlot {
pub expansion_slots_provided: u8,
pub first_in_chassis: bool,
}
impl From<ExpansionSlotProto> for ExpansionSlot {
fn from(proto: ExpansionSlotProto) -> Self {
let _ = proto.rsvdp();
Self {
expansion_slots_provided: proto.expansion_slots_provided(),
first_in_chassis: proto.first_in_chassis(),
}
}
}
impl From<u8> for ExpansionSlot {
fn from(byte: u8) -> Self { ExpansionSlotProto::from(byte).into() }
}