pub const MAX_CANONICAL_BYTES: usize = 16 * 1024 * 1024;
pub const MAX_REMOTE_ENVELOPE_BYTES: usize = 32 * 1024 * 1024;
pub const MAX_CANONICAL_DEPTH: usize = 64;
pub const MAX_CANONICAL_COLLECTION_LEN: usize = 65_536;
pub const MAX_CANONICAL_STRING_BYTES: usize = 1024 * 1024;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CodecLimits {
pub max_bytes: usize,
pub max_depth: usize,
pub max_collection_len: usize,
pub max_string_bytes: usize,
}
impl CodecLimits {
pub const CANONICAL: Self = Self {
max_bytes: MAX_CANONICAL_BYTES,
max_depth: MAX_CANONICAL_DEPTH,
max_collection_len: MAX_CANONICAL_COLLECTION_LEN,
max_string_bytes: MAX_CANONICAL_STRING_BYTES,
};
}
impl Default for CodecLimits {
fn default() -> Self {
Self::CANONICAL
}
}
pub const CANONICAL_CODEC_LIMITS: CodecLimits = CodecLimits::CANONICAL;
pub const REMOTE_ENVELOPE_CODEC_LIMITS: CodecLimits = CodecLimits {
max_bytes: MAX_REMOTE_ENVELOPE_BYTES,
max_depth: MAX_CANONICAL_DEPTH,
max_collection_len: MAX_CANONICAL_COLLECTION_LEN,
max_string_bytes: MAX_CANONICAL_STRING_BYTES,
};
pub const REMOTE_REQUEST_CODEC_LIMITS: CodecLimits = CodecLimits {
max_bytes: MAX_REMOTE_ENVELOPE_BYTES,
max_depth: MAX_CANONICAL_DEPTH + 1,
max_collection_len: MAX_CANONICAL_COLLECTION_LEN,
max_string_bytes: MAX_CANONICAL_STRING_BYTES,
};
pub const MAX_SELECTED_SLOTS: usize = 16;
pub const MAX_BINDINGS: usize = 256;
pub const MAX_PREDICATE_NODES: usize = 4_096;
pub const MAX_PREDICATE_DEPTH: usize = 64;
pub const MAX_BOOLEAN_TERMS: usize = 256;
pub const MAX_ALLOWED_CROSS_JOINS: usize = 1_024;
pub const MAX_ORDER_TERMS: usize = 64;
pub const MAX_COLLECTION_ORDER_TERMS: usize = 64;
pub const MAX_INPUT_ROWS: usize = 4_096;
pub const MAX_INPUT_BYTES: usize = 4 * 1024 * 1024;
pub const MAX_QUERY_INVOCATION_BYTES: usize = MAX_INPUT_BYTES + 234;
pub const MAX_OUTPUT_NAME_BYTES: usize = 128;
pub const MAX_SEMANTIC_ID_BYTES: usize = 512;
pub const MAX_DIAGNOSTIC_BYTES: usize = 65_536;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StructuralLimits {
pub selected_slots: usize,
pub bindings: usize,
pub predicate_nodes: usize,
pub predicate_depth: usize,
pub boolean_terms: usize,
pub allowed_cross_joins: usize,
pub order_terms: usize,
pub collection_order_terms: usize,
pub input_rows: usize,
pub input_bytes: usize,
pub output_name_bytes: usize,
pub semantic_id_bytes: usize,
pub diagnostic_bytes: usize,
}
impl StructuralLimits {
pub const CANONICAL: Self = Self {
selected_slots: MAX_SELECTED_SLOTS,
bindings: MAX_BINDINGS,
predicate_nodes: MAX_PREDICATE_NODES,
predicate_depth: MAX_PREDICATE_DEPTH,
boolean_terms: MAX_BOOLEAN_TERMS,
allowed_cross_joins: MAX_ALLOWED_CROSS_JOINS,
order_terms: MAX_ORDER_TERMS,
collection_order_terms: MAX_COLLECTION_ORDER_TERMS,
input_rows: MAX_INPUT_ROWS,
input_bytes: MAX_INPUT_BYTES,
output_name_bytes: MAX_OUTPUT_NAME_BYTES,
semantic_id_bytes: MAX_SEMANTIC_ID_BYTES,
diagnostic_bytes: MAX_DIAGNOSTIC_BYTES,
};
pub const fn allows_selected_slots(self, actual: usize) -> bool {
actual <= self.selected_slots
}
pub const fn allows_bindings(self, actual: usize) -> bool {
actual <= self.bindings
}
pub const fn allows_input_rows(self, actual: usize) -> bool {
actual <= self.input_rows
}
pub const fn allows_input_bytes(self, actual: usize) -> bool {
actual <= self.input_bytes
}
pub const fn allows_order_terms(self, actual: usize) -> bool {
actual <= self.order_terms
}
pub const fn allows_predicate_nodes(self, actual: usize) -> bool {
actual <= self.predicate_nodes
}
pub const fn allows_predicate_depth(self, actual: usize) -> bool {
actual <= self.predicate_depth
}
pub const fn allows_diagnostic_bytes(self, actual: usize) -> bool {
actual <= self.diagnostic_bytes
}
}
impl Default for StructuralLimits {
fn default() -> Self {
Self::CANONICAL
}
}
pub const CANONICAL_STRUCTURAL_LIMITS: StructuralLimits = StructuralLimits::CANONICAL;