-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
tl_input_game_gen.go
710 lines (617 loc) · 15.8 KB
/
tl_input_game_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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// 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/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{}
)
// InputGameID represents TL type `inputGameID#32c3e77`.
// Indicates an already sent game
//
// See https://core.telegram.org/constructor/inputGameID for reference.
type InputGameID struct {
// game ID from Game¹ constructor
//
// Links:
// 1) https://core.telegram.org/type/Game
ID int64
// access hash from Game¹ constructor
//
// Links:
// 1) https://core.telegram.org/type/Game
AccessHash int64
}
// InputGameIDTypeID is TL type id of InputGameID.
const InputGameIDTypeID = 0x32c3e77
func (i *InputGameID) Zero() bool {
if i == nil {
return true
}
if !(i.ID == 0) {
return false
}
if !(i.AccessHash == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (i *InputGameID) String() string {
if i == nil {
return "InputGameID(nil)"
}
type Alias InputGameID
return fmt.Sprintf("InputGameID%+v", Alias(*i))
}
// FillFrom fills InputGameID from given interface.
func (i *InputGameID) FillFrom(from interface {
GetID() (value int64)
GetAccessHash() (value int64)
}) {
i.ID = from.GetID()
i.AccessHash = from.GetAccessHash()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*InputGameID) TypeID() uint32 {
return InputGameIDTypeID
}
// TypeName returns name of type in TL schema.
func (*InputGameID) TypeName() string {
return "inputGameID"
}
// TypeInfo returns info about TL type.
func (i *InputGameID) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "inputGameID",
ID: InputGameIDTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "ID",
SchemaName: "id",
},
{
Name: "AccessHash",
SchemaName: "access_hash",
},
}
return typ
}
// Encode implements bin.Encoder.
func (i *InputGameID) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputGameID#32c3e77 as nil")
}
b.PutID(InputGameIDTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *InputGameID) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputGameID#32c3e77 as nil")
}
b.PutLong(i.ID)
b.PutLong(i.AccessHash)
return nil
}
// GetID returns value of ID field.
func (i *InputGameID) GetID() (value int64) {
return i.ID
}
// GetAccessHash returns value of AccessHash field.
func (i *InputGameID) GetAccessHash() (value int64) {
return i.AccessHash
}
// Decode implements bin.Decoder.
func (i *InputGameID) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputGameID#32c3e77 to nil")
}
if err := b.ConsumeID(InputGameIDTypeID); err != nil {
return fmt.Errorf("unable to decode inputGameID#32c3e77: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *InputGameID) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputGameID#32c3e77 to nil")
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode inputGameID#32c3e77: field id: %w", err)
}
i.ID = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode inputGameID#32c3e77: field access_hash: %w", err)
}
i.AccessHash = value
}
return nil
}
// construct implements constructor of InputGameClass.
func (i InputGameID) construct() InputGameClass { return &i }
// Ensuring interfaces in compile-time for InputGameID.
var (
_ bin.Encoder = &InputGameID{}
_ bin.Decoder = &InputGameID{}
_ bin.BareEncoder = &InputGameID{}
_ bin.BareDecoder = &InputGameID{}
_ InputGameClass = &InputGameID{}
)
// InputGameShortName represents TL type `inputGameShortName#c331e80a`.
// Game by short name
//
// See https://core.telegram.org/constructor/inputGameShortName for reference.
type InputGameShortName struct {
// The bot that provides the game
BotID InputUserClass
// The game's short name
ShortName string
}
// InputGameShortNameTypeID is TL type id of InputGameShortName.
const InputGameShortNameTypeID = 0xc331e80a
func (i *InputGameShortName) Zero() bool {
if i == nil {
return true
}
if !(i.BotID == nil) {
return false
}
if !(i.ShortName == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (i *InputGameShortName) String() string {
if i == nil {
return "InputGameShortName(nil)"
}
type Alias InputGameShortName
return fmt.Sprintf("InputGameShortName%+v", Alias(*i))
}
// FillFrom fills InputGameShortName from given interface.
func (i *InputGameShortName) FillFrom(from interface {
GetBotID() (value InputUserClass)
GetShortName() (value string)
}) {
i.BotID = from.GetBotID()
i.ShortName = from.GetShortName()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*InputGameShortName) TypeID() uint32 {
return InputGameShortNameTypeID
}
// TypeName returns name of type in TL schema.
func (*InputGameShortName) TypeName() string {
return "inputGameShortName"
}
// TypeInfo returns info about TL type.
func (i *InputGameShortName) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "inputGameShortName",
ID: InputGameShortNameTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "BotID",
SchemaName: "bot_id",
},
{
Name: "ShortName",
SchemaName: "short_name",
},
}
return typ
}
// Encode implements bin.Encoder.
func (i *InputGameShortName) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputGameShortName#c331e80a as nil")
}
b.PutID(InputGameShortNameTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *InputGameShortName) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputGameShortName#c331e80a as nil")
}
if i.BotID == nil {
return fmt.Errorf("unable to encode inputGameShortName#c331e80a: field bot_id is nil")
}
if err := i.BotID.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputGameShortName#c331e80a: field bot_id: %w", err)
}
b.PutString(i.ShortName)
return nil
}
// GetBotID returns value of BotID field.
func (i *InputGameShortName) GetBotID() (value InputUserClass) {
return i.BotID
}
// GetShortName returns value of ShortName field.
func (i *InputGameShortName) GetShortName() (value string) {
return i.ShortName
}
// Decode implements bin.Decoder.
func (i *InputGameShortName) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputGameShortName#c331e80a to nil")
}
if err := b.ConsumeID(InputGameShortNameTypeID); err != nil {
return fmt.Errorf("unable to decode inputGameShortName#c331e80a: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *InputGameShortName) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputGameShortName#c331e80a to nil")
}
{
value, err := DecodeInputUser(b)
if err != nil {
return fmt.Errorf("unable to decode inputGameShortName#c331e80a: field bot_id: %w", err)
}
i.BotID = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode inputGameShortName#c331e80a: field short_name: %w", err)
}
i.ShortName = value
}
return nil
}
// construct implements constructor of InputGameClass.
func (i InputGameShortName) construct() InputGameClass { return &i }
// Ensuring interfaces in compile-time for InputGameShortName.
var (
_ bin.Encoder = &InputGameShortName{}
_ bin.Decoder = &InputGameShortName{}
_ bin.BareEncoder = &InputGameShortName{}
_ bin.BareDecoder = &InputGameShortName{}
_ InputGameClass = &InputGameShortName{}
)
// InputGameClass represents InputGame generic type.
//
// See https://core.telegram.org/type/InputGame for reference.
//
// Example:
// g, err := tg.DecodeInputGame(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tg.InputGameID: // inputGameID#32c3e77
// case *tg.InputGameShortName: // inputGameShortName#c331e80a
// default: panic(v)
// }
type InputGameClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() InputGameClass
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
TypeID() uint32
// TypeName returns name of type in TL schema.
TypeName() string
// String implements fmt.Stringer.
String() string
// Zero returns true if current object has a zero value.
Zero() bool
}
// DecodeInputGame implements binary de-serialization for InputGameClass.
func DecodeInputGame(buf *bin.Buffer) (InputGameClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case InputGameIDTypeID:
// Decoding inputGameID#32c3e77.
v := InputGameID{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode InputGameClass: %w", err)
}
return &v, nil
case InputGameShortNameTypeID:
// Decoding inputGameShortName#c331e80a.
v := InputGameShortName{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode InputGameClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode InputGameClass: %w", bin.NewUnexpectedID(id))
}
}
// InputGame boxes the InputGameClass providing a helper.
type InputGameBox struct {
InputGame InputGameClass
}
// Decode implements bin.Decoder for InputGameBox.
func (b *InputGameBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode InputGameBox to nil")
}
v, err := DecodeInputGame(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.InputGame = v
return nil
}
// Encode implements bin.Encode for InputGameBox.
func (b *InputGameBox) Encode(buf *bin.Buffer) error {
if b == nil || b.InputGame == nil {
return fmt.Errorf("unable to encode InputGameClass as nil")
}
return b.InputGame.Encode(buf)
}
// InputGameClassArray is adapter for slice of InputGameClass.
type InputGameClassArray []InputGameClass
// Sort sorts slice of InputGameClass.
func (s InputGameClassArray) Sort(less func(a, b InputGameClass) bool) InputGameClassArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of InputGameClass.
func (s InputGameClassArray) SortStable(less func(a, b InputGameClass) bool) InputGameClassArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of InputGameClass.
func (s InputGameClassArray) Retain(keep func(x InputGameClass) bool) InputGameClassArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s InputGameClassArray) First() (v InputGameClass, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s InputGameClassArray) Last() (v InputGameClass, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputGameClassArray) PopFirst() (v InputGameClass, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero InputGameClass
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *InputGameClassArray) Pop() (v InputGameClass, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}
// AsInputGameID returns copy with only InputGameID constructors.
func (s InputGameClassArray) AsInputGameID() (to InputGameIDArray) {
for _, elem := range s {
value, ok := elem.(*InputGameID)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// AsInputGameShortName returns copy with only InputGameShortName constructors.
func (s InputGameClassArray) AsInputGameShortName() (to InputGameShortNameArray) {
for _, elem := range s {
value, ok := elem.(*InputGameShortName)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// InputGameIDArray is adapter for slice of InputGameID.
type InputGameIDArray []InputGameID
// Sort sorts slice of InputGameID.
func (s InputGameIDArray) Sort(less func(a, b InputGameID) bool) InputGameIDArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of InputGameID.
func (s InputGameIDArray) SortStable(less func(a, b InputGameID) bool) InputGameIDArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of InputGameID.
func (s InputGameIDArray) Retain(keep func(x InputGameID) bool) InputGameIDArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s InputGameIDArray) First() (v InputGameID, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s InputGameIDArray) Last() (v InputGameID, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputGameIDArray) PopFirst() (v InputGameID, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero InputGameID
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *InputGameIDArray) Pop() (v InputGameID, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}
// InputGameShortNameArray is adapter for slice of InputGameShortName.
type InputGameShortNameArray []InputGameShortName
// Sort sorts slice of InputGameShortName.
func (s InputGameShortNameArray) Sort(less func(a, b InputGameShortName) bool) InputGameShortNameArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of InputGameShortName.
func (s InputGameShortNameArray) SortStable(less func(a, b InputGameShortName) bool) InputGameShortNameArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of InputGameShortName.
func (s InputGameShortNameArray) Retain(keep func(x InputGameShortName) bool) InputGameShortNameArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s InputGameShortNameArray) First() (v InputGameShortName, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s InputGameShortNameArray) Last() (v InputGameShortName, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputGameShortNameArray) PopFirst() (v InputGameShortName, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero InputGameShortName
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *InputGameShortNameArray) Pop() (v InputGameShortName, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}