use crate::diagnostic::{Code, Diagnostic};
const DEFAULT_DECOMPRESSED_BYTES: u64 = 16 << 30;
const DEFAULT_ROWS_PER_CATEGORY: u64 = 1 << 28;
const DEFAULT_DICTIONARY_ENTRIES: u32 = 1 << 24;
const DEFAULT_COMPRESSION_RATIO: u64 = 1_000;
const DEFAULT_NESTING_DEPTH: u32 = 64;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Limits {
pub decompressed_bytes: u64,
pub compression_ratio: u64,
pub rows_per_category: u64,
pub nesting_depth: u32,
pub dictionary_entries: u32,
}
impl Default for Limits {
fn default() -> Self {
Self {
decompressed_bytes: DEFAULT_DECOMPRESSED_BYTES,
compression_ratio: DEFAULT_COMPRESSION_RATIO,
rows_per_category: DEFAULT_ROWS_PER_CATEGORY,
nesting_depth: DEFAULT_NESTING_DEPTH,
dictionary_entries: DEFAULT_DICTIONARY_ENTRIES,
}
}
}
impl Limits {
#[must_use]
pub const fn unbounded() -> Self {
Self {
decompressed_bytes: u64::MAX,
compression_ratio: DEFAULT_COMPRESSION_RATIO,
rows_per_category: u64::MAX,
nesting_depth: DEFAULT_NESTING_DEPTH,
dictionary_entries: u32::MAX - 1,
}
}
#[must_use]
pub fn exceeded(limit: &'static str, value: impl std::fmt::Display) -> Diagnostic {
Diagnostic::new(Code::E1901)
.with_context("limit", limit)
.with_context("value", value.to_string())
}
}