session_manager_config/
session_manager_config_rust_config_lib_source.rs1use fidl::unpersist;
2use fidl_cf_sc_internal_sessionmanagerconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0x42, 0x2c, 0xf0, 0x81, 0x50, 0xac, 0x71, 0xf7, 0x99, 0xf3, 0x6e, 0x3b, 0x04, 0x8d, 0xf9, 0xf9,
8 0x11, 0x2c, 0x8d, 0x14, 0x79, 0xf0, 0xff, 0xd7, 0x58, 0x78, 0x69, 0x49, 0xab, 0x8d, 0x38, 0x95,
9];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13 pub autolaunch: bool,
14 pub enable_debug_shortcut: bool,
15 pub session_url: String,
16 pub suspend_enabled: bool,
17}
18impl Config {
19 #[doc = r" Take the config startup handle and parse its contents."]
20 #[doc = r""]
21 #[doc = r" # Panics"]
22 #[doc = r""]
23 #[doc = r" If the config startup handle was already taken or if it is not valid."]
24 pub fn take_from_startup_handle() -> Self {
25 <Self as ComponentConfig>::take_from_startup_handle()
26 }
27 #[doc = r" Parse `Self` from `vmo`."]
28 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
29 <Self as ComponentConfig>::from_vmo(vmo)
30 }
31 #[doc = r" Parse `Self` from `bytes`."]
32 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
33 <Self as ComponentConfig>::from_bytes(bytes)
34 }
35 pub fn record_inspect(&self, inspector_node: &Node) {
36 <Self as ComponentConfig>::record_inspect(self, inspector_node)
37 }
38}
39impl ComponentConfig for Config {
40 #[doc = r" Parse `Self` from `bytes`."]
41 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
42 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
43 let checksum_len_bytes: [u8; 2] =
44 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
45 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
46 let (observed_checksum, bytes) =
47 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
48 if observed_checksum != EXPECTED_CHECKSUM {
49 return Err(Error::ChecksumMismatch {
50 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
51 observed_checksum: observed_checksum.to_vec(),
52 });
53 }
54 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
55 Ok(Self {
56 autolaunch: fidl_config.autolaunch,
57 enable_debug_shortcut: fidl_config.enable_debug_shortcut,
58 session_url: fidl_config.session_url,
59 suspend_enabled: fidl_config.suspend_enabled,
60 })
61 }
62 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
63 let fidl_config = FidlConfig {
64 autolaunch: self.autolaunch.clone(),
65 enable_debug_shortcut: self.enable_debug_shortcut.clone(),
66 session_url: self.session_url.clone(),
67 suspend_enabled: self.suspend_enabled.clone(),
68 };
69 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
70 let mut bytes = Vec::with_capacity(
71 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
72 );
73 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
74 bytes.extend_from_slice(EXPECTED_CHECKSUM);
75 bytes.append(&mut fidl_bytes);
76 Ok(bytes)
77 }
78 fn record_inspect(&self, inspector_node: &Node) {
79 inspector_node.record_bool("autolaunch", self.autolaunch);
80 inspector_node.record_bool("enable_debug_shortcut", self.enable_debug_shortcut);
81 inspector_node.record_string("session_url", &self.session_url);
82 inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
83 }
84}