wedb_embed 0.1.2

Embedded database engine providing Redis-like APIs, built on fjall / 嵌入式数据库引擎,提供类似 Redis 的接口,底层基于 fjall 开发
Documentation
use crate::key_composer::{KeyComposer, KeyTag, SmallKey};

/// 栈上定长构造 TimeSeries 元数据键(零堆分配)
#[inline]
pub fn meta(kc: &KeyComposer<'_>, key: &[u8]) -> SmallKey {
  kc.compose_meta_key_stack(KeyTag::TimeSeriesMeta.as_slice(), key)
}

/// 构造 TimeSeries 元数据前缀
#[inline]
pub fn meta_prefix(kc: &KeyComposer<'_>) -> Vec<u8> {
  kc.compose_meta_prefix(KeyTag::TimeSeriesMeta.as_slice())
}

/// 栈上定长构造 TimeSeries 数据分块存储键(零堆分配,大端序紧凑保序 8 字节)
#[inline]
pub fn item(kc: &KeyComposer<'_>, key: &[u8], timestamp: u64) -> SmallKey {
  kc.compose_subkey_stack(
    KeyTag::TimeSeriesData.as_slice(),
    key,
    &timestamp.to_be_bytes(),
  )
}

/// 构造 TimeSeries 数据前缀
#[inline]
pub fn prefix(kc: &KeyComposer<'_>, key: &[u8]) -> Vec<u8> {
  kc.compose_prefix(KeyTag::TimeSeriesData.as_slice(), key)
}

/// 栈上定长构造 TimeSeries 数据前缀(零堆分配)
#[inline]
pub fn prefix_stack(kc: &KeyComposer<'_>, key: &[u8]) -> SmallKey {
  kc.compose_prefix_stack(KeyTag::TimeSeriesData.as_slice(), key)
}

/// 栈上定长构造 TimeSeries 下游压实规则元数据键(零堆分配)
#[inline]
pub fn downstream_meta(kc: &KeyComposer<'_>, src_key: &[u8], dst_key: &[u8]) -> SmallKey {
  kc.compose_subkey2_stack(KeyTag::TimeSeriesData.as_slice(), src_key, b"\xFF", dst_key)
}

/// 构造 TimeSeries 下游压实规则前缀
#[inline]
pub fn downstream_prefix(kc: &KeyComposer<'_>, src_key: &[u8]) -> Vec<u8> {
  let mut buf = Vec::new();
  kc.compose_prefix_into_with_extra(KeyTag::TimeSeriesData.as_slice(), src_key, 1, &mut buf);
  buf.push(0xFF);
  buf
}