1use bitfield::bitfield;
6
7use crate::frame::error::FrameParseError;
8use crate::frame::FrameTypeMarker;
9use crate::DLCI;
10
11pub(crate) const FRAME_ADDRESS_IDX: usize = 0;
13bitfield! {
14 pub struct AddressField(u8);
15 impl Debug;
16 pub bool, ea_bit, set_ea_bit: 0;
17 pub bool, cr_bit, set_cr_bit: 1;
18 pub u8, dlci_raw, set_dlci: 7, 2;
19}
20
21impl AddressField {
22 pub fn dlci(&self) -> Result<DLCI, FrameParseError> {
24 DLCI::try_from(self.dlci_raw())
25 }
26}
27
28pub(crate) const FRAME_CONTROL_IDX: usize = 1;
30bitfield! {
31 pub struct ControlField(u8);
32 impl Debug;
33 pub bool, poll_final, set_poll_final: 4;
34 pub u8, frame_type_raw, set_frame_type: 7, 0;
35}
36
37impl ControlField {
38 pub fn frame_type(&self) -> Result<FrameTypeMarker, FrameParseError> {
40 const FRAME_TYPE_MASK: u8 = 0b11101111;
43 FrameTypeMarker::try_from(self.frame_type_raw() & FRAME_TYPE_MASK)
44 }
45}
46
47pub(crate) const FRAME_INFORMATION_IDX: usize = 2;
49
50pub(crate) const INFORMATION_SECOND_OCTET_SHIFT: usize = 7;
54
55bitfield! {
56 pub struct InformationField(u8);
57 impl Debug;
58 pub bool, ea_bit, set_ea_bit: 0;
59 pub u8, length, set_length_inner: 7, 1;
60}
61
62impl InformationField {
63 pub fn set_length(&mut self, length: u8) {
64 let mask = 0b1111111;
66 self.set_length_inner(length & mask);
67 }
68}