Skip to main content

systemconfiguration/
schema.rs

1use std::collections::BTreeMap;
2
3use serde::Deserialize;
4
5use crate::{bridge, error::Result, ffi};
6
7#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
8/// Wraps grouped symbols from `SCSchemaDefinitions.h`.
9pub struct SchemaCatalog {
10    /// Wraps all exported symbols from `SCSchemaDefinitions.h`.
11    pub all: BTreeMap<String, String>,
12    /// Wraps reserved symbols from `SCSchemaDefinitions.h`.
13    pub reserved: BTreeMap<String, String>,
14    /// Wraps preference symbols from `SCSchemaDefinitions.h`.
15    pub preferences: BTreeMap<String, String>,
16    /// Wraps component symbols from `SCSchemaDefinitions.h`.
17    pub components: BTreeMap<String, String>,
18    /// Wraps entity symbols from `SCSchemaDefinitions.h`.
19    pub entities: BTreeMap<String, String>,
20    /// Wraps generic property symbols from `SCSchemaDefinitions.h`.
21    pub generic_properties: BTreeMap<String, String>,
22    /// Wraps IPv4 symbols from `SCSchemaDefinitions.h`.
23    pub ipv4: BTreeMap<String, String>,
24    /// Wraps IPv6 symbols from `SCSchemaDefinitions.h`.
25    pub ipv6: BTreeMap<String, String>,
26    /// Wraps DNS symbols from `SCSchemaDefinitions.h`.
27    pub dns: BTreeMap<String, String>,
28    /// Wraps proxy symbols from `SCSchemaDefinitions.h`.
29    pub proxies: BTreeMap<String, String>,
30    /// Wraps interface-type symbols from `SCSchemaDefinitions.h`.
31    pub interface_types: BTreeMap<String, String>,
32}
33
34impl SchemaCatalog {
35    /// Wraps symbol lookup within `SCSchemaDefinitions.h`.
36    pub fn get(&self, symbol: &str) -> Option<&str> {
37        self.all.get(symbol).map(String::as_str)
38    }
39
40    /// Wraps symbol membership checks within `SCSchemaDefinitions.h`.
41    pub fn contains(&self, symbol: &str) -> bool {
42        self.all.contains_key(symbol)
43    }
44}
45
46#[derive(Clone, Copy, Debug, Default)]
47/// Wraps the `SCSchemaDefinitions.h` catalog helpers.
48pub struct Schema;
49
50impl Schema {
51    /// Wraps grouped constants from `SCSchemaDefinitions.h`.
52    pub fn catalog() -> Result<SchemaCatalog> {
53        bridge::parse_json("sc_schema_copy_catalog", unsafe {
54            ffi::schema::sc_schema_copy_catalog()
55        })
56    }
57}