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 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];
10#[derive(Debug)]
11pub struct Config {
12 pub attach_phone_number_to_voice_tag: bool,
13 pub controller_encoding_cvsd: bool,
14 pub controller_encoding_msbc: bool,
15 pub echo_canceling_and_noise_reduction: bool,
16 pub enhanced_call_controls: bool,
17 pub enhanced_voice_recognition: bool,
18 pub enhanced_voice_recognition_with_text: bool,
19 pub in_band_ringtone: bool,
20 pub offload_type: String,
21 pub reject_incoming_voice_call: bool,
22 pub three_way_calling: bool,
23 pub voice_recognition: bool,
24 pub wide_band_speech: bool,
25}
26impl Config {
27 #[doc = r" Take the config startup handle and parse its contents."]
28 #[doc = r""]
29 #[doc = r" # Panics"]
30 #[doc = r""]
31 #[doc = r" If the config startup handle was already taken or if it is not valid."]
32 pub fn take_from_startup_handle() -> Self {
33 <Self as ComponentConfig>::take_from_startup_handle()
34 }
35 #[doc = r" Parse `Self` from `vmo`."]
36 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
37 <Self as ComponentConfig>::from_vmo(vmo)
38 }
39 #[doc = r" Parse `Self` from `bytes`."]
40 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
41 <Self as ComponentConfig>::from_bytes(bytes)
42 }
43 pub fn record_inspect(&self, inspector_node: &Node) {
44 <Self as ComponentConfig>::record_inspect(self, inspector_node)
45 }
46}
47impl ComponentConfig for Config {
48 #[doc = r" Parse `Self` from `bytes`."]
49 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
50 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
51 let checksum_len_bytes: [u8; 2] =
52 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
53 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
54 let (observed_checksum, bytes) =
55 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
56 if observed_checksum != EXPECTED_CHECKSUM {
57 return Err(Error::ChecksumMismatch {
58 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
59 observed_checksum: observed_checksum.to_vec(),
60 });
61 }
62 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
63 Ok(Self {
64 attach_phone_number_to_voice_tag: fidl_config.attach_phone_number_to_voice_tag,
65 controller_encoding_cvsd: fidl_config.controller_encoding_cvsd,
66 controller_encoding_msbc: fidl_config.controller_encoding_msbc,
67 echo_canceling_and_noise_reduction: fidl_config.echo_canceling_and_noise_reduction,
68 enhanced_call_controls: fidl_config.enhanced_call_controls,
69 enhanced_voice_recognition: fidl_config.enhanced_voice_recognition,
70 enhanced_voice_recognition_with_text: fidl_config.enhanced_voice_recognition_with_text,
71 in_band_ringtone: fidl_config.in_band_ringtone,
72 offload_type: fidl_config.offload_type,
73 reject_incoming_voice_call: fidl_config.reject_incoming_voice_call,
74 three_way_calling: fidl_config.three_way_calling,
75 voice_recognition: fidl_config.voice_recognition,
76 wide_band_speech: fidl_config.wide_band_speech,
77 })
78 }
79 fn record_inspect(&self, inspector_node: &Node) {
80 inspector_node
81 .record_bool("attach_phone_number_to_voice_tag", self.attach_phone_number_to_voice_tag);
82 inspector_node.record_bool("controller_encoding_cvsd", self.controller_encoding_cvsd);
83 inspector_node.record_bool("controller_encoding_msbc", self.controller_encoding_msbc);
84 inspector_node.record_bool(
85 "echo_canceling_and_noise_reduction",
86 self.echo_canceling_and_noise_reduction,
87 );
88 inspector_node.record_bool("enhanced_call_controls", self.enhanced_call_controls);
89 inspector_node.record_bool("enhanced_voice_recognition", self.enhanced_voice_recognition);
90 inspector_node.record_bool(
91 "enhanced_voice_recognition_with_text",
92 self.enhanced_voice_recognition_with_text,
93 );
94 inspector_node.record_bool("in_band_ringtone", self.in_band_ringtone);
95 inspector_node.record_string("offload_type", &self.offload_type);
96 inspector_node.record_bool("reject_incoming_voice_call", self.reject_incoming_voice_call);
97 inspector_node.record_bool("three_way_calling", self.three_way_calling);
98 inspector_node.record_bool("voice_recognition", self.voice_recognition);
99 inspector_node.record_bool("wide_band_speech", self.wide_band_speech);
100 }
101}