scene_manager_structured_config/
scene_manager_structured_config_rust_config_lib_source.rs1use 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 0x6a, 0x88, 0x7a, 0x3e, 0x99, 0x89, 0xcb, 0x1d, 0x2f, 0xfa, 0xc0, 0x60, 0xe1, 0x8b, 0x26, 0xd6,
8 0x28, 0xff, 0xf3, 0xed, 0x4d, 0x00, 0x48, 0xed, 0x7b, 0x83, 0x88, 0xdf, 0x61, 0x52, 0xac, 0x1e,
9];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13 pub attach_a11y_view: bool,
14 pub display_pixel_density: String,
15 pub display_rotation: u64,
16 pub enable_merge_touch_events: bool,
17 pub idle_threshold_ms: u64,
18 pub prefetch: bool,
19 pub supported_input_devices: Vec<String>,
20 pub suspend_enabled: bool,
21 pub viewing_distance: String,
22}
23impl Config {
24 #[doc = r" Take the config startup handle and parse its contents."]
25 #[doc = r""]
26 #[doc = r" # Panics"]
27 #[doc = r""]
28 #[doc = r" If the config startup handle was already taken or if it is not valid."]
29 pub fn take_from_startup_handle() -> Self {
30 <Self as ComponentConfig>::take_from_startup_handle()
31 }
32 #[doc = r" Parse `Self` from `vmo`."]
33 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
34 <Self as ComponentConfig>::from_vmo(vmo)
35 }
36 #[doc = r" Parse `Self` from `bytes`."]
37 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
38 <Self as ComponentConfig>::from_bytes(bytes)
39 }
40 pub fn record_inspect(&self, inspector_node: &Node) {
41 <Self as ComponentConfig>::record_inspect(self, inspector_node)
42 }
43}
44impl ComponentConfig for Config {
45 #[doc = r" Parse `Self` from `bytes`."]
46 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
47 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
48 let checksum_len_bytes: [u8; 2] =
49 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
50 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
51 let (observed_checksum, bytes) =
52 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
53 if observed_checksum != EXPECTED_CHECKSUM {
54 return Err(Error::ChecksumMismatch {
55 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
56 observed_checksum: observed_checksum.to_vec(),
57 });
58 }
59 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
60 Ok(Self {
61 attach_a11y_view: fidl_config.attach_a11y_view,
62 display_pixel_density: fidl_config.display_pixel_density,
63 display_rotation: fidl_config.display_rotation,
64 enable_merge_touch_events: fidl_config.enable_merge_touch_events,
65 idle_threshold_ms: fidl_config.idle_threshold_ms,
66 prefetch: fidl_config.prefetch,
67 supported_input_devices: fidl_config.supported_input_devices,
68 suspend_enabled: fidl_config.suspend_enabled,
69 viewing_distance: fidl_config.viewing_distance,
70 })
71 }
72 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
73 let fidl_config = FidlConfig {
74 attach_a11y_view: self.attach_a11y_view.clone(),
75 display_pixel_density: self.display_pixel_density.clone(),
76 display_rotation: self.display_rotation.clone(),
77 enable_merge_touch_events: self.enable_merge_touch_events.clone(),
78 idle_threshold_ms: self.idle_threshold_ms.clone(),
79 prefetch: self.prefetch.clone(),
80 supported_input_devices: self.supported_input_devices.clone(),
81 suspend_enabled: self.suspend_enabled.clone(),
82 viewing_distance: self.viewing_distance.clone(),
83 };
84 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
85 let mut bytes = Vec::with_capacity(
86 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
87 );
88 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
89 bytes.extend_from_slice(EXPECTED_CHECKSUM);
90 bytes.append(&mut fidl_bytes);
91 Ok(bytes)
92 }
93 fn record_inspect(&self, inspector_node: &Node) {
94 inspector_node.record_bool("attach_a11y_view", self.attach_a11y_view);
95 inspector_node.record_string("display_pixel_density", &self.display_pixel_density);
96 inspector_node.record_uint("display_rotation", self.display_rotation);
97 inspector_node.record_bool("enable_merge_touch_events", self.enable_merge_touch_events);
98 inspector_node.record_uint("idle_threshold_ms", self.idle_threshold_ms);
99 inspector_node.record_bool("prefetch", self.prefetch);
100 let arr = inspector_node
101 .create_string_array("supported_input_devices", self.supported_input_devices.len());
102 for i in 0..self.supported_input_devices.len() {
103 arr.set(i, &self.supported_input_devices[i]);
104 }
105 inspector_node.record(arr);
106 inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
107 inspector_node.record_string("viewing_distance", &self.viewing_distance);
108 }
109}