type_bridge_contract/
limits.rs1pub const MAX_CANONICAL_BYTES: usize = 16 * 1024 * 1024;
5pub const MAX_REMOTE_ENVELOPE_BYTES: usize = 32 * 1024 * 1024;
11pub const MAX_CANONICAL_DEPTH: usize = 64;
13pub const MAX_CANONICAL_COLLECTION_LEN: usize = 65_536;
15pub const MAX_CANONICAL_STRING_BYTES: usize = 1024 * 1024;
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub struct CodecLimits {
21 pub max_bytes: usize,
23 pub max_depth: usize,
25 pub max_collection_len: usize,
27 pub max_string_bytes: usize,
29}
30
31impl CodecLimits {
32 pub const CANONICAL: Self = Self {
34 max_bytes: MAX_CANONICAL_BYTES,
35 max_depth: MAX_CANONICAL_DEPTH,
36 max_collection_len: MAX_CANONICAL_COLLECTION_LEN,
37 max_string_bytes: MAX_CANONICAL_STRING_BYTES,
38 };
39}
40
41impl Default for CodecLimits {
42 fn default() -> Self {
43 Self::CANONICAL
44 }
45}
46
47pub const CANONICAL_CODEC_LIMITS: CodecLimits = CodecLimits::CANONICAL;
49
50pub const REMOTE_ENVELOPE_CODEC_LIMITS: CodecLimits = CodecLimits {
52 max_bytes: MAX_REMOTE_ENVELOPE_BYTES,
53 max_depth: MAX_CANONICAL_DEPTH,
54 max_collection_len: MAX_CANONICAL_COLLECTION_LEN,
55 max_string_bytes: MAX_CANONICAL_STRING_BYTES,
56};
57
58pub const REMOTE_REQUEST_CODEC_LIMITS: CodecLimits = CodecLimits {
65 max_bytes: MAX_REMOTE_ENVELOPE_BYTES,
66 max_depth: MAX_CANONICAL_DEPTH + 1,
67 max_collection_len: MAX_CANONICAL_COLLECTION_LEN,
68 max_string_bytes: MAX_CANONICAL_STRING_BYTES,
69};
70
71pub const MAX_SELECTED_SLOTS: usize = 16;
73pub const MAX_BINDINGS: usize = 256;
75pub const MAX_PREDICATE_NODES: usize = 4_096;
77pub const MAX_PREDICATE_DEPTH: usize = 64;
79pub const MAX_BOOLEAN_TERMS: usize = 256;
81pub const MAX_ALLOWED_CROSS_JOINS: usize = 1_024;
83pub const MAX_ORDER_TERMS: usize = 64;
85pub const MAX_COLLECTION_ORDER_TERMS: usize = 64;
87pub const MAX_INPUT_ROWS: usize = 4_096;
89pub const MAX_INPUT_BYTES: usize = 4 * 1024 * 1024;
91pub const MAX_QUERY_INVOCATION_BYTES: usize = MAX_INPUT_BYTES + 234;
99pub const MAX_OUTPUT_NAME_BYTES: usize = 128;
101pub const MAX_SEMANTIC_ID_BYTES: usize = 512;
103pub const MAX_DIAGNOSTIC_BYTES: usize = 65_536;
105
106#[derive(Debug, Clone, Copy, PartialEq, Eq)]
108pub struct StructuralLimits {
109 pub selected_slots: usize,
111 pub bindings: usize,
113 pub predicate_nodes: usize,
115 pub predicate_depth: usize,
117 pub boolean_terms: usize,
119 pub allowed_cross_joins: usize,
121 pub order_terms: usize,
123 pub collection_order_terms: usize,
125 pub input_rows: usize,
127 pub input_bytes: usize,
129 pub output_name_bytes: usize,
131 pub semantic_id_bytes: usize,
133 pub diagnostic_bytes: usize,
135}
136
137impl StructuralLimits {
138 pub const CANONICAL: Self = Self {
140 selected_slots: MAX_SELECTED_SLOTS,
141 bindings: MAX_BINDINGS,
142 predicate_nodes: MAX_PREDICATE_NODES,
143 predicate_depth: MAX_PREDICATE_DEPTH,
144 boolean_terms: MAX_BOOLEAN_TERMS,
145 allowed_cross_joins: MAX_ALLOWED_CROSS_JOINS,
146 order_terms: MAX_ORDER_TERMS,
147 collection_order_terms: MAX_COLLECTION_ORDER_TERMS,
148 input_rows: MAX_INPUT_ROWS,
149 input_bytes: MAX_INPUT_BYTES,
150 output_name_bytes: MAX_OUTPUT_NAME_BYTES,
151 semantic_id_bytes: MAX_SEMANTIC_ID_BYTES,
152 diagnostic_bytes: MAX_DIAGNOSTIC_BYTES,
153 };
154
155 pub const fn allows_selected_slots(self, actual: usize) -> bool {
157 actual <= self.selected_slots
158 }
159
160 pub const fn allows_bindings(self, actual: usize) -> bool {
162 actual <= self.bindings
163 }
164
165 pub const fn allows_input_rows(self, actual: usize) -> bool {
167 actual <= self.input_rows
168 }
169
170 pub const fn allows_input_bytes(self, actual: usize) -> bool {
172 actual <= self.input_bytes
173 }
174
175 pub const fn allows_order_terms(self, actual: usize) -> bool {
177 actual <= self.order_terms
178 }
179
180 pub const fn allows_predicate_nodes(self, actual: usize) -> bool {
182 actual <= self.predicate_nodes
183 }
184
185 pub const fn allows_predicate_depth(self, actual: usize) -> bool {
187 actual <= self.predicate_depth
188 }
189
190 pub const fn allows_diagnostic_bytes(self, actual: usize) -> bool {
192 actual <= self.diagnostic_bytes
193 }
194}
195
196impl Default for StructuralLimits {
197 fn default() -> Self {
198 Self::CANONICAL
199 }
200}
201
202pub const CANONICAL_STRUCTURAL_LIMITS: StructuralLimits = StructuralLimits::CANONICAL;