use crate::io::{AKey, DKey};
use daos::daos_recx_t;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct QueryKeyFlags(u64);
impl QueryKeyFlags {
pub const GET_MAX: Self = Self(1 << 0);
pub const GET_MIN: Self = Self(1 << 1);
pub const GET_DKEY: Self = Self(1 << 2);
pub const GET_AKEY: Self = Self(1 << 3);
pub const GET_RECX: Self = Self(1 << 4);
pub fn is_empty(self) -> bool {
self.0 == 0
}
pub fn contains(self, other: Self) -> bool {
(self.0 & other.0) != 0
}
pub fn as_raw(self) -> u64 {
self.0
}
}
impl std::ops::BitOr for QueryKeyFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
#[derive(Debug, Clone)]
pub struct QueryKeyResult {
pub dkey: Option<DKey>,
pub akey: Option<AKey>,
pub recx: Option<daos_recx_t>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct QueryEpochResult {
pub epoch: u64,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_query_key_flags_constants() {
assert_eq!(QueryKeyFlags::GET_MAX.0, 1 << 0);
assert_eq!(QueryKeyFlags::GET_MIN.0, 1 << 1);
assert_eq!(QueryKeyFlags::GET_DKEY.0, 1 << 2);
assert_eq!(QueryKeyFlags::GET_AKEY.0, 1 << 3);
assert_eq!(QueryKeyFlags::GET_RECX.0, 1 << 4);
}
#[test]
fn test_query_key_flags_contains() {
let flags = QueryKeyFlags::GET_DKEY | QueryKeyFlags::GET_AKEY;
assert!(flags.contains(QueryKeyFlags::GET_DKEY));
assert!(flags.contains(QueryKeyFlags::GET_AKEY));
assert!(!flags.contains(QueryKeyFlags::GET_MAX));
}
#[test]
fn test_query_key_flags_is_empty() {
assert!(QueryKeyFlags::default().is_empty());
assert!(!QueryKeyFlags::GET_MAX.is_empty());
}
}