httpsdate_config/
httpsdate_config_rust_config_lib_source.rs
1use fidl::unpersist;
2use fidl_cf_sc_internal_httpsdateconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0x47, 0x9d, 0xa0, 0xef, 0x6a, 0xf6, 0xb8, 0xac, 0x91, 0xd9, 0x20, 0xb6, 0xe9, 0x78, 0x94, 0xb6,
8 0x0a, 0xbf, 0x2c, 0x4f, 0x88, 0x4e, 0xa1, 0xdc, 0x15, 0x86, 0xae, 0x9e, 0x97, 0x2f, 0x1c, 0x6f,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub first_rtt_time_factor: u16,
13 pub https_timeout_sec: u8,
14 pub max_attempts_urgency_high: u32,
15 pub max_attempts_urgency_low: u32,
16 pub max_attempts_urgency_medium: u32,
17 pub num_polls_urgency_high: u32,
18 pub num_polls_urgency_low: u32,
19 pub num_polls_urgency_medium: u32,
20 pub standard_deviation_bound_percentage: u8,
21 pub time_source_endpoint_url: String,
22 pub use_pull_api: bool,
23}
24impl Config {
25 #[doc = r" Take the config startup handle and parse its contents."]
26 #[doc = r""]
27 #[doc = r" # Panics"]
28 #[doc = r""]
29 #[doc = r" If the config startup handle was already taken or if it is not valid."]
30 pub fn take_from_startup_handle() -> Self {
31 <Self as ComponentConfig>::take_from_startup_handle()
32 }
33 #[doc = r" Parse `Self` from `vmo`."]
34 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
35 <Self as ComponentConfig>::from_vmo(vmo)
36 }
37 #[doc = r" Parse `Self` from `bytes`."]
38 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
39 <Self as ComponentConfig>::from_bytes(bytes)
40 }
41 pub fn record_inspect(&self, inspector_node: &Node) {
42 <Self as ComponentConfig>::record_inspect(self, inspector_node)
43 }
44}
45impl ComponentConfig for Config {
46 #[doc = r" Parse `Self` from `bytes`."]
47 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
48 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
49 let checksum_len_bytes: [u8; 2] =
50 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
51 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
52 let (observed_checksum, bytes) =
53 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
54 if observed_checksum != EXPECTED_CHECKSUM {
55 return Err(Error::ChecksumMismatch {
56 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
57 observed_checksum: observed_checksum.to_vec(),
58 });
59 }
60 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
61 Ok(Self {
62 first_rtt_time_factor: fidl_config.first_rtt_time_factor,
63 https_timeout_sec: fidl_config.https_timeout_sec,
64 max_attempts_urgency_high: fidl_config.max_attempts_urgency_high,
65 max_attempts_urgency_low: fidl_config.max_attempts_urgency_low,
66 max_attempts_urgency_medium: fidl_config.max_attempts_urgency_medium,
67 num_polls_urgency_high: fidl_config.num_polls_urgency_high,
68 num_polls_urgency_low: fidl_config.num_polls_urgency_low,
69 num_polls_urgency_medium: fidl_config.num_polls_urgency_medium,
70 standard_deviation_bound_percentage: fidl_config.standard_deviation_bound_percentage,
71 time_source_endpoint_url: fidl_config.time_source_endpoint_url,
72 use_pull_api: fidl_config.use_pull_api,
73 })
74 }
75 fn record_inspect(&self, inspector_node: &Node) {
76 inspector_node.record_uint("first_rtt_time_factor", self.first_rtt_time_factor as u64);
77 inspector_node.record_uint("https_timeout_sec", self.https_timeout_sec as u64);
78 inspector_node
79 .record_uint("max_attempts_urgency_high", self.max_attempts_urgency_high as u64);
80 inspector_node
81 .record_uint("max_attempts_urgency_low", self.max_attempts_urgency_low as u64);
82 inspector_node
83 .record_uint("max_attempts_urgency_medium", self.max_attempts_urgency_medium as u64);
84 inspector_node.record_uint("num_polls_urgency_high", self.num_polls_urgency_high as u64);
85 inspector_node.record_uint("num_polls_urgency_low", self.num_polls_urgency_low as u64);
86 inspector_node
87 .record_uint("num_polls_urgency_medium", self.num_polls_urgency_medium as u64);
88 inspector_node.record_uint(
89 "standard_deviation_bound_percentage",
90 self.standard_deviation_bound_percentage as u64,
91 );
92 inspector_node.record_string("time_source_endpoint_url", &self.time_source_endpoint_url);
93 inspector_node.record_bool("use_pull_api", self.use_pull_api);
94 }
95}