use jsonx_lib::Parser;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct Limits {
pub max_message_bytes: usize,
pub max_header_bytes: usize,
pub max_headers: usize,
pub max_batch: usize,
pub json: jsonx_lib::Limits,
}
impl Limits {
#[must_use]
pub const fn new() -> Self {
Self {
max_message_bytes: 64 * 1024 * 1024,
max_header_bytes: 8 * 1024,
max_headers: 32,
max_batch: 1024,
json: jsonx_lib::Limits::new(),
}
}
#[must_use]
pub const fn with_max_message_bytes(mut self, bytes: usize) -> Self {
self.max_message_bytes = bytes;
self
}
#[must_use]
pub const fn with_max_header_bytes(mut self, bytes: usize) -> Self {
self.max_header_bytes = bytes;
self
}
#[must_use]
pub const fn with_max_headers(mut self, count: usize) -> Self {
self.max_headers = count;
self
}
#[must_use]
pub const fn with_max_batch(mut self, count: usize) -> Self {
self.max_batch = count;
self
}
#[must_use]
pub const fn with_json(mut self, json: jsonx_lib::Limits) -> Self {
self.json = json;
self
}
pub const fn parser(&self) -> Parser {
Parser::new().limits(self.json.with_max_input_bytes(self.max_message_bytes))
}
}
impl Default for Limits {
fn default() -> Self {
Self::new()
}
}