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 0x17, 0xe4, 0x9c, 0x47, 0x5d, 0x21, 0x45, 0xe2, 0xe3, 0x9f, 0xcf, 0x72, 0x33, 0x07, 0x9a, 0x12,
8 0x27, 0xcc, 0x10, 0x00, 0x74, 0x21, 0xf8, 0x0d, 0x34, 0x80, 0x61, 0xbc, 0xcf, 0x8c, 0x6f, 0x26,
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 pub visual_debugging_level: u8,
23}
24impl Config {
25 #[doc = r" Take the config startup handle and parse its contents."]
26 #[doc = r""]
27 #[doc = r" # Panics"]
28 #[doc = r""]
29 #[doc = r" If the config startup handle was already taken or if it is not valid."]
30 pub fn take_from_startup_handle() -> Self {
31 <Self as ComponentConfig>::take_from_startup_handle()
32 }
33 #[doc = r" Parse `Self` from `vmo`."]
34 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
35 <Self as ComponentConfig>::from_vmo(vmo)
36 }
37 #[doc = r" Parse `Self` from `bytes`."]
38 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
39 <Self as ComponentConfig>::from_bytes(bytes)
40 }
41 pub fn record_inspect(&self, inspector_node: &Node) {
42 <Self as ComponentConfig>::record_inspect(self, inspector_node)
43 }
44}
45impl ComponentConfig for Config {
46 #[doc = r" Parse `Self` from `bytes`."]
47 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
48 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
49 let checksum_len_bytes: [u8; 2] =
50 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
51 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
52 let (observed_checksum, bytes) =
53 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
54 if observed_checksum != EXPECTED_CHECKSUM {
55 return Err(Error::ChecksumMismatch {
56 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
57 observed_checksum: observed_checksum.to_vec(),
58 });
59 }
60 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
61 Ok(Self {
62 attach_a11y_view: fidl_config.attach_a11y_view,
63 display_pixel_density: fidl_config.display_pixel_density,
64 display_rotation: fidl_config.display_rotation,
65 enable_merge_touch_events: fidl_config.enable_merge_touch_events,
66 idle_threshold_ms: fidl_config.idle_threshold_ms,
67 prefetch: fidl_config.prefetch,
68 supported_input_devices: fidl_config.supported_input_devices,
69 suspend_enabled: fidl_config.suspend_enabled,
70 viewing_distance: fidl_config.viewing_distance,
71 visual_debugging_level: fidl_config.visual_debugging_level,
72 })
73 }
74 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
75 let fidl_config = FidlConfig {
76 attach_a11y_view: self.attach_a11y_view.clone(),
77 display_pixel_density: self.display_pixel_density.clone(),
78 display_rotation: self.display_rotation.clone(),
79 enable_merge_touch_events: self.enable_merge_touch_events.clone(),
80 idle_threshold_ms: self.idle_threshold_ms.clone(),
81 prefetch: self.prefetch.clone(),
82 supported_input_devices: self.supported_input_devices.clone(),
83 suspend_enabled: self.suspend_enabled.clone(),
84 viewing_distance: self.viewing_distance.clone(),
85 visual_debugging_level: self.visual_debugging_level.clone(),
86 };
87 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
88 let mut bytes = Vec::with_capacity(
89 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
90 );
91 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
92 bytes.extend_from_slice(EXPECTED_CHECKSUM);
93 bytes.append(&mut fidl_bytes);
94 Ok(bytes)
95 }
96 fn record_inspect(&self, inspector_node: &Node) {
97 inspector_node.record_bool("attach_a11y_view", self.attach_a11y_view);
98 inspector_node.record_string("display_pixel_density", &self.display_pixel_density);
99 inspector_node.record_uint("display_rotation", self.display_rotation);
100 inspector_node.record_bool("enable_merge_touch_events", self.enable_merge_touch_events);
101 inspector_node.record_uint("idle_threshold_ms", self.idle_threshold_ms);
102 inspector_node.record_bool("prefetch", self.prefetch);
103 let arr = inspector_node
104 .create_string_array("supported_input_devices", self.supported_input_devices.len());
105 for i in 0..self.supported_input_devices.len() {
106 arr.set(i, &self.supported_input_devices[i]);
107 }
108 inspector_node.record(arr);
109 inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
110 inspector_node.record_string("viewing_distance", &self.viewing_distance);
111 inspector_node.record_uint("visual_debugging_level", self.visual_debugging_level as u64);
112 }
113}