use gnitz_wire::TypeCode;
use gnitz_zset::schema::{key_prefixed_schema, SchemaColumn, SchemaDescriptor};
const DELTA_TICK_COL: SchemaColumn = SchemaColumn::new(TypeCode::U64, false);
const _: () = assert!(DELTA_TICK_COL.size() as usize == 8);
pub(crate) fn delta_round_prefix(round: u64) -> [u8; 8] {
round.to_be_bytes()
}
pub(crate) fn delta_round(delta_key: &[u8]) -> u64 {
let tick = &delta_key[..DELTA_TICK_COL.size() as usize];
u64::from_be_bytes(tick.try_into().expect("a delta key leads with its round"))
}
pub(crate) fn make_delta_schema(view: &SchemaDescriptor) -> Option<SchemaDescriptor> {
key_prefixed_schema(DELTA_TICK_COL, view)
}
const _: () = assert!(
gnitz_wire::PK_LIST_MAX_COLS < gnitz_wire::MAX_PK_COLUMNS,
"a _tick stamp on the widest view PK no longer fits the PK limits"
);
#[cfg(test)]
#[path = "tests/delta.rs"]
mod tests;