pkg_resolver_config/
config_lib_rust_config_lib_source.rs1use fidl::unpersist;
2use fidl_cf_sc_internal_pkgresolverconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0x52, 0x0d, 0xab, 0xe2, 0xc1, 0xed, 0xd2, 0xa4, 0xf9, 0x22, 0xdb, 0xd9, 0xce, 0xf0, 0x14, 0x4b,
8 0x63, 0xd9, 0x3a, 0x26, 0x20, 0xe7, 0x55, 0x74, 0x96, 0x4f, 0x06, 0x07, 0x03, 0x48, 0xac, 0x28,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub blob_download_concurrency_limit: u16,
13 pub blob_download_resumption_attempts_limit: u32,
14 pub blob_network_body_timeout_seconds: u32,
15 pub blob_network_header_timeout_seconds: u32,
16 pub delivery_blob_type: u32,
17 pub tuf_metadata_timeout_seconds: u32,
18}
19impl Config {
20 #[doc = r" Take the config startup handle and parse its contents."]
21 #[doc = r""]
22 #[doc = r" # Panics"]
23 #[doc = r""]
24 #[doc = r" If the config startup handle was already taken or if it is not valid."]
25 pub fn take_from_startup_handle() -> Self {
26 <Self as ComponentConfig>::take_from_startup_handle()
27 }
28 #[doc = r" Parse `Self` from `vmo`."]
29 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
30 <Self as ComponentConfig>::from_vmo(vmo)
31 }
32 #[doc = r" Parse `Self` from `bytes`."]
33 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
34 <Self as ComponentConfig>::from_bytes(bytes)
35 }
36 pub fn record_inspect(&self, inspector_node: &Node) {
37 <Self as ComponentConfig>::record_inspect(self, inspector_node)
38 }
39}
40impl ComponentConfig for Config {
41 #[doc = r" Parse `Self` from `bytes`."]
42 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
43 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
44 let checksum_len_bytes: [u8; 2] =
45 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
46 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
47 let (observed_checksum, bytes) =
48 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
49 if observed_checksum != EXPECTED_CHECKSUM {
50 return Err(Error::ChecksumMismatch {
51 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
52 observed_checksum: observed_checksum.to_vec(),
53 });
54 }
55 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
56 Ok(Self {
57 blob_download_concurrency_limit: fidl_config.blob_download_concurrency_limit,
58 blob_download_resumption_attempts_limit: fidl_config
59 .blob_download_resumption_attempts_limit,
60 blob_network_body_timeout_seconds: fidl_config.blob_network_body_timeout_seconds,
61 blob_network_header_timeout_seconds: fidl_config.blob_network_header_timeout_seconds,
62 delivery_blob_type: fidl_config.delivery_blob_type,
63 tuf_metadata_timeout_seconds: fidl_config.tuf_metadata_timeout_seconds,
64 })
65 }
66 fn record_inspect(&self, inspector_node: &Node) {
67 inspector_node.record_uint(
68 "blob_download_concurrency_limit",
69 self.blob_download_concurrency_limit as u64,
70 );
71 inspector_node.record_uint(
72 "blob_download_resumption_attempts_limit",
73 self.blob_download_resumption_attempts_limit as u64,
74 );
75 inspector_node.record_uint(
76 "blob_network_body_timeout_seconds",
77 self.blob_network_body_timeout_seconds as u64,
78 );
79 inspector_node.record_uint(
80 "blob_network_header_timeout_seconds",
81 self.blob_network_header_timeout_seconds as u64,
82 );
83 inspector_node.record_uint("delivery_blob_type", self.delivery_blob_type as u64);
84 inspector_node
85 .record_uint("tuf_metadata_timeout_seconds", self.tuf_metadata_timeout_seconds as u64);
86 }
87}