archivist_config/
archivist-config_rust_config_lib_source.rs1use fidl::unpersist;
2use fidl_cf_sc_internal_archivistconfig::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 0xc6, 0xf6, 0x8a, 0x24, 0xfb, 0x8a, 0x7c, 0xb6, 0x74, 0x9f, 0x02, 0x6a, 0xed, 0x90, 0x3a, 0x22,
8 0xbc, 0xa3, 0x52, 0xec, 0xb9, 0xe9, 0x0c, 0x8b, 0xea, 0xe8, 0x4c, 0xf5, 0xfe, 0xc6, 0xb9, 0x6f,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub allow_serial_logs: Vec<String>,
13 pub bind_services: Vec<String>,
14 pub component_initial_interests: Vec<String>,
15 pub deny_serial_log_tags: Vec<String>,
16 pub enable_klog: bool,
17 pub fuchsia_diagnostics_sample_min_period_seconds: i64,
18 pub logs_max_cached_original_bytes: u64,
19 pub maximum_concurrent_snapshots_per_reader: u64,
20 pub num_threads: u8,
21 pub per_component_batch_timeout_seconds: i64,
22 pub pipelines_path: String,
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 allow_serial_logs: fidl_config.allow_serial_logs,
63 bind_services: fidl_config.bind_services,
64 component_initial_interests: fidl_config.component_initial_interests,
65 deny_serial_log_tags: fidl_config.deny_serial_log_tags,
66 enable_klog: fidl_config.enable_klog,
67 fuchsia_diagnostics_sample_min_period_seconds: fidl_config
68 .fuchsia_diagnostics_sample_min_period_seconds,
69 logs_max_cached_original_bytes: fidl_config.logs_max_cached_original_bytes,
70 maximum_concurrent_snapshots_per_reader: fidl_config
71 .maximum_concurrent_snapshots_per_reader,
72 num_threads: fidl_config.num_threads,
73 per_component_batch_timeout_seconds: fidl_config.per_component_batch_timeout_seconds,
74 pipelines_path: fidl_config.pipelines_path,
75 })
76 }
77 fn record_inspect(&self, inspector_node: &Node) {
78 let arr =
79 inspector_node.create_string_array("allow_serial_logs", self.allow_serial_logs.len());
80 for i in 0..self.allow_serial_logs.len() {
81 arr.set(i, &self.allow_serial_logs[i]);
82 }
83 inspector_node.record(arr);
84 let arr = inspector_node.create_string_array("bind_services", self.bind_services.len());
85 for i in 0..self.bind_services.len() {
86 arr.set(i, &self.bind_services[i]);
87 }
88 inspector_node.record(arr);
89 let arr = inspector_node.create_string_array(
90 "component_initial_interests",
91 self.component_initial_interests.len(),
92 );
93 for i in 0..self.component_initial_interests.len() {
94 arr.set(i, &self.component_initial_interests[i]);
95 }
96 inspector_node.record(arr);
97 let arr = inspector_node
98 .create_string_array("deny_serial_log_tags", self.deny_serial_log_tags.len());
99 for i in 0..self.deny_serial_log_tags.len() {
100 arr.set(i, &self.deny_serial_log_tags[i]);
101 }
102 inspector_node.record(arr);
103 inspector_node.record_bool("enable_klog", self.enable_klog);
104 inspector_node.record_int(
105 "fuchsia_diagnostics_sample_min_period_seconds",
106 self.fuchsia_diagnostics_sample_min_period_seconds,
107 );
108 inspector_node
109 .record_uint("logs_max_cached_original_bytes", self.logs_max_cached_original_bytes);
110 inspector_node.record_uint(
111 "maximum_concurrent_snapshots_per_reader",
112 self.maximum_concurrent_snapshots_per_reader,
113 );
114 inspector_node.record_uint("num_threads", self.num_threads as u64);
115 inspector_node.record_int(
116 "per_component_batch_timeout_seconds",
117 self.per_component_batch_timeout_seconds,
118 );
119 inspector_node.record_string("pipelines_path", &self.pipelines_path);
120 }
121}