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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

// Copyright 2020 - developers of the `grammers` project.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/// The schema layer from which the definitions were generated.
pub const LAYER: i32 = 2;

/// This module contains all of the bare types, each
/// represented by a `struct`. All of them implement
/// [`Identifiable`], [`Serializable`] and [`Deserializable`].
///
/// [`Identifiable`]: ../trait.Identifiable.html
/// [`Serializable`]: ../trait.Serializable.html
/// [`Deserializable`]: ../trait.Deserializable.html
#[allow(clippy::cognitive_complexity, clippy::identity_op, clippy::unreadable_literal)]
pub mod types {
    #[allow(unused_imports)]
    use std::convert::TryFrom;
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub struct ChannelState {
        pub channel_id: i64,
        pub pts: i32,
    }
    impl crate::Identifiable for ChannelState {
        const CONSTRUCTOR_ID: u32 = 3266377933;
    }
    impl crate::Serializable for ChannelState {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            self.channel_id.serialize(buf);
            self.pts.serialize(buf);
        }
    }
    impl crate::Deserializable for ChannelState {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            let channel_id = i64::deserialize(buf)?;
            let pts = i32::deserialize(buf)?;
            Ok(ChannelState {
                channel_id,
                pts,
            })
        }
    }
    impl From<crate::enums::ChannelState> for ChannelState {
        fn from(x: crate::enums::ChannelState) -> Self {
            match x {
                crate::enums::ChannelState::State(x) => x,
            }
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub struct DataCenter {
        pub id: i32,
        pub ipv4: Option<i32>,
        pub ipv6: Option<[u8; 16]>,
        pub port: i32,
        pub auth: Option<Vec<u8>>,
    }
    impl crate::Identifiable for DataCenter {
        const CONSTRUCTOR_ID: u32 = 1970083510;
    }
    impl crate::Serializable for DataCenter {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            (0u32 | if self.ipv4.is_some() { 1 } else { 0 } | if self.ipv6.is_some() { 2 } else { 0 } | if self.auth.is_some() { 4 } else { 0 }).serialize(buf);
            self.id.serialize(buf);
            if let Some(ref x) = self.ipv4 { 
                x.serialize(buf);
            }
            if let Some(ref x) = self.ipv6 { 
                x.serialize(buf);
            }
            self.port.serialize(buf);
            if let Some(ref x) = self.auth { 
                x.serialize(buf);
            }
        }
    }
    impl crate::Deserializable for DataCenter {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            let flags = u32::deserialize(buf)?;
            let id = i32::deserialize(buf)?;
            let ipv4 = if (flags & 1) != 0 {
                Some(i32::deserialize(buf)?)
            } else {
                None
            };
            let ipv6 = if (flags & 2) != 0 {
                Some(<[u8; 16]>::deserialize(buf)?)
            } else {
                None
            };
            let port = i32::deserialize(buf)?;
            let auth = if (flags & 4) != 0 {
                Some(Vec::<u8>::deserialize(buf)?)
            } else {
                None
            };
            Ok(DataCenter {
                                id,
                ipv4,
                ipv6,
                port,
                auth,
            })
        }
    }
    impl From<crate::enums::DataCenter> for DataCenter {
        fn from(x: crate::enums::DataCenter) -> Self {
            match x {
                crate::enums::DataCenter::Center(x) => x,
            }
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub struct Session {
        pub dcs: Vec<crate::enums::DataCenter>,
        pub user: Option<crate::enums::User>,
        pub state: Option<crate::enums::UpdateState>,
    }
    impl crate::Identifiable for Session {
        const CONSTRUCTOR_ID: u32 = 2805905614;
    }
    impl crate::Serializable for Session {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            (0u32 | if self.user.is_some() { 1 } else { 0 } | if self.state.is_some() { 2 } else { 0 }).serialize(buf);
            self.dcs.serialize(buf);
            if let Some(ref x) = self.user { 
                x.serialize(buf);
            }
            if let Some(ref x) = self.state { 
                x.serialize(buf);
            }
        }
    }
    impl crate::Deserializable for Session {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            let flags = u32::deserialize(buf)?;
            let dcs = Vec::<crate::enums::DataCenter>::deserialize(buf)?;
            let user = if (flags & 1) != 0 {
                Some(crate::enums::User::deserialize(buf)?)
            } else {
                None
            };
            let state = if (flags & 2) != 0 {
                Some(crate::enums::UpdateState::deserialize(buf)?)
            } else {
                None
            };
            Ok(Session {
                                dcs,
                user,
                state,
            })
        }
    }
    impl From<crate::enums::Session> for Session {
        fn from(x: crate::enums::Session) -> Self {
            match x {
                crate::enums::Session::Session(x) => x,
            }
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub struct UpdateState {
        pub pts: i32,
        pub qts: i32,
        pub date: i32,
        pub seq: i32,
        pub channels: Vec<crate::enums::ChannelState>,
    }
    impl crate::Identifiable for UpdateState {
        const CONSTRUCTOR_ID: u32 = 3502955713;
    }
    impl crate::Serializable for UpdateState {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            self.pts.serialize(buf);
            self.qts.serialize(buf);
            self.date.serialize(buf);
            self.seq.serialize(buf);
            self.channels.serialize(buf);
        }
    }
    impl crate::Deserializable for UpdateState {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            let pts = i32::deserialize(buf)?;
            let qts = i32::deserialize(buf)?;
            let date = i32::deserialize(buf)?;
            let seq = i32::deserialize(buf)?;
            let channels = Vec::<crate::enums::ChannelState>::deserialize(buf)?;
            Ok(UpdateState {
                pts,
                qts,
                date,
                seq,
                channels,
            })
        }
    }
    impl From<crate::enums::UpdateState> for UpdateState {
        fn from(x: crate::enums::UpdateState) -> Self {
            match x {
                crate::enums::UpdateState::State(x) => x,
            }
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub struct User {
        pub id: i64,
        pub dc: i32,
        pub bot: bool,
    }
    impl crate::Identifiable for User {
        const CONSTRUCTOR_ID: u32 = 1731150477;
    }
    impl crate::Serializable for User {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            self.id.serialize(buf);
            self.dc.serialize(buf);
            self.bot.serialize(buf);
        }
    }
    impl crate::Deserializable for User {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            let id = i64::deserialize(buf)?;
            let dc = i32::deserialize(buf)?;
            let bot = bool::deserialize(buf)?;
            Ok(User {
                id,
                dc,
                bot,
            })
        }
    }
    impl From<crate::enums::User> for User {
        fn from(x: crate::enums::User) -> Self {
            match x {
                crate::enums::User::User(x) => x,
            }
        }
    }
}
/// This module contains all of the functions, each
/// represented by a `struct`. All of them implement
/// [`Identifiable`] and [`Serializable`].
///
/// To find out the type that Telegram will return upon
/// invoking one of these requests, check out the associated
/// type in the corresponding [`RemoteCall`] trait impl.
///
/// [`Identifiable`]: ../trait.Identifiable.html
/// [`Serializable`]: ../trait.Serializable.html
/// [`RemoteCall`]: trait.RemoteCall.html
#[allow(clippy::cognitive_complexity, clippy::identity_op, clippy::unreadable_literal)]
pub mod functions {
            
}
/// This module contains all of the boxed types, each
/// represented by a `enum`. All of them implement
/// [`Serializable`] and [`Deserializable`].
///
/// [`Serializable`]: /grammers_tl_types/trait.Serializable.html
/// [`Deserializable`]: /grammers_tl_types/trait.Deserializable.html
#[allow(clippy::large_enum_variant)]
pub mod enums {
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub enum ChannelState {
        State(crate::types::ChannelState),
    }
    impl crate::Serializable for ChannelState {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            use crate::Identifiable;
            match self {
                Self::State(x) => {
                    crate::types::ChannelState::CONSTRUCTOR_ID.serialize(buf);
                    x.serialize(buf)
                },
            }
        }
    }
    impl crate::Deserializable for ChannelState {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            use crate::Identifiable;
            let id = u32::deserialize(buf)?;
            Ok(match id {
                crate::types::ChannelState::CONSTRUCTOR_ID => Self::State(crate::types::ChannelState::deserialize(buf)?),
                _ => return Err(crate::deserialize::Error::UnexpectedConstructor { id }),
            })
        }
    }
    impl From<crate::types::ChannelState> for ChannelState {
        fn from(x: crate::types::ChannelState) -> Self {
            ChannelState::State(x)
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub enum DataCenter {
        Center(crate::types::DataCenter),
    }
    impl crate::Serializable for DataCenter {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            use crate::Identifiable;
            match self {
                Self::Center(x) => {
                    crate::types::DataCenter::CONSTRUCTOR_ID.serialize(buf);
                    x.serialize(buf)
                },
            }
        }
    }
    impl crate::Deserializable for DataCenter {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            use crate::Identifiable;
            let id = u32::deserialize(buf)?;
            Ok(match id {
                crate::types::DataCenter::CONSTRUCTOR_ID => Self::Center(crate::types::DataCenter::deserialize(buf)?),
                _ => return Err(crate::deserialize::Error::UnexpectedConstructor { id }),
            })
        }
    }
    impl From<crate::types::DataCenter> for DataCenter {
        fn from(x: crate::types::DataCenter) -> Self {
            DataCenter::Center(x)
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub enum Session {
        Session(crate::types::Session),
    }
    impl crate::Serializable for Session {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            use crate::Identifiable;
            match self {
                Self::Session(x) => {
                    crate::types::Session::CONSTRUCTOR_ID.serialize(buf);
                    x.serialize(buf)
                },
            }
        }
    }
    impl crate::Deserializable for Session {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            use crate::Identifiable;
            let id = u32::deserialize(buf)?;
            Ok(match id {
                crate::types::Session::CONSTRUCTOR_ID => Self::Session(crate::types::Session::deserialize(buf)?),
                _ => return Err(crate::deserialize::Error::UnexpectedConstructor { id }),
            })
        }
    }
    impl From<crate::types::Session> for Session {
        fn from(x: crate::types::Session) -> Self {
            Session::Session(x)
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub enum UpdateState {
        State(crate::types::UpdateState),
    }
    impl crate::Serializable for UpdateState {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            use crate::Identifiable;
            match self {
                Self::State(x) => {
                    crate::types::UpdateState::CONSTRUCTOR_ID.serialize(buf);
                    x.serialize(buf)
                },
            }
        }
    }
    impl crate::Deserializable for UpdateState {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            use crate::Identifiable;
            let id = u32::deserialize(buf)?;
            Ok(match id {
                crate::types::UpdateState::CONSTRUCTOR_ID => Self::State(crate::types::UpdateState::deserialize(buf)?),
                _ => return Err(crate::deserialize::Error::UnexpectedConstructor { id }),
            })
        }
    }
    impl From<crate::types::UpdateState> for UpdateState {
        fn from(x: crate::types::UpdateState) -> Self {
            UpdateState::State(x)
        }
    }
    #[derive(Debug)]
    #[derive(Clone, PartialEq)]
    pub enum User {
        User(crate::types::User),
    }
    impl crate::Serializable for User {
        fn serialize(&self, buf: crate::serialize::Buffer) {
            use crate::Identifiable;
            match self {
                Self::User(x) => {
                    crate::types::User::CONSTRUCTOR_ID.serialize(buf);
                    x.serialize(buf)
                },
            }
        }
    }
    impl crate::Deserializable for User {
        fn deserialize(buf: crate::deserialize::Buffer) -> crate::deserialize::Result<Self> {
            use crate::Identifiable;
            let id = u32::deserialize(buf)?;
            Ok(match id {
                crate::types::User::CONSTRUCTOR_ID => Self::User(crate::types::User::deserialize(buf)?),
                _ => return Err(crate::deserialize::Error::UnexpectedConstructor { id }),
            })
        }
    }
    impl From<crate::types::User> for User {
        fn from(x: crate::types::User) -> Self {
            User::User(x)
        }
    }
}