pub mod compression;
pub mod decompression;
mod traits;
use std::os::raw::c_uint;
use traits::CType;
#[derive(Clone, Copy, Debug)]
pub struct TableUpdateRate(pub(crate) u32);
impl TableUpdateRate {
pub const FAST: TableUpdateRate = TableUpdateRate(20);
pub const DEFAULT: TableUpdateRate = TableUpdateRate(8);
pub const SLOW: TableUpdateRate = TableUpdateRate(2);
pub const VERY_SLOW: TableUpdateRate = TableUpdateRate(1);
pub fn new(rate: u32) -> Self {
if rate > Self::FAST.0 {
Self::FAST
} else if rate > Self::VERY_SLOW.0 {
Self::VERY_SLOW
} else {
Self(rate)
}
}
pub fn table_update_settings(&self) -> TableUpdateInterval {
let (max, slow) = match self.0 {
1 => (4, 32),
2 => (5, 33),
3 => (6, 34),
4 => (7, 35),
5 => (8, 36),
6 => (16, 48),
7 => (32, 72),
8 => (64, 64),
9 => (98, 80),
10 => (128, 96),
11 => (192, 112),
12 => (256, 128),
13 => (512, 160),
14 => (1024, 192),
15 => (2048, 224),
16 => (2048, 128 + (16 * 8)),
17 => (2048, 128 + (16 * 10)),
18 => (2048, 128 + (16 * 12)),
19 => (2048, 128 + (16 * 14)),
20 => (2048, 128 + (16 * 16)),
_ => unreachable!(),
};
TableUpdateInterval(max, slow)
}
}
#[derive(Clone, Copy, Debug)]
pub struct TableUpdateInterval(pub u32, pub u32);
impl TableUpdateInterval {
pub fn from_rate(rate: &TableUpdateRate) -> Self {
rate.table_update_settings()
}
}
impl Default for TableUpdateInterval {
fn default() -> Self {
TableUpdateRate::DEFAULT.table_update_settings()
}
}
impl CType for TableUpdateRate {
type CItem = lzham_sys::lzham_table_update_rate;
fn to_c_type(self) -> Self::CItem {
self.0
}
}
impl CType for TableUpdateInterval {
type CItem = (c_uint, c_uint);
fn to_c_type(self) -> Self::CItem {
(self.0 as c_uint, self.1 as c_uint)
}
}