osquery_rust_ng/plugin/table/
column_def.rs

1use bitflags::bitflags;
2use strum_macros::Display;
3
4// ColumnDef defines a column used in a table plugin.
5// Prefer using the helper functions to create a ColumnDef.
6#[derive(Clone, Debug)]
7pub struct ColumnDef {
8    name: String,
9    t: ColumnType,
10    o: ColumnOptions,
11}
12
13#[derive(Clone, Display, Debug)]
14#[strum(serialize_all = "UPPERCASE")]
15pub enum ColumnType {
16    // TEXT: containing strings
17    Text,
18    // INTEGER: containing integers
19    Integer,
20    // BIGINT: containing large integers
21    BigInt,
22    // DOUBLE: containing floating point values
23    Double,
24}
25
26bitflags! {
27    #[derive(Clone, Debug, PartialEq, Eq, Hash)]
28    pub struct ColumnOptions: u32 {
29        const DEFAULT = 0;
30        const INDEX = 1;
31        const REQUIRED = 2;
32        const ADDITIONAL = 4;
33        const OPTIMIZED = 8;
34        const HIDDEN = 16;
35        const COLLATEBINARY = 32;
36    }
37}
38
39impl ColumnDef {
40    pub fn new(name: &str, t: ColumnType, o: ColumnOptions) -> Self {
41        ColumnDef {
42            name: name.to_owned(),
43            t,
44            o,
45        }
46    }
47
48    pub(crate) fn name(&self) -> String {
49        self.name.to_string()
50    }
51
52    pub(crate) fn t(&self) -> String {
53        self.t.to_string()
54    }
55
56    pub(crate) fn o(&self) -> String {
57        self.o.bits().to_string()
58    }
59}