Skip to main content

ironrdp_pdu/rdp/capability_sets/offscreen_bitmap_cache/
mod.rs

1#[cfg(test)]
2mod tests;
3
4use ironrdp_core::{Decode, DecodeResult, Encode, EncodeResult, ReadCursor, WriteCursor, ensure_fixed_part_size};
5
6const OFFSCREEN_BITMAP_CACHE_LENGTH: usize = 8;
7
8#[derive(Debug, PartialEq, Eq, Clone)]
9#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10pub struct OffscreenBitmapCache {
11    pub is_supported: bool,
12    pub cache_size: u16,
13    pub cache_entries: u16,
14}
15
16impl OffscreenBitmapCache {
17    const NAME: &'static str = "OffscreenBitmapCache";
18
19    const FIXED_PART_SIZE: usize = OFFSCREEN_BITMAP_CACHE_LENGTH;
20}
21
22impl Encode for OffscreenBitmapCache {
23    fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
24        ensure_fixed_part_size!(in: dst);
25
26        dst.write_u32(u32::from(self.is_supported));
27        dst.write_u16(self.cache_size);
28        dst.write_u16(self.cache_entries);
29
30        Ok(())
31    }
32
33    fn name(&self) -> &'static str {
34        Self::NAME
35    }
36
37    fn size(&self) -> usize {
38        Self::FIXED_PART_SIZE
39    }
40}
41
42impl<'de> Decode<'de> for OffscreenBitmapCache {
43    fn decode(src: &mut ReadCursor<'de>) -> DecodeResult<Self> {
44        ensure_fixed_part_size!(in: src);
45
46        let is_supported = src.read_u32() != 0;
47        let cache_size = src.read_u16();
48        let cache_entries = src.read_u16();
49
50        Ok(OffscreenBitmapCache {
51            is_supported,
52            cache_size,
53            cache_entries,
54        })
55    }
56}