use crate::key_composer::{KeyComposer, KeyTag, SmallKey, encode_oppv_u64};
#[inline]
pub fn meta(kc: &KeyComposer<'_>, key: &[u8]) -> SmallKey {
kc.compose_meta_key_stack(KeyTag::StreamMeta.as_slice(), key)
}
#[inline]
pub fn item(kc: &KeyComposer<'_>, key: &[u8], ms: u64, seq: u64) -> SmallKey {
kc.compose_subkey2_stack(
KeyTag::StreamData.as_slice(),
key,
&ms.to_be_bytes(),
&seq.to_be_bytes(),
)
}
#[inline]
pub fn prefix(kc: &KeyComposer<'_>, key: &[u8]) -> Vec<u8> {
kc.compose_prefix(KeyTag::StreamData.as_slice(), key)
}
#[inline]
pub fn prefix_stack(kc: &KeyComposer<'_>, key: &[u8]) -> SmallKey {
kc.compose_prefix_stack(KeyTag::StreamData.as_slice(), key)
}
#[inline]
pub fn group_meta(kc: &KeyComposer<'_>, key: &[u8], group: &[u8]) -> SmallKey {
kc.compose_subkey_stack(KeyTag::StreamGroup.as_slice(), key, group)
}
#[inline]
pub fn group_prefix(kc: &KeyComposer<'_>, key: &[u8]) -> Vec<u8> {
kc.compose_prefix(KeyTag::StreamGroup.as_slice(), key)
}
#[inline]
pub fn group_prefix_stack(kc: &KeyComposer<'_>, key: &[u8]) -> SmallKey {
kc.compose_prefix_stack(KeyTag::StreamGroup.as_slice(), key)
}
#[inline]
pub fn consumer_meta(kc: &KeyComposer<'_>, key: &[u8], group: &[u8], consumer: &[u8]) -> SmallKey {
kc.compose_oppv_subkey_stack(KeyTag::StreamConsumer.as_slice(), key, group, consumer)
}
#[inline]
pub fn consumer_prefix(kc: &KeyComposer<'_>, key: &[u8], group: &[u8]) -> Vec<u8> {
let mut buf = Vec::new();
kc.compose_prefix_into_with_extra(
KeyTag::StreamConsumer.as_slice(),
key,
9 + group.len(),
&mut buf,
);
encode_oppv_u64(group.len() as u64, &mut buf);
buf.extend_from_slice(group);
buf
}
#[inline]
pub fn consumer_prefix_all(kc: &KeyComposer<'_>, key: &[u8]) -> Vec<u8> {
kc.compose_prefix(KeyTag::StreamConsumer.as_slice(), key)
}
#[inline]
pub fn pel_item(kc: &KeyComposer<'_>, key: &[u8], group: &[u8], ms: u64, seq: u64) -> SmallKey {
let mut id = [0u8; 16];
id[..8].copy_from_slice(&ms.to_be_bytes());
id[8..].copy_from_slice(&seq.to_be_bytes());
kc.compose_oppv_subkey_stack(KeyTag::StreamPel.as_slice(), key, group, &id)
}
#[inline]
pub fn pel_prefix(kc: &KeyComposer<'_>, key: &[u8], group: &[u8]) -> Vec<u8> {
let mut buf = Vec::new();
kc.compose_prefix_into_with_extra(KeyTag::StreamPel.as_slice(), key, 9 + group.len(), &mut buf);
encode_oppv_u64(group.len() as u64, &mut buf);
buf.extend_from_slice(group);
buf
}
#[inline]
pub fn pel_prefix_all(kc: &KeyComposer<'_>, key: &[u8]) -> Vec<u8> {
kc.compose_prefix(KeyTag::StreamPel.as_slice(), key)
}