dm_database_sqllog2db/pipeline/
field_mask.rs1pub const FIELD_NAMES: &[&str] = &[
3 "ts", "ep", "sess_id", "thrd_id", "username", "trx_id", "statement", "appname", "client_ip", "tag", "sql", "exec_time_ms", "row_count", "exec_id", "normalized_sql", ];
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct FieldMask(pub u16);
23
24impl FieldMask {
25 pub const ALL: Self = Self(0x7FFF);
27
28 pub fn from_names(names: &[String]) -> std::result::Result<Self, String> {
30 let mut mask = 0u16;
31 for name in names {
32 match FIELD_NAMES.iter().position(|&n| n == name.as_str()) {
33 Some(idx) => mask |= 1u16 << idx,
34 None => return Err(format!("unknown field: '{name}'")),
35 }
36 }
37 Ok(Self(mask))
38 }
39
40 #[inline]
42 #[must_use]
43 pub(crate) fn is_active(self, idx: usize) -> bool {
44 idx < 15 && (self.0 >> idx) & 1 == 1
45 }
46
47 #[inline]
49 #[must_use]
50 pub fn includes_normalized_sql(self) -> bool {
51 self.is_active(14)
52 }
53}
54
55impl Default for FieldMask {
56 fn default() -> Self {
57 Self::ALL
58 }
59}