1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Limits {
pub field_name_size: Option<usize>,
pub field_size: Option<usize>,
pub fields: Option<usize>,
pub file_size: Option<usize>,
pub files: Option<usize>,
pub parts: Option<usize>,
pub stream_size: Option<u64>,
pub buffer_size: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
field_name_size: Some(Self::DEFAULT_FIELD_NAME_SIZE),
field_size: Some(Self::DEFAULT_FIELD_SIZE),
fields: None,
file_size: Some(Self::DEFAULT_FILE_SIZE),
files: None,
parts: None,
stream_size: Some(Self::DEFAULT_STREAM_SIZE),
buffer_size: Self::DEFAULT_BUFFER_SIZE,
}
}
}
impl Limits {
pub const DEFAULT_FIELD_NAME_SIZE: usize = 100;
pub const DEFAULT_FIELD_SIZE: usize = 100 * 1024;
pub const DEFAULT_FILE_SIZE: usize = 10 * 1024 * 1024;
pub const DEFAULT_STREAM_SIZE: u64 = 200 * 1024 * 1024;
pub const DEFAULT_BUFFER_SIZE: usize = 8 * 1024;
pub fn field_name_size(mut self, max: usize) -> Self {
self.field_name_size.replace(max);
self
}
pub fn field_size(mut self, max: usize) -> Self {
self.field_size.replace(max);
self
}
pub fn fields(mut self, max: usize) -> Self {
self.fields.replace(max);
self
}
pub fn file_size(mut self, max: usize) -> Self {
self.file_size.replace(max);
self
}
pub fn files(mut self, max: usize) -> Self {
self.files.replace(max);
self
}
pub fn parts(mut self, max: usize) -> Self {
self.parts.replace(max);
self
}
pub fn buffer_size(mut self, max: usize) -> Self {
assert!(
max >= Self::DEFAULT_BUFFER_SIZE,
"The max_buffer_size cannot be smaller than {}.",
Self::DEFAULT_BUFFER_SIZE,
);
self.buffer_size = max;
self
}
pub fn stream_size(mut self, max: u64) -> Self {
self.stream_size.replace(max);
self
}
pub fn checked_parts(&self, rhs: usize) -> Option<usize> {
self.parts.filter(|max| rhs > *max)
}
pub fn checked_fields(&self, rhs: usize) -> Option<usize> {
self.fields.filter(|max| rhs > *max)
}
pub fn checked_files(&self, rhs: usize) -> Option<usize> {
self.files.filter(|max| rhs > *max)
}
pub fn checked_stream_size(&self, rhs: u64) -> Option<u64> {
self.stream_size.filter(|max| rhs > *max)
}
pub fn checked_file_size(&self, rhs: usize) -> Option<usize> {
self.file_size.filter(|max| rhs > *max)
}
pub fn checked_field_size(&self, rhs: usize) -> Option<usize> {
self.field_size.filter(|max| rhs > *max)
}
pub fn checked_field_name_size(&self, rhs: usize) -> Option<usize> {
self.field_name_size.filter(|max| rhs > *max)
}
}