scene_manager_structured_config/
scene_manager_structured_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_scenemanagerstructuredconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0x54, 0xb2, 0x6f, 0x40, 0x5c, 0x8c, 0x28, 0x5d, 0x60, 0x79, 0xe5, 0x57, 0xd0, 0xb9, 0x58, 0x6d,
8    0x78, 0xad, 0x68, 0x60, 0x8a, 0xf7, 0x4a, 0xeb, 0xf2, 0x94, 0x07, 0xaf, 0x67, 0x9f, 0x95, 0xaa,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub attach_a11y_view: bool,
13    pub display_pixel_density: String,
14    pub display_rotation: u64,
15    pub idle_threshold_ms: u64,
16    pub supported_input_devices: Vec<String>,
17    pub suspend_enabled: bool,
18    pub viewing_distance: String,
19}
20impl Config {
21    #[doc = r" Take the config startup handle and parse its contents."]
22    #[doc = r""]
23    #[doc = r" # Panics"]
24    #[doc = r""]
25    #[doc = r" If the config startup handle was already taken or if it is not valid."]
26    pub fn take_from_startup_handle() -> Self {
27        <Self as ComponentConfig>::take_from_startup_handle()
28    }
29    #[doc = r" Parse `Self` from `vmo`."]
30    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
31        <Self as ComponentConfig>::from_vmo(vmo)
32    }
33    #[doc = r" Parse `Self` from `bytes`."]
34    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
35        <Self as ComponentConfig>::from_bytes(bytes)
36    }
37    pub fn record_inspect(&self, inspector_node: &Node) {
38        <Self as ComponentConfig>::record_inspect(self, inspector_node)
39    }
40}
41impl ComponentConfig for Config {
42    #[doc = r" Parse `Self` from `bytes`."]
43    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
44        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
45        let checksum_len_bytes: [u8; 2] =
46            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
47        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
48        let (observed_checksum, bytes) =
49            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
50        if observed_checksum != EXPECTED_CHECKSUM {
51            return Err(Error::ChecksumMismatch {
52                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
53                observed_checksum: observed_checksum.to_vec(),
54            });
55        }
56        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
57        Ok(Self {
58            attach_a11y_view: fidl_config.attach_a11y_view,
59            display_pixel_density: fidl_config.display_pixel_density,
60            display_rotation: fidl_config.display_rotation,
61            idle_threshold_ms: fidl_config.idle_threshold_ms,
62            supported_input_devices: fidl_config.supported_input_devices,
63            suspend_enabled: fidl_config.suspend_enabled,
64            viewing_distance: fidl_config.viewing_distance,
65        })
66    }
67    fn record_inspect(&self, inspector_node: &Node) {
68        inspector_node.record_bool("attach_a11y_view", self.attach_a11y_view);
69        inspector_node.record_string("display_pixel_density", &self.display_pixel_density);
70        inspector_node.record_uint("display_rotation", self.display_rotation);
71        inspector_node.record_uint("idle_threshold_ms", self.idle_threshold_ms);
72        let arr = inspector_node
73            .create_string_array("supported_input_devices", self.supported_input_devices.len());
74        for i in 0..self.supported_input_devices.len() {
75            arr.set(i, &self.supported_input_devices[i]);
76        }
77        inspector_node.record(arr);
78        inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
79        inspector_node.record_string("viewing_distance", &self.viewing_distance);
80    }
81}