binder_proxy_tests_config/
binder_proxy_tests_config_rust_config_lib_source.rs1use fidl::unpersist;
2use fidl_cf_sc_internal_binderproxytestsconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0xbb, 0xba, 0xb1, 0xff, 0x7e, 0x87, 0x4c, 0xf5, 0xb0, 0x5a, 0x83, 0xe6, 0x1c, 0x6e, 0x24, 0x7f,
8 0x24, 0x55, 0x1e, 0xd7, 0xba, 0xeb, 0x4d, 0x3f, 0x1a, 0xda, 0xba, 0x3c, 0xfc, 0xc5, 0x8b, 0xb1,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub expected_uuids: Vec<String>,
13}
14impl Config {
15 #[doc = r" Take the config startup handle and parse its contents."]
16 #[doc = r""]
17 #[doc = r" # Panics"]
18 #[doc = r""]
19 #[doc = r" If the config startup handle was already taken or if it is not valid."]
20 pub fn take_from_startup_handle() -> Self {
21 <Self as ComponentConfig>::take_from_startup_handle()
22 }
23 #[doc = r" Parse `Self` from `vmo`."]
24 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
25 <Self as ComponentConfig>::from_vmo(vmo)
26 }
27 #[doc = r" Parse `Self` from `bytes`."]
28 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
29 <Self as ComponentConfig>::from_bytes(bytes)
30 }
31 pub fn record_inspect(&self, inspector_node: &Node) {
32 <Self as ComponentConfig>::record_inspect(self, inspector_node)
33 }
34}
35impl ComponentConfig for Config {
36 #[doc = r" Parse `Self` from `bytes`."]
37 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
38 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
39 let checksum_len_bytes: [u8; 2] =
40 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
41 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
42 let (observed_checksum, bytes) =
43 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
44 if observed_checksum != EXPECTED_CHECKSUM {
45 return Err(Error::ChecksumMismatch {
46 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
47 observed_checksum: observed_checksum.to_vec(),
48 });
49 }
50 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
51 Ok(Self { expected_uuids: fidl_config.expected_uuids })
52 }
53 fn record_inspect(&self, inspector_node: &Node) {
54 let arr = inspector_node.create_string_array("expected_uuids", self.expected_uuids.len());
55 for i in 0..self.expected_uuids.len() {
56 arr.set(i, &self.expected_uuids[i]);
57 }
58 inspector_node.record(arr);
59 }
60}