1#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
6#[serde(default)]
7#[non_exhaustive]
8pub struct Limits {
9 pub max_input_bytes: u64,
11 pub max_decompressed_bytes: u64,
13 pub max_objects: u64,
15 pub max_depth: u32,
17 pub max_string_bytes: u32,
19 pub max_vertices: u32,
21 pub max_total_vertices: u64,
24}
25
26impl Default for Limits {
27 fn default() -> Self {
28 Self::new()
29 }
30}
31
32impl Limits {
33 pub const fn new() -> Self {
35 Self {
36 max_input_bytes: 2 << 30,
37 max_decompressed_bytes: 4 << 30,
38 max_objects: 20_000_000,
39 max_depth: 64,
40 max_string_bytes: 16 << 20,
41 max_vertices: 10_000_000,
42 max_total_vertices: 100_000_000,
43 }
44 }
45
46 pub const fn strict() -> Self {
49 Self {
50 max_input_bytes: 64 << 20,
51 max_decompressed_bytes: 256 << 20,
52 max_objects: 500_000,
53 max_depth: 32,
54 max_string_bytes: 4 << 20,
55 max_vertices: 1_000_000,
56 max_total_vertices: 5_000_000,
57 }
58 }
59
60 pub const fn with_max_input_bytes(mut self, bytes: u64) -> Self {
62 self.max_input_bytes = bytes;
63 self
64 }
65
66 pub const fn with_max_decompressed_bytes(mut self, bytes: u64) -> Self {
68 self.max_decompressed_bytes = bytes;
69 self
70 }
71
72 pub const fn with_max_objects(mut self, count: u64) -> Self {
74 self.max_objects = count;
75 self
76 }
77
78 pub const fn with_max_depth(mut self, depth: u32) -> Self {
80 self.max_depth = depth;
81 self
82 }
83
84 pub const fn with_max_string_bytes(mut self, bytes: u32) -> Self {
86 self.max_string_bytes = bytes;
87 self
88 }
89
90 pub const fn with_max_vertices(mut self, count: u32) -> Self {
92 self.max_vertices = count;
93 self
94 }
95
96 pub const fn with_max_total_vertices(mut self, count: u64) -> Self {
98 self.max_total_vertices = count;
99 self
100 }
101}
102
103#[derive(Debug, Clone, PartialEq, Default, serde::Serialize, serde::Deserialize)]
105#[serde(default)]
106#[non_exhaustive]
107pub struct ReadOptions {
108 pub limits: Limits,
110 pub keep_raw: bool,
112 pub fallback_codepage: Option<String>,
115}
116
117impl ReadOptions {
118 pub fn new() -> Self {
120 Self::default()
121 }
122
123 pub fn with_limits(mut self, limits: Limits) -> Self {
125 self.limits = limits;
126 self
127 }
128
129 pub fn with_keep_raw(mut self, keep_raw: bool) -> Self {
131 self.keep_raw = keep_raw;
132 self
133 }
134
135 pub fn with_fallback_codepage(mut self, codepage: impl Into<String>) -> Self {
137 self.fallback_codepage = Some(codepage.into());
138 self
139 }
140}