Skip to main content

nbt_rust/
limits.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub struct NbtLimits {
3    pub max_depth: usize,
4    pub max_read_bytes: usize,
5    pub max_string_len: usize,
6    pub max_array_len: usize,
7    pub max_list_len: usize,
8    pub max_compound_entries: usize,
9}
10
11impl NbtLimits {
12    pub const fn new(
13        max_depth: usize,
14        max_read_bytes: usize,
15        max_string_len: usize,
16        max_array_len: usize,
17        max_list_len: usize,
18        max_compound_entries: usize,
19    ) -> Self {
20        Self {
21            max_depth,
22            max_read_bytes,
23            max_string_len,
24            max_array_len,
25            max_list_len,
26            max_compound_entries,
27        }
28    }
29
30    pub const fn with_max_depth(mut self, max_depth: usize) -> Self {
31        self.max_depth = max_depth;
32        self
33    }
34
35    pub const fn with_max_read_bytes(mut self, max_read_bytes: usize) -> Self {
36        self.max_read_bytes = max_read_bytes;
37        self
38    }
39
40    pub const fn with_max_string_len(mut self, max_string_len: usize) -> Self {
41        self.max_string_len = max_string_len;
42        self
43    }
44
45    pub const fn with_max_array_len(mut self, max_array_len: usize) -> Self {
46        self.max_array_len = max_array_len;
47        self
48    }
49
50    pub const fn with_max_list_len(mut self, max_list_len: usize) -> Self {
51        self.max_list_len = max_list_len;
52        self
53    }
54
55    pub const fn with_max_compound_entries(mut self, max_compound_entries: usize) -> Self {
56        self.max_compound_entries = max_compound_entries;
57        self
58    }
59}
60
61impl Default for NbtLimits {
62    fn default() -> Self {
63        Self {
64            max_depth: 512,
65            max_read_bytes: 16 * 1024 * 1024,
66            max_string_len: 1024 * 1024,
67            max_array_len: 4 * 1024 * 1024,
68            max_list_len: 1024 * 1024,
69            max_compound_entries: 1024 * 1024,
70        }
71    }
72}