a2dp_profile_config/
a2dp_profile_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_a2dpprofileconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0x86, 0xf7, 0xab, 0x7e, 0x80, 0xb6, 0x5f, 0x16, 0x55, 0xf7, 0xf1, 0x51, 0x01, 0xd5, 0xd1, 0x1e,
8    0xb5, 0x19, 0xbb, 0xa3, 0xc4, 0x27, 0x1e, 0xd5, 0xfd, 0x77, 0xfc, 0xa2, 0x47, 0x24, 0x96, 0x85,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub channel_mode: String,
13    pub domain: String,
14    pub enable_aac: bool,
15    pub enable_avrcp_target: bool,
16    pub enable_sink: bool,
17    pub initiator_delay: u32,
18    pub source_type: 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            channel_mode: fidl_config.channel_mode,
59            domain: fidl_config.domain,
60            enable_aac: fidl_config.enable_aac,
61            enable_avrcp_target: fidl_config.enable_avrcp_target,
62            enable_sink: fidl_config.enable_sink,
63            initiator_delay: fidl_config.initiator_delay,
64            source_type: fidl_config.source_type,
65        })
66    }
67    fn record_inspect(&self, inspector_node: &Node) {
68        inspector_node.record_string("channel_mode", &self.channel_mode);
69        inspector_node.record_string("domain", &self.domain);
70        inspector_node.record_bool("enable_aac", self.enable_aac);
71        inspector_node.record_bool("enable_avrcp_target", self.enable_avrcp_target);
72        inspector_node.record_bool("enable_sink", self.enable_sink);
73        inspector_node.record_uint("initiator_delay", self.initiator_delay as u64);
74        inspector_node.record_string("source_type", &self.source_type);
75    }
76}