virtcon_config/
virtcon_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_virtconconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArithmeticArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0x02, 0x87, 0xd8, 0x2f, 0x8e, 0x68, 0x4f, 0xf2, 0xbe, 0xfd, 0x39, 0x5b, 0xb2, 0x60, 0x47, 0x73,
8    0x34, 0x47, 0x80, 0xd4, 0x93, 0xf7, 0xf9, 0xb9, 0xec, 0x5b, 0x8e, 0x18, 0xaf, 0x3d, 0x7e, 0xf8,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub boot_animation: bool,
13    pub buffer_count: u32,
14    pub color_scheme: String,
15    pub disable: bool,
16    pub display_rotation: u32,
17    pub dpi: Vec<u32>,
18    pub font_size: String,
19    pub keep_log_visible: bool,
20    pub key_map: String,
21    pub keyrepeat: bool,
22    pub rounded_corners: bool,
23    pub scrollback_rows: u32,
24    pub show_logo: bool,
25}
26impl Config {
27    #[doc = r" Take the config startup handle and parse its contents."]
28    #[doc = r""]
29    #[doc = r" # Panics"]
30    #[doc = r""]
31    #[doc = r" If the config startup handle was already taken or if it is not valid."]
32    pub fn take_from_startup_handle() -> Self {
33        <Self as ComponentConfig>::take_from_startup_handle()
34    }
35    #[doc = r" Parse `Self` from `vmo`."]
36    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
37        <Self as ComponentConfig>::from_vmo(vmo)
38    }
39    #[doc = r" Parse `Self` from `bytes`."]
40    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
41        <Self as ComponentConfig>::from_bytes(bytes)
42    }
43    pub fn record_inspect(&self, inspector_node: &Node) {
44        <Self as ComponentConfig>::record_inspect(self, inspector_node)
45    }
46}
47impl ComponentConfig for Config {
48    #[doc = r" Parse `Self` from `bytes`."]
49    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
50        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
51        let checksum_len_bytes: [u8; 2] =
52            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
53        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
54        let (observed_checksum, bytes) =
55            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
56        if observed_checksum != EXPECTED_CHECKSUM {
57            return Err(Error::ChecksumMismatch {
58                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
59                observed_checksum: observed_checksum.to_vec(),
60            });
61        }
62        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
63        Ok(Self {
64            boot_animation: fidl_config.boot_animation,
65            buffer_count: fidl_config.buffer_count,
66            color_scheme: fidl_config.color_scheme,
67            disable: fidl_config.disable,
68            display_rotation: fidl_config.display_rotation,
69            dpi: fidl_config.dpi,
70            font_size: fidl_config.font_size,
71            keep_log_visible: fidl_config.keep_log_visible,
72            key_map: fidl_config.key_map,
73            keyrepeat: fidl_config.keyrepeat,
74            rounded_corners: fidl_config.rounded_corners,
75            scrollback_rows: fidl_config.scrollback_rows,
76            show_logo: fidl_config.show_logo,
77        })
78    }
79    fn record_inspect(&self, inspector_node: &Node) {
80        inspector_node.record_bool("boot_animation", self.boot_animation);
81        inspector_node.record_uint("buffer_count", self.buffer_count as u64);
82        inspector_node.record_string("color_scheme", &self.color_scheme);
83        inspector_node.record_bool("disable", self.disable);
84        inspector_node.record_uint("display_rotation", self.display_rotation as u64);
85        let arr = inspector_node.create_uint_array("dpi", self.dpi.len());
86        for i in 0..self.dpi.len() {
87            arr.add(i, self.dpi[i] as u64);
88        }
89        inspector_node.record(arr);
90        inspector_node.record_string("font_size", &self.font_size);
91        inspector_node.record_bool("keep_log_visible", self.keep_log_visible);
92        inspector_node.record_string("key_map", &self.key_map);
93        inspector_node.record_bool("keyrepeat", self.keyrepeat);
94        inspector_node.record_bool("rounded_corners", self.rounded_corners);
95        inspector_node.record_uint("scrollback_rows", self.scrollback_rows as u64);
96        inspector_node.record_bool("show_logo", self.show_logo);
97    }
98}