#[derive(Debug, Clone, PartialEq)]
pub enum Store {
Tree,
Data,
Bitfield,
Oplog,
}
impl std::fmt::Display for Store {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Store::Tree => write!(f, "tree"),
Store::Data => write!(f, "data"),
Store::Bitfield => write!(f, "bitfield"),
Store::Oplog => write!(f, "oplog"),
}
}
}
#[derive(Debug, PartialEq)]
pub(crate) enum StoreInfoType {
Content,
Size,
}
#[derive(Debug)]
pub(crate) struct StoreInfo {
pub(crate) store: Store,
pub(crate) info_type: StoreInfoType,
pub(crate) index: u64,
pub(crate) length: Option<u64>,
pub(crate) data: Option<Box<[u8]>>,
pub(crate) miss: bool,
}
impl StoreInfo {
pub(crate) fn new_content(store: Store, index: u64, data: &[u8]) -> Self {
Self {
store,
info_type: StoreInfoType::Content,
index,
length: Some(data.len() as u64),
data: Some(data.into()),
miss: false,
}
}
pub(crate) fn new_content_miss(store: Store, index: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Content,
index,
length: None,
data: None,
miss: true,
}
}
pub(crate) fn new_delete(store: Store, index: u64, length: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Content,
index,
length: Some(length),
data: None,
miss: true,
}
}
pub(crate) fn new_truncate(store: Store, index: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Size,
index,
length: None,
data: None,
miss: true,
}
}
pub(crate) fn new_size(store: Store, index: u64, length: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Size,
index,
length: Some(length),
data: None,
miss: false,
}
}
}
#[derive(Debug)]
pub(crate) struct StoreInfoInstruction {
pub(crate) store: Store,
pub(crate) info_type: StoreInfoType,
pub(crate) index: u64,
pub(crate) length: Option<u64>,
pub(crate) allow_miss: bool,
}
impl StoreInfoInstruction {
pub(crate) fn new_content(store: Store, index: u64, length: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Content,
index,
length: Some(length),
allow_miss: false,
}
}
pub(crate) fn new_content_allow_miss(store: Store, index: u64, length: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Content,
index,
length: Some(length),
allow_miss: true,
}
}
pub(crate) fn new_all_content(store: Store) -> Self {
Self {
store,
info_type: StoreInfoType::Content,
index: 0,
length: None,
allow_miss: false,
}
}
pub(crate) fn new_size(store: Store, index: u64) -> Self {
Self {
store,
info_type: StoreInfoType::Size,
index,
length: None,
allow_miss: false,
}
}
}