ironrdp_pdu/input/
sync.rs

1use bitflags::bitflags;
2use ironrdp_core::{
3    ensure_fixed_part_size, read_padding, write_padding, Decode, DecodeResult, Encode, EncodeResult, ReadCursor,
4    WriteCursor,
5};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct SyncPdu {
9    pub flags: SyncToggleFlags,
10}
11
12impl SyncPdu {
13    const NAME: &'static str = "SyncPdu";
14
15    const FIXED_PART_SIZE: usize = 2 /* padding */ + 4 /* flags */;
16}
17
18impl Encode for SyncPdu {
19    fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
20        ensure_fixed_part_size!(in: dst);
21
22        write_padding!(dst, 2);
23        dst.write_u32(self.flags.bits());
24
25        Ok(())
26    }
27
28    fn name(&self) -> &'static str {
29        Self::NAME
30    }
31
32    fn size(&self) -> usize {
33        Self::FIXED_PART_SIZE
34    }
35}
36
37impl<'de> Decode<'de> for SyncPdu {
38    fn decode(src: &mut ReadCursor<'de>) -> DecodeResult<Self> {
39        ensure_fixed_part_size!(in: src);
40
41        read_padding!(src, 2);
42        let flags = SyncToggleFlags::from_bits_truncate(src.read_u32());
43
44        Ok(Self { flags })
45    }
46}
47
48bitflags! {
49    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
50    pub struct SyncToggleFlags: u32 {
51        const SCROLL_LOCK = 0x1;
52        const NUM_LOCK = 0x2;
53        const CAPS_LOCK = 0x4;
54        const KANA_LOCK = 0x8;
55    }
56}