-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
tl_dc_option_gen.go
473 lines (437 loc) · 9.44 KB
/
tl_dc_option_gen.go
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// DCOption represents TL type `dcOption#18b7a10d`.
// Data centre
//
// See https://core.telegram.org/constructor/dcOption for reference.
type DCOption struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Whether the specified IP is an IPv6 address
Ipv6 bool
// Whether this DC should only be used to download or upload files¹
//
// Links:
// 1) https://core.telegram.org/api/files
MediaOnly bool
// Whether this DC only supports connection with transport obfuscation¹
//
// Links:
// 1) https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation
TCPObfuscatedOnly bool
// Whether this is a CDN DC¹.
//
// Links:
// 1) https://core.telegram.org/cdn
CDN bool
// If set, this IP should be used when connecting through a proxy
Static bool
// DC ID
ID int
// IP address of DC
IPAddress string
// Port
Port int
// If the tcpo_only flag is set, specifies the secret to use when connecting using
// transport obfuscation¹
//
// Links:
// 1) https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation
//
// Use SetSecret and GetSecret helpers.
Secret []byte
}
// DCOptionTypeID is TL type id of DCOption.
const DCOptionTypeID = 0x18b7a10d
// Ensuring interfaces in compile-time for DCOption.
var (
_ bin.Encoder = &DCOption{}
_ bin.Decoder = &DCOption{}
_ bin.BareEncoder = &DCOption{}
_ bin.BareDecoder = &DCOption{}
)
func (d *DCOption) Zero() bool {
if d == nil {
return true
}
if !(d.Flags.Zero()) {
return false
}
if !(d.Ipv6 == false) {
return false
}
if !(d.MediaOnly == false) {
return false
}
if !(d.TCPObfuscatedOnly == false) {
return false
}
if !(d.CDN == false) {
return false
}
if !(d.Static == false) {
return false
}
if !(d.ID == 0) {
return false
}
if !(d.IPAddress == "") {
return false
}
if !(d.Port == 0) {
return false
}
if !(d.Secret == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (d *DCOption) String() string {
if d == nil {
return "DCOption(nil)"
}
type Alias DCOption
return fmt.Sprintf("DCOption%+v", Alias(*d))
}
// FillFrom fills DCOption from given interface.
func (d *DCOption) FillFrom(from interface {
GetIpv6() (value bool)
GetMediaOnly() (value bool)
GetTCPObfuscatedOnly() (value bool)
GetCDN() (value bool)
GetStatic() (value bool)
GetID() (value int)
GetIPAddress() (value string)
GetPort() (value int)
GetSecret() (value []byte, ok bool)
}) {
d.Ipv6 = from.GetIpv6()
d.MediaOnly = from.GetMediaOnly()
d.TCPObfuscatedOnly = from.GetTCPObfuscatedOnly()
d.CDN = from.GetCDN()
d.Static = from.GetStatic()
d.ID = from.GetID()
d.IPAddress = from.GetIPAddress()
d.Port = from.GetPort()
if val, ok := from.GetSecret(); ok {
d.Secret = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*DCOption) TypeID() uint32 {
return DCOptionTypeID
}
// TypeName returns name of type in TL schema.
func (*DCOption) TypeName() string {
return "dcOption"
}
// TypeInfo returns info about TL type.
func (d *DCOption) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "dcOption",
ID: DCOptionTypeID,
}
if d == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Ipv6",
SchemaName: "ipv6",
Null: !d.Flags.Has(0),
},
{
Name: "MediaOnly",
SchemaName: "media_only",
Null: !d.Flags.Has(1),
},
{
Name: "TCPObfuscatedOnly",
SchemaName: "tcpo_only",
Null: !d.Flags.Has(2),
},
{
Name: "CDN",
SchemaName: "cdn",
Null: !d.Flags.Has(3),
},
{
Name: "Static",
SchemaName: "static",
Null: !d.Flags.Has(4),
},
{
Name: "ID",
SchemaName: "id",
},
{
Name: "IPAddress",
SchemaName: "ip_address",
},
{
Name: "Port",
SchemaName: "port",
},
{
Name: "Secret",
SchemaName: "secret",
Null: !d.Flags.Has(10),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (d *DCOption) SetFlags() {
if !(d.Ipv6 == false) {
d.Flags.Set(0)
}
if !(d.MediaOnly == false) {
d.Flags.Set(1)
}
if !(d.TCPObfuscatedOnly == false) {
d.Flags.Set(2)
}
if !(d.CDN == false) {
d.Flags.Set(3)
}
if !(d.Static == false) {
d.Flags.Set(4)
}
if !(d.Secret == nil) {
d.Flags.Set(10)
}
}
// Encode implements bin.Encoder.
func (d *DCOption) Encode(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't encode dcOption#18b7a10d as nil")
}
b.PutID(DCOptionTypeID)
return d.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (d *DCOption) EncodeBare(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't encode dcOption#18b7a10d as nil")
}
d.SetFlags()
if err := d.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode dcOption#18b7a10d: field flags: %w", err)
}
b.PutInt(d.ID)
b.PutString(d.IPAddress)
b.PutInt(d.Port)
if d.Flags.Has(10) {
b.PutBytes(d.Secret)
}
return nil
}
// Decode implements bin.Decoder.
func (d *DCOption) Decode(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't decode dcOption#18b7a10d to nil")
}
if err := b.ConsumeID(DCOptionTypeID); err != nil {
return fmt.Errorf("unable to decode dcOption#18b7a10d: %w", err)
}
return d.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (d *DCOption) DecodeBare(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't decode dcOption#18b7a10d to nil")
}
{
if err := d.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode dcOption#18b7a10d: field flags: %w", err)
}
}
d.Ipv6 = d.Flags.Has(0)
d.MediaOnly = d.Flags.Has(1)
d.TCPObfuscatedOnly = d.Flags.Has(2)
d.CDN = d.Flags.Has(3)
d.Static = d.Flags.Has(4)
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode dcOption#18b7a10d: field id: %w", err)
}
d.ID = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode dcOption#18b7a10d: field ip_address: %w", err)
}
d.IPAddress = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode dcOption#18b7a10d: field port: %w", err)
}
d.Port = value
}
if d.Flags.Has(10) {
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode dcOption#18b7a10d: field secret: %w", err)
}
d.Secret = value
}
return nil
}
// SetIpv6 sets value of Ipv6 conditional field.
func (d *DCOption) SetIpv6(value bool) {
if value {
d.Flags.Set(0)
d.Ipv6 = true
} else {
d.Flags.Unset(0)
d.Ipv6 = false
}
}
// GetIpv6 returns value of Ipv6 conditional field.
func (d *DCOption) GetIpv6() (value bool) {
if d == nil {
return
}
return d.Flags.Has(0)
}
// SetMediaOnly sets value of MediaOnly conditional field.
func (d *DCOption) SetMediaOnly(value bool) {
if value {
d.Flags.Set(1)
d.MediaOnly = true
} else {
d.Flags.Unset(1)
d.MediaOnly = false
}
}
// GetMediaOnly returns value of MediaOnly conditional field.
func (d *DCOption) GetMediaOnly() (value bool) {
if d == nil {
return
}
return d.Flags.Has(1)
}
// SetTCPObfuscatedOnly sets value of TCPObfuscatedOnly conditional field.
func (d *DCOption) SetTCPObfuscatedOnly(value bool) {
if value {
d.Flags.Set(2)
d.TCPObfuscatedOnly = true
} else {
d.Flags.Unset(2)
d.TCPObfuscatedOnly = false
}
}
// GetTCPObfuscatedOnly returns value of TCPObfuscatedOnly conditional field.
func (d *DCOption) GetTCPObfuscatedOnly() (value bool) {
if d == nil {
return
}
return d.Flags.Has(2)
}
// SetCDN sets value of CDN conditional field.
func (d *DCOption) SetCDN(value bool) {
if value {
d.Flags.Set(3)
d.CDN = true
} else {
d.Flags.Unset(3)
d.CDN = false
}
}
// GetCDN returns value of CDN conditional field.
func (d *DCOption) GetCDN() (value bool) {
if d == nil {
return
}
return d.Flags.Has(3)
}
// SetStatic sets value of Static conditional field.
func (d *DCOption) SetStatic(value bool) {
if value {
d.Flags.Set(4)
d.Static = true
} else {
d.Flags.Unset(4)
d.Static = false
}
}
// GetStatic returns value of Static conditional field.
func (d *DCOption) GetStatic() (value bool) {
if d == nil {
return
}
return d.Flags.Has(4)
}
// GetID returns value of ID field.
func (d *DCOption) GetID() (value int) {
if d == nil {
return
}
return d.ID
}
// GetIPAddress returns value of IPAddress field.
func (d *DCOption) GetIPAddress() (value string) {
if d == nil {
return
}
return d.IPAddress
}
// GetPort returns value of Port field.
func (d *DCOption) GetPort() (value int) {
if d == nil {
return
}
return d.Port
}
// SetSecret sets value of Secret conditional field.
func (d *DCOption) SetSecret(value []byte) {
d.Flags.Set(10)
d.Secret = value
}
// GetSecret returns value of Secret conditional field and
// boolean which is true if field was set.
func (d *DCOption) GetSecret() (value []byte, ok bool) {
if d == nil {
return
}
if !d.Flags.Has(10) {
return value, false
}
return d.Secret, true
}