pub const FIELD_NAMES: &[&str] = &[
"ts", "ep", "sess_id", "thrd_id", "username", "trx_id", "statement", "appname", "client_ip", "tag", "sql", "exec_time_ms", "row_count", "exec_id", "normalized_sql", ];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FieldMask(pub u16);
impl FieldMask {
pub const ALL: Self = Self(0x7FFF);
pub fn from_names(names: &[String]) -> std::result::Result<Self, String> {
let mut mask = 0u16;
for name in names {
match FIELD_NAMES.iter().position(|&n| n == name.as_str()) {
Some(idx) => mask |= 1u16 << idx,
None => return Err(format!("unknown field: '{name}'")),
}
}
Ok(Self(mask))
}
#[inline]
#[must_use]
pub(crate) fn is_active(self, idx: usize) -> bool {
idx < 15 && (self.0 >> idx) & 1 == 1
}
#[inline]
#[must_use]
pub fn includes_normalized_sql(self) -> bool {
self.is_active(14)
}
}
impl Default for FieldMask {
fn default() -> Self {
Self::ALL
}
}