hfp_profile_config/
hfp_profile_config_rust_config_lib_source.rs1use 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 0x46, 0xab, 0x33, 0x80, 0x14, 0x07, 0x6b, 0x51, 0x87, 0x91, 0x23, 0x0d, 0x57, 0xb2, 0xff, 0xf9,
8 0xa1, 0xdf, 0xea, 0xf1, 0x2c, 0xa0, 0x82, 0xe8, 0x5b, 0x59, 0xec, 0x83, 0x52, 0x7f, 0xf9, 0xc9,
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 offload_type: String,
19 pub reject_incoming_voice_call: bool,
20 pub three_way_calling: bool,
21 pub wide_band_speech: bool,
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_phone_number_to_voice_tag: fidl_config.attach_phone_number_to_voice_tag,
62 controller_encoding_cvsd: fidl_config.controller_encoding_cvsd,
63 controller_encoding_msbc: fidl_config.controller_encoding_msbc,
64 echo_canceling_and_noise_reduction: fidl_config.echo_canceling_and_noise_reduction,
65 enhanced_call_controls: fidl_config.enhanced_call_controls,
66 offload_type: fidl_config.offload_type,
67 reject_incoming_voice_call: fidl_config.reject_incoming_voice_call,
68 three_way_calling: fidl_config.three_way_calling,
69 wide_band_speech: fidl_config.wide_band_speech,
70 })
71 }
72 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
73 let fidl_config = FidlConfig {
74 attach_phone_number_to_voice_tag: self.attach_phone_number_to_voice_tag.clone(),
75 controller_encoding_cvsd: self.controller_encoding_cvsd.clone(),
76 controller_encoding_msbc: self.controller_encoding_msbc.clone(),
77 echo_canceling_and_noise_reduction: self.echo_canceling_and_noise_reduction.clone(),
78 enhanced_call_controls: self.enhanced_call_controls.clone(),
79 offload_type: self.offload_type.clone(),
80 reject_incoming_voice_call: self.reject_incoming_voice_call.clone(),
81 three_way_calling: self.three_way_calling.clone(),
82 wide_band_speech: self.wide_band_speech.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
95 .record_bool("attach_phone_number_to_voice_tag", self.attach_phone_number_to_voice_tag);
96 inspector_node.record_bool("controller_encoding_cvsd", self.controller_encoding_cvsd);
97 inspector_node.record_bool("controller_encoding_msbc", self.controller_encoding_msbc);
98 inspector_node.record_bool(
99 "echo_canceling_and_noise_reduction",
100 self.echo_canceling_and_noise_reduction,
101 );
102 inspector_node.record_bool("enhanced_call_controls", self.enhanced_call_controls);
103 inspector_node.record_string("offload_type", &self.offload_type);
104 inspector_node.record_bool("reject_incoming_voice_call", self.reject_incoming_voice_call);
105 inspector_node.record_bool("three_way_calling", self.three_way_calling);
106 inspector_node.record_bool("wide_band_speech", self.wide_band_speech);
107 }
108}