Skip to main content

hfp_profile_config/
hfp_profile_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_hfpprofileconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0x53, 0xda, 0x30, 0x9e, 0x28, 0x16, 0x79, 0x5b, 0xd7, 0x13, 0x34, 0xf3, 0x69, 0xd9, 0x93, 0xc6,
8    0x6b, 0xe4, 0xb4, 0x64, 0x33, 0x20, 0x52, 0xbb, 0x5f, 0x2e, 0x96, 0x72, 0xc9, 0x36, 0xec, 0x3c,
9];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13    pub attach_phone_number_to_voice_tag: bool,
14    pub controller_encoding_cvsd: bool,
15    pub controller_encoding_msbc: bool,
16    pub echo_canceling_and_noise_reduction: bool,
17    pub enhanced_call_controls: bool,
18    pub enhanced_voice_recognition: bool,
19    pub enhanced_voice_recognition_with_text: bool,
20    pub in_band_ringtone: bool,
21    pub offload_type: String,
22    pub reject_incoming_voice_call: bool,
23    pub three_way_calling: bool,
24    pub voice_recognition: bool,
25    pub wide_band_speech: bool,
26}
27impl Config {
28    #[doc = r" Take the config startup handle and parse its contents."]
29    #[doc = r""]
30    #[doc = r" # Panics"]
31    #[doc = r""]
32    #[doc = r" If the config startup handle was already taken or if it is not valid."]
33    pub fn take_from_startup_handle() -> Self {
34        <Self as ComponentConfig>::take_from_startup_handle()
35    }
36    #[doc = r" Parse `Self` from `vmo`."]
37    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
38        <Self as ComponentConfig>::from_vmo(vmo)
39    }
40    #[doc = r" Parse `Self` from `bytes`."]
41    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
42        <Self as ComponentConfig>::from_bytes(bytes)
43    }
44    pub fn record_inspect(&self, inspector_node: &Node) {
45        <Self as ComponentConfig>::record_inspect(self, inspector_node)
46    }
47}
48impl ComponentConfig for Config {
49    #[doc = r" Parse `Self` from `bytes`."]
50    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
51        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
52        let checksum_len_bytes: [u8; 2] =
53            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
54        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
55        let (observed_checksum, bytes) =
56            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
57        if observed_checksum != EXPECTED_CHECKSUM {
58            return Err(Error::ChecksumMismatch {
59                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
60                observed_checksum: observed_checksum.to_vec(),
61            });
62        }
63        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
64        Ok(Self {
65            attach_phone_number_to_voice_tag: fidl_config.attach_phone_number_to_voice_tag,
66            controller_encoding_cvsd: fidl_config.controller_encoding_cvsd,
67            controller_encoding_msbc: fidl_config.controller_encoding_msbc,
68            echo_canceling_and_noise_reduction: fidl_config.echo_canceling_and_noise_reduction,
69            enhanced_call_controls: fidl_config.enhanced_call_controls,
70            enhanced_voice_recognition: fidl_config.enhanced_voice_recognition,
71            enhanced_voice_recognition_with_text: fidl_config.enhanced_voice_recognition_with_text,
72            in_band_ringtone: fidl_config.in_band_ringtone,
73            offload_type: fidl_config.offload_type,
74            reject_incoming_voice_call: fidl_config.reject_incoming_voice_call,
75            three_way_calling: fidl_config.three_way_calling,
76            voice_recognition: fidl_config.voice_recognition,
77            wide_band_speech: fidl_config.wide_band_speech,
78        })
79    }
80    fn to_bytes(&self) -> Result<Vec<u8>, Error> {
81        let fidl_config = FidlConfig {
82            attach_phone_number_to_voice_tag: self.attach_phone_number_to_voice_tag.clone(),
83            controller_encoding_cvsd: self.controller_encoding_cvsd.clone(),
84            controller_encoding_msbc: self.controller_encoding_msbc.clone(),
85            echo_canceling_and_noise_reduction: self.echo_canceling_and_noise_reduction.clone(),
86            enhanced_call_controls: self.enhanced_call_controls.clone(),
87            enhanced_voice_recognition: self.enhanced_voice_recognition.clone(),
88            enhanced_voice_recognition_with_text: self.enhanced_voice_recognition_with_text.clone(),
89            in_band_ringtone: self.in_band_ringtone.clone(),
90            offload_type: self.offload_type.clone(),
91            reject_incoming_voice_call: self.reject_incoming_voice_call.clone(),
92            three_way_calling: self.three_way_calling.clone(),
93            voice_recognition: self.voice_recognition.clone(),
94            wide_band_speech: self.wide_band_speech.clone(),
95        };
96        let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
97        let mut bytes = Vec::with_capacity(
98            EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
99        );
100        bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
101        bytes.extend_from_slice(EXPECTED_CHECKSUM);
102        bytes.append(&mut fidl_bytes);
103        Ok(bytes)
104    }
105    fn record_inspect(&self, inspector_node: &Node) {
106        inspector_node
107            .record_bool("attach_phone_number_to_voice_tag", self.attach_phone_number_to_voice_tag);
108        inspector_node.record_bool("controller_encoding_cvsd", self.controller_encoding_cvsd);
109        inspector_node.record_bool("controller_encoding_msbc", self.controller_encoding_msbc);
110        inspector_node.record_bool(
111            "echo_canceling_and_noise_reduction",
112            self.echo_canceling_and_noise_reduction,
113        );
114        inspector_node.record_bool("enhanced_call_controls", self.enhanced_call_controls);
115        inspector_node.record_bool("enhanced_voice_recognition", self.enhanced_voice_recognition);
116        inspector_node.record_bool(
117            "enhanced_voice_recognition_with_text",
118            self.enhanced_voice_recognition_with_text,
119        );
120        inspector_node.record_bool("in_band_ringtone", self.in_band_ringtone);
121        inspector_node.record_string("offload_type", &self.offload_type);
122        inspector_node.record_bool("reject_incoming_voice_call", self.reject_incoming_voice_call);
123        inspector_node.record_bool("three_way_calling", self.three_way_calling);
124        inspector_node.record_bool("voice_recognition", self.voice_recognition);
125        inspector_node.record_bool("wide_band_speech", self.wide_band_speech);
126    }
127}