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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
mod de;
mod se;
#[derive(Debug, Clone, PartialEq, Hash)]
pub enum Schema {
Null,
Boolean,
Int(Option<IntLogical>),
Long(Option<LongLogical>),
Float,
Double,
Bytes(Option<BytesLogical>),
String(Option<StringLogical>),
Record(Record),
Enum(Enum),
Array(Box<Schema>),
Map(Box<Schema>),
Union(Vec<Schema>),
Fixed(Fixed),
}
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
pub enum Order {
Ascending,
Descending,
Ignore,
}
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct Field {
pub name: String,
pub doc: Option<String>,
pub schema: Schema,
pub default: Option<Schema>,
pub order: Option<Order>,
pub aliases: Vec<String>,
}
impl Field {
pub fn new<I: Into<String>>(name: I, schema: Schema) -> Self {
Self {
name: name.into(),
doc: None,
schema,
default: None,
order: None,
aliases: vec![],
}
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct Record {
pub name: String,
pub namespace: Option<String>,
pub doc: Option<String>,
pub aliases: Vec<String>,
pub fields: Vec<Field>,
}
impl Record {
pub fn new<I: Into<String>>(name: I, fields: Vec<Field>) -> Self {
Self {
name: name.into(),
namespace: None,
doc: None,
fields,
aliases: vec![],
}
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct Fixed {
pub name: String,
pub namespace: Option<String>,
pub doc: Option<String>,
pub aliases: Vec<String>,
pub size: usize,
pub logical: Option<FixedLogical>,
}
impl Fixed {
pub fn new<I: Into<String>>(name: I, size: usize) -> Self {
Self {
name: name.into(),
namespace: None,
doc: None,
size,
aliases: vec![],
logical: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct Enum {
pub name: String,
pub namespace: Option<String>,
pub aliases: Vec<String>,
pub doc: Option<String>,
pub symbols: Vec<String>,
pub default: Option<String>,
}
impl Enum {
pub fn new<I: Into<String>>(name: I, symbols: Vec<String>) -> Self {
Self {
name: name.into(),
namespace: None,
doc: None,
symbols,
aliases: vec![],
default: None,
}
}
}
impl From<Enum> for Schema {
fn from(enum_: Enum) -> Self {
Schema::Enum(enum_)
}
}
impl From<Record> for Schema {
fn from(record: Record) -> Self {
Schema::Record(record)
}
}
impl From<Fixed> for Schema {
fn from(fixed: Fixed) -> Self {
Schema::Fixed(fixed)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IntLogical {
Date,
Time,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LongLogical {
Time,
TimestampMillis,
TimestampMicros,
LocalTimestampMillis,
LocalTimestampMicros,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StringLogical {
Uuid,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FixedLogical {
Decimal(usize, usize),
Duration,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BytesLogical {
Decimal(usize, usize),
}