-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
tl_input_photo_gen.go
658 lines (571 loc) · 14.7 KB
/
tl_input_photo_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
// 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{}
)
// InputPhotoEmpty represents TL type `inputPhotoEmpty#1cd7bf0d`.
// Empty constructor.
//
// See https://core.telegram.org/constructor/inputPhotoEmpty for reference.
type InputPhotoEmpty struct {
}
// InputPhotoEmptyTypeID is TL type id of InputPhotoEmpty.
const InputPhotoEmptyTypeID = 0x1cd7bf0d
func (i *InputPhotoEmpty) Zero() bool {
if i == nil {
return true
}
return true
}
// String implements fmt.Stringer.
func (i *InputPhotoEmpty) String() string {
if i == nil {
return "InputPhotoEmpty(nil)"
}
type Alias InputPhotoEmpty
return fmt.Sprintf("InputPhotoEmpty%+v", Alias(*i))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*InputPhotoEmpty) TypeID() uint32 {
return InputPhotoEmptyTypeID
}
// TypeName returns name of type in TL schema.
func (*InputPhotoEmpty) TypeName() string {
return "inputPhotoEmpty"
}
// TypeInfo returns info about TL type.
func (i *InputPhotoEmpty) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "inputPhotoEmpty",
ID: InputPhotoEmptyTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{}
return typ
}
// Encode implements bin.Encoder.
func (i *InputPhotoEmpty) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputPhotoEmpty#1cd7bf0d as nil")
}
b.PutID(InputPhotoEmptyTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *InputPhotoEmpty) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputPhotoEmpty#1cd7bf0d as nil")
}
return nil
}
// Decode implements bin.Decoder.
func (i *InputPhotoEmpty) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputPhotoEmpty#1cd7bf0d to nil")
}
if err := b.ConsumeID(InputPhotoEmptyTypeID); err != nil {
return fmt.Errorf("unable to decode inputPhotoEmpty#1cd7bf0d: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *InputPhotoEmpty) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputPhotoEmpty#1cd7bf0d to nil")
}
return nil
}
// construct implements constructor of InputPhotoClass.
func (i InputPhotoEmpty) construct() InputPhotoClass { return &i }
// Ensuring interfaces in compile-time for InputPhotoEmpty.
var (
_ bin.Encoder = &InputPhotoEmpty{}
_ bin.Decoder = &InputPhotoEmpty{}
_ bin.BareEncoder = &InputPhotoEmpty{}
_ bin.BareDecoder = &InputPhotoEmpty{}
_ InputPhotoClass = &InputPhotoEmpty{}
)
// InputPhoto represents TL type `inputPhoto#3bb3b94a`.
// Defines a photo for further interaction.
//
// See https://core.telegram.org/constructor/inputPhoto for reference.
type InputPhoto struct {
// Photo identifier
ID int64
// access_hash value from the photo¹ constructor
//
// Links:
// 1) https://core.telegram.org/constructor/photo
AccessHash int64
// File reference¹
//
// Links:
// 1) https://core.telegram.org/api/file_reference
FileReference []byte
}
// InputPhotoTypeID is TL type id of InputPhoto.
const InputPhotoTypeID = 0x3bb3b94a
func (i *InputPhoto) Zero() bool {
if i == nil {
return true
}
if !(i.ID == 0) {
return false
}
if !(i.AccessHash == 0) {
return false
}
if !(i.FileReference == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (i *InputPhoto) String() string {
if i == nil {
return "InputPhoto(nil)"
}
type Alias InputPhoto
return fmt.Sprintf("InputPhoto%+v", Alias(*i))
}
// FillFrom fills InputPhoto from given interface.
func (i *InputPhoto) FillFrom(from interface {
GetID() (value int64)
GetAccessHash() (value int64)
GetFileReference() (value []byte)
}) {
i.ID = from.GetID()
i.AccessHash = from.GetAccessHash()
i.FileReference = from.GetFileReference()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*InputPhoto) TypeID() uint32 {
return InputPhotoTypeID
}
// TypeName returns name of type in TL schema.
func (*InputPhoto) TypeName() string {
return "inputPhoto"
}
// TypeInfo returns info about TL type.
func (i *InputPhoto) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "inputPhoto",
ID: InputPhotoTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "ID",
SchemaName: "id",
},
{
Name: "AccessHash",
SchemaName: "access_hash",
},
{
Name: "FileReference",
SchemaName: "file_reference",
},
}
return typ
}
// Encode implements bin.Encoder.
func (i *InputPhoto) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputPhoto#3bb3b94a as nil")
}
b.PutID(InputPhotoTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *InputPhoto) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputPhoto#3bb3b94a as nil")
}
b.PutLong(i.ID)
b.PutLong(i.AccessHash)
b.PutBytes(i.FileReference)
return nil
}
// GetID returns value of ID field.
func (i *InputPhoto) GetID() (value int64) {
return i.ID
}
// GetAccessHash returns value of AccessHash field.
func (i *InputPhoto) GetAccessHash() (value int64) {
return i.AccessHash
}
// GetFileReference returns value of FileReference field.
func (i *InputPhoto) GetFileReference() (value []byte) {
return i.FileReference
}
// Decode implements bin.Decoder.
func (i *InputPhoto) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputPhoto#3bb3b94a to nil")
}
if err := b.ConsumeID(InputPhotoTypeID); err != nil {
return fmt.Errorf("unable to decode inputPhoto#3bb3b94a: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *InputPhoto) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputPhoto#3bb3b94a to nil")
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode inputPhoto#3bb3b94a: field id: %w", err)
}
i.ID = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode inputPhoto#3bb3b94a: field access_hash: %w", err)
}
i.AccessHash = value
}
{
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode inputPhoto#3bb3b94a: field file_reference: %w", err)
}
i.FileReference = value
}
return nil
}
// construct implements constructor of InputPhotoClass.
func (i InputPhoto) construct() InputPhotoClass { return &i }
// Ensuring interfaces in compile-time for InputPhoto.
var (
_ bin.Encoder = &InputPhoto{}
_ bin.Decoder = &InputPhoto{}
_ bin.BareEncoder = &InputPhoto{}
_ bin.BareDecoder = &InputPhoto{}
_ InputPhotoClass = &InputPhoto{}
)
// InputPhotoClass represents InputPhoto generic type.
//
// See https://core.telegram.org/type/InputPhoto for reference.
//
// Example:
// g, err := tg.DecodeInputPhoto(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tg.InputPhotoEmpty: // inputPhotoEmpty#1cd7bf0d
// case *tg.InputPhoto: // inputPhoto#3bb3b94a
// default: panic(v)
// }
type InputPhotoClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() InputPhotoClass
// 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
// AsNotEmpty tries to map InputPhotoClass to InputPhoto.
AsNotEmpty() (*InputPhoto, bool)
}
// AsInputPhotoFileLocation tries to map InputPhoto to InputPhotoFileLocation.
func (i *InputPhoto) AsInputPhotoFileLocation() *InputPhotoFileLocation {
value := new(InputPhotoFileLocation)
value.ID = i.GetID()
value.AccessHash = i.GetAccessHash()
value.FileReference = i.GetFileReference()
return value
}
// AsNotEmpty tries to map InputPhotoEmpty to InputPhoto.
func (i *InputPhotoEmpty) AsNotEmpty() (*InputPhoto, bool) {
return nil, false
}
// AsNotEmpty tries to map InputPhoto to InputPhoto.
func (i *InputPhoto) AsNotEmpty() (*InputPhoto, bool) {
return i, true
}
// DecodeInputPhoto implements binary de-serialization for InputPhotoClass.
func DecodeInputPhoto(buf *bin.Buffer) (InputPhotoClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case InputPhotoEmptyTypeID:
// Decoding inputPhotoEmpty#1cd7bf0d.
v := InputPhotoEmpty{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode InputPhotoClass: %w", err)
}
return &v, nil
case InputPhotoTypeID:
// Decoding inputPhoto#3bb3b94a.
v := InputPhoto{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode InputPhotoClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode InputPhotoClass: %w", bin.NewUnexpectedID(id))
}
}
// InputPhoto boxes the InputPhotoClass providing a helper.
type InputPhotoBox struct {
InputPhoto InputPhotoClass
}
// Decode implements bin.Decoder for InputPhotoBox.
func (b *InputPhotoBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode InputPhotoBox to nil")
}
v, err := DecodeInputPhoto(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.InputPhoto = v
return nil
}
// Encode implements bin.Encode for InputPhotoBox.
func (b *InputPhotoBox) Encode(buf *bin.Buffer) error {
if b == nil || b.InputPhoto == nil {
return fmt.Errorf("unable to encode InputPhotoClass as nil")
}
return b.InputPhoto.Encode(buf)
}
// InputPhotoClassArray is adapter for slice of InputPhotoClass.
type InputPhotoClassArray []InputPhotoClass
// Sort sorts slice of InputPhotoClass.
func (s InputPhotoClassArray) Sort(less func(a, b InputPhotoClass) bool) InputPhotoClassArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of InputPhotoClass.
func (s InputPhotoClassArray) SortStable(less func(a, b InputPhotoClass) bool) InputPhotoClassArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of InputPhotoClass.
func (s InputPhotoClassArray) Retain(keep func(x InputPhotoClass) bool) InputPhotoClassArray {
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 InputPhotoClassArray) First() (v InputPhotoClass, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s InputPhotoClassArray) Last() (v InputPhotoClass, 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 *InputPhotoClassArray) PopFirst() (v InputPhotoClass, 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 InputPhotoClass
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 *InputPhotoClassArray) Pop() (v InputPhotoClass, 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
}
// AsInputPhoto returns copy with only InputPhoto constructors.
func (s InputPhotoClassArray) AsInputPhoto() (to InputPhotoArray) {
for _, elem := range s {
value, ok := elem.(*InputPhoto)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// AppendOnlyNotEmpty appends only NotEmpty constructors to
// given slice.
func (s InputPhotoClassArray) AppendOnlyNotEmpty(to []*InputPhoto) []*InputPhoto {
for _, elem := range s {
value, ok := elem.AsNotEmpty()
if !ok {
continue
}
to = append(to, value)
}
return to
}
// AsNotEmpty returns copy with only NotEmpty constructors.
func (s InputPhotoClassArray) AsNotEmpty() (to []*InputPhoto) {
return s.AppendOnlyNotEmpty(to)
}
// FirstAsNotEmpty returns first element of slice (if exists).
func (s InputPhotoClassArray) FirstAsNotEmpty() (v *InputPhoto, ok bool) {
value, ok := s.First()
if !ok {
return
}
return value.AsNotEmpty()
}
// LastAsNotEmpty returns last element of slice (if exists).
func (s InputPhotoClassArray) LastAsNotEmpty() (v *InputPhoto, ok bool) {
value, ok := s.Last()
if !ok {
return
}
return value.AsNotEmpty()
}
// PopFirstAsNotEmpty returns element of slice (if exists).
func (s *InputPhotoClassArray) PopFirstAsNotEmpty() (v *InputPhoto, ok bool) {
value, ok := s.PopFirst()
if !ok {
return
}
return value.AsNotEmpty()
}
// PopAsNotEmpty returns element of slice (if exists).
func (s *InputPhotoClassArray) PopAsNotEmpty() (v *InputPhoto, ok bool) {
value, ok := s.Pop()
if !ok {
return
}
return value.AsNotEmpty()
}
// InputPhotoArray is adapter for slice of InputPhoto.
type InputPhotoArray []InputPhoto
// Sort sorts slice of InputPhoto.
func (s InputPhotoArray) Sort(less func(a, b InputPhoto) bool) InputPhotoArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of InputPhoto.
func (s InputPhotoArray) SortStable(less func(a, b InputPhoto) bool) InputPhotoArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of InputPhoto.
func (s InputPhotoArray) Retain(keep func(x InputPhoto) bool) InputPhotoArray {
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 InputPhotoArray) First() (v InputPhoto, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s InputPhotoArray) Last() (v InputPhoto, 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 *InputPhotoArray) PopFirst() (v InputPhoto, 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 InputPhoto
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 *InputPhotoArray) Pop() (v InputPhoto, 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
}