archivist_config/
archivist-config_rust_config_lib_source.rs

1use 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    0x9c, 0xec, 0xa4, 0xc8, 0xf2, 0x9a, 0x0a, 0xdb, 0x49, 0x30, 0x85, 0x23, 0xca, 0x2b, 0x33, 0xd1,
8    0xaf, 0x76, 0x9e, 0xcc, 0x1a, 0x26, 0xc8, 0xa1, 0x1f, 0x13, 0x1e, 0x05, 0x25, 0x89, 0x04, 0x2c,
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 logs_max_cached_original_bytes: u64,
18    pub maximum_concurrent_snapshots_per_reader: u64,
19    pub num_threads: u8,
20    pub per_component_batch_timeout_seconds: i64,
21    pub pipelines_path: String,
22}
23impl Config {
24    #[doc = r" Take the config startup handle and parse its contents."]
25    #[doc = r""]
26    #[doc = r" # Panics"]
27    #[doc = r""]
28    #[doc = r" If the config startup handle was already taken or if it is not valid."]
29    pub fn take_from_startup_handle() -> Self {
30        <Self as ComponentConfig>::take_from_startup_handle()
31    }
32    #[doc = r" Parse `Self` from `vmo`."]
33    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
34        <Self as ComponentConfig>::from_vmo(vmo)
35    }
36    #[doc = r" Parse `Self` from `bytes`."]
37    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
38        <Self as ComponentConfig>::from_bytes(bytes)
39    }
40    pub fn record_inspect(&self, inspector_node: &Node) {
41        <Self as ComponentConfig>::record_inspect(self, inspector_node)
42    }
43}
44impl ComponentConfig for Config {
45    #[doc = r" Parse `Self` from `bytes`."]
46    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
47        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
48        let checksum_len_bytes: [u8; 2] =
49            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
50        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
51        let (observed_checksum, bytes) =
52            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
53        if observed_checksum != EXPECTED_CHECKSUM {
54            return Err(Error::ChecksumMismatch {
55                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
56                observed_checksum: observed_checksum.to_vec(),
57            });
58        }
59        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
60        Ok(Self {
61            allow_serial_logs: fidl_config.allow_serial_logs,
62            bind_services: fidl_config.bind_services,
63            component_initial_interests: fidl_config.component_initial_interests,
64            deny_serial_log_tags: fidl_config.deny_serial_log_tags,
65            enable_klog: fidl_config.enable_klog,
66            logs_max_cached_original_bytes: fidl_config.logs_max_cached_original_bytes,
67            maximum_concurrent_snapshots_per_reader: fidl_config
68                .maximum_concurrent_snapshots_per_reader,
69            num_threads: fidl_config.num_threads,
70            per_component_batch_timeout_seconds: fidl_config.per_component_batch_timeout_seconds,
71            pipelines_path: fidl_config.pipelines_path,
72        })
73    }
74    fn record_inspect(&self, inspector_node: &Node) {
75        let arr =
76            inspector_node.create_string_array("allow_serial_logs", self.allow_serial_logs.len());
77        for i in 0..self.allow_serial_logs.len() {
78            arr.set(i, &self.allow_serial_logs[i]);
79        }
80        inspector_node.record(arr);
81        let arr = inspector_node.create_string_array("bind_services", self.bind_services.len());
82        for i in 0..self.bind_services.len() {
83            arr.set(i, &self.bind_services[i]);
84        }
85        inspector_node.record(arr);
86        let arr = inspector_node.create_string_array(
87            "component_initial_interests",
88            self.component_initial_interests.len(),
89        );
90        for i in 0..self.component_initial_interests.len() {
91            arr.set(i, &self.component_initial_interests[i]);
92        }
93        inspector_node.record(arr);
94        let arr = inspector_node
95            .create_string_array("deny_serial_log_tags", self.deny_serial_log_tags.len());
96        for i in 0..self.deny_serial_log_tags.len() {
97            arr.set(i, &self.deny_serial_log_tags[i]);
98        }
99        inspector_node.record(arr);
100        inspector_node.record_bool("enable_klog", self.enable_klog);
101        inspector_node
102            .record_uint("logs_max_cached_original_bytes", self.logs_max_cached_original_bytes);
103        inspector_node.record_uint(
104            "maximum_concurrent_snapshots_per_reader",
105            self.maximum_concurrent_snapshots_per_reader,
106        );
107        inspector_node.record_uint("num_threads", self.num_threads as u64);
108        inspector_node.record_int(
109            "per_component_batch_timeout_seconds",
110            self.per_component_batch_timeout_seconds,
111        );
112        inspector_node.record_string("pipelines_path", &self.pipelines_path);
113    }
114}