#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct JsonLimits {
pub max_input_bytes: usize,
pub max_depth: usize,
pub max_string_bytes: usize,
pub max_key_bytes: usize,
pub max_number_bytes: usize,
pub max_array_items: usize,
pub max_object_members: usize,
pub max_total_nodes: usize,
pub max_total_decoded_string_bytes: usize,
}
impl JsonLimits {
pub const fn new() -> Self {
Self {
max_input_bytes: 1 << 20,
max_depth: 64,
max_string_bytes: 256 << 10,
max_key_bytes: 16 << 10,
max_number_bytes: 256,
max_array_items: 100_000,
max_object_members: 100_000,
max_total_nodes: 200_000,
max_total_decoded_string_bytes: 1 << 20,
}
}
pub const fn conservative() -> Self {
Self {
max_input_bytes: 64 << 10,
max_depth: 32,
max_string_bytes: 16 << 10,
max_key_bytes: 1 << 10,
max_number_bytes: 64,
max_array_items: 4_096,
max_object_members: 4_096,
max_total_nodes: 16_384,
max_total_decoded_string_bytes: 64 << 10,
}
}
pub const fn permissive() -> Self {
Self {
max_input_bytes: 64 << 20,
max_depth: 128,
max_string_bytes: 16 << 20,
max_key_bytes: 256 << 10,
max_number_bytes: 1_024,
max_array_items: 5_000_000,
max_object_members: 5_000_000,
max_total_nodes: 10_000_000,
max_total_decoded_string_bytes: 64 << 20,
}
}
pub const fn with_max_depth(mut self, value: usize) -> Self {
self.max_depth = value;
self
}
pub const fn with_max_input_bytes(mut self, value: usize) -> Self {
self.max_input_bytes = value;
self
}
pub const fn with_max_string_bytes(mut self, value: usize) -> Self {
self.max_string_bytes = value;
self
}
pub const fn with_max_total_nodes(mut self, value: usize) -> Self {
self.max_total_nodes = value;
self
}
}
impl Default for JsonLimits {
fn default() -> Self {
Self::new()
}
}