#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "adaptive")]
mod adaptive;
mod decode;
mod encode;
mod error;
mod probe;
#[cfg(feature = "adaptive")]
#[cfg_attr(docsrs, doc(cfg(feature = "adaptive")))]
pub use adaptive::{Adaptive, Choice, NetSignal, Stat};
pub use decode::{decode, decode_limit, decode_owned, decode_owned_limit, decode_payload_limit};
pub use encode::{
DEFAULT_MAX_WINDOW_LOG, EncodeOpt, Encoded, LOW_LATENCY_WINDOW_LOG, encode, encode_into,
encode_into_opt, encode_opt, encode_owned, encode_owned_opt,
};
pub use error::{Error, Result};
pub use probe::{ContentBucket, classify};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum Type {
Raw = 0,
Zstd = 1,
}
impl TryFrom<u8> for Type {
type Error = Error;
#[inline]
fn try_from(tag: u8) -> Result<Self> {
match tag {
0 => Ok(Self::Raw),
1 => Ok(Self::Zstd),
other => Err(Error::InvalidType(other)),
}
}
}
impl From<Type> for u8 {
#[inline]
fn from(value: Type) -> Self {
value as Self
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(i32)]
pub enum Level {
UltraFast = -4,
SuperFast = -1,
Fastest = 1,
Fast = 3,
#[default]
Balanced = 6,
Strong = 9,
High = 12,
Best = 19,
}
impl Level {
pub const ALL: [Self; 8] = [
Self::UltraFast,
Self::SuperFast,
Self::Fastest,
Self::Fast,
Self::Balanced,
Self::Strong,
Self::High,
Self::Best,
];
#[cfg(feature = "adaptive")]
pub(crate) const ONLINE_CNT: usize = 7;
#[must_use]
#[inline]
pub const fn get(self) -> i32 {
self as i32
}
#[cfg(feature = "adaptive")]
#[inline]
pub(crate) const fn index(self) -> usize {
match self {
Self::UltraFast => 0,
Self::SuperFast => 1,
Self::Fastest => 2,
Self::Fast => 3,
Self::Balanced => 4,
Self::Strong => 5,
Self::High => 6,
Self::Best => 7,
}
}
}
#[cfg(feature = "adaptive")]
const _: () = {
let mut i = 0;
while i < Level::ALL.len() {
assert!(Level::ALL[i].index() == i);
i += 1;
}
assert!(Level::ALL[Level::ONLINE_CNT - 1].get() == Level::High.get());
};
impl From<Level> for i32 {
#[inline]
fn from(value: Level) -> Self {
value.get()
}
}