-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
tl_stats_graph_gen.go
613 lines (546 loc) · 14.2 KB
/
tl_stats_graph_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
// 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{}
)
// StatsGraphAsync represents TL type `statsGraphAsync#4a27eb2d`.
// This channel statistics graph¹ must be generated asynchronously using stats
// loadAsyncGraph² to reduce server load
//
// Links:
// 1) https://core.telegram.org/api/stats
// 2) https://core.telegram.org/method/stats.loadAsyncGraph
//
// See https://core.telegram.org/constructor/statsGraphAsync for reference.
type StatsGraphAsync struct {
// Token to use for fetching the async graph
Token string
}
// StatsGraphAsyncTypeID is TL type id of StatsGraphAsync.
const StatsGraphAsyncTypeID = 0x4a27eb2d
// construct implements constructor of StatsGraphClass.
func (s StatsGraphAsync) construct() StatsGraphClass { return &s }
// Ensuring interfaces in compile-time for StatsGraphAsync.
var (
_ bin.Encoder = &StatsGraphAsync{}
_ bin.Decoder = &StatsGraphAsync{}
_ bin.BareEncoder = &StatsGraphAsync{}
_ bin.BareDecoder = &StatsGraphAsync{}
_ StatsGraphClass = &StatsGraphAsync{}
)
func (s *StatsGraphAsync) Zero() bool {
if s == nil {
return true
}
if !(s.Token == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *StatsGraphAsync) String() string {
if s == nil {
return "StatsGraphAsync(nil)"
}
type Alias StatsGraphAsync
return fmt.Sprintf("StatsGraphAsync%+v", Alias(*s))
}
// FillFrom fills StatsGraphAsync from given interface.
func (s *StatsGraphAsync) FillFrom(from interface {
GetToken() (value string)
}) {
s.Token = from.GetToken()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*StatsGraphAsync) TypeID() uint32 {
return StatsGraphAsyncTypeID
}
// TypeName returns name of type in TL schema.
func (*StatsGraphAsync) TypeName() string {
return "statsGraphAsync"
}
// TypeInfo returns info about TL type.
func (s *StatsGraphAsync) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "statsGraphAsync",
ID: StatsGraphAsyncTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Token",
SchemaName: "token",
},
}
return typ
}
// Encode implements bin.Encoder.
func (s *StatsGraphAsync) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode statsGraphAsync#4a27eb2d as nil")
}
b.PutID(StatsGraphAsyncTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *StatsGraphAsync) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode statsGraphAsync#4a27eb2d as nil")
}
b.PutString(s.Token)
return nil
}
// Decode implements bin.Decoder.
func (s *StatsGraphAsync) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode statsGraphAsync#4a27eb2d to nil")
}
if err := b.ConsumeID(StatsGraphAsyncTypeID); err != nil {
return fmt.Errorf("unable to decode statsGraphAsync#4a27eb2d: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *StatsGraphAsync) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode statsGraphAsync#4a27eb2d to nil")
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode statsGraphAsync#4a27eb2d: field token: %w", err)
}
s.Token = value
}
return nil
}
// GetToken returns value of Token field.
func (s *StatsGraphAsync) GetToken() (value string) {
if s == nil {
return
}
return s.Token
}
// StatsGraphError represents TL type `statsGraphError#bedc9822`.
// An error occurred while generating the statistics graph¹
//
// Links:
// 1) https://core.telegram.org/api/stats
//
// See https://core.telegram.org/constructor/statsGraphError for reference.
type StatsGraphError struct {
// The error
Error string
}
// StatsGraphErrorTypeID is TL type id of StatsGraphError.
const StatsGraphErrorTypeID = 0xbedc9822
// construct implements constructor of StatsGraphClass.
func (s StatsGraphError) construct() StatsGraphClass { return &s }
// Ensuring interfaces in compile-time for StatsGraphError.
var (
_ bin.Encoder = &StatsGraphError{}
_ bin.Decoder = &StatsGraphError{}
_ bin.BareEncoder = &StatsGraphError{}
_ bin.BareDecoder = &StatsGraphError{}
_ StatsGraphClass = &StatsGraphError{}
)
func (s *StatsGraphError) Zero() bool {
if s == nil {
return true
}
if !(s.Error == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *StatsGraphError) String() string {
if s == nil {
return "StatsGraphError(nil)"
}
type Alias StatsGraphError
return fmt.Sprintf("StatsGraphError%+v", Alias(*s))
}
// FillFrom fills StatsGraphError from given interface.
func (s *StatsGraphError) FillFrom(from interface {
GetError() (value string)
}) {
s.Error = from.GetError()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*StatsGraphError) TypeID() uint32 {
return StatsGraphErrorTypeID
}
// TypeName returns name of type in TL schema.
func (*StatsGraphError) TypeName() string {
return "statsGraphError"
}
// TypeInfo returns info about TL type.
func (s *StatsGraphError) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "statsGraphError",
ID: StatsGraphErrorTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Error",
SchemaName: "error",
},
}
return typ
}
// Encode implements bin.Encoder.
func (s *StatsGraphError) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode statsGraphError#bedc9822 as nil")
}
b.PutID(StatsGraphErrorTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *StatsGraphError) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode statsGraphError#bedc9822 as nil")
}
b.PutString(s.Error)
return nil
}
// Decode implements bin.Decoder.
func (s *StatsGraphError) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode statsGraphError#bedc9822 to nil")
}
if err := b.ConsumeID(StatsGraphErrorTypeID); err != nil {
return fmt.Errorf("unable to decode statsGraphError#bedc9822: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *StatsGraphError) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode statsGraphError#bedc9822 to nil")
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode statsGraphError#bedc9822: field error: %w", err)
}
s.Error = value
}
return nil
}
// GetError returns value of Error field.
func (s *StatsGraphError) GetError() (value string) {
if s == nil {
return
}
return s.Error
}
// StatsGraph represents TL type `statsGraph#8ea464b6`.
// Channel statistics graph¹
//
// Links:
// 1) https://core.telegram.org/api/stats
//
// See https://core.telegram.org/constructor/statsGraph for reference.
type StatsGraph struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Statistics data
JSON DataJSON
// Zoom token
//
// Use SetZoomToken and GetZoomToken helpers.
ZoomToken string
}
// StatsGraphTypeID is TL type id of StatsGraph.
const StatsGraphTypeID = 0x8ea464b6
// construct implements constructor of StatsGraphClass.
func (s StatsGraph) construct() StatsGraphClass { return &s }
// Ensuring interfaces in compile-time for StatsGraph.
var (
_ bin.Encoder = &StatsGraph{}
_ bin.Decoder = &StatsGraph{}
_ bin.BareEncoder = &StatsGraph{}
_ bin.BareDecoder = &StatsGraph{}
_ StatsGraphClass = &StatsGraph{}
)
func (s *StatsGraph) Zero() bool {
if s == nil {
return true
}
if !(s.Flags.Zero()) {
return false
}
if !(s.JSON.Zero()) {
return false
}
if !(s.ZoomToken == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *StatsGraph) String() string {
if s == nil {
return "StatsGraph(nil)"
}
type Alias StatsGraph
return fmt.Sprintf("StatsGraph%+v", Alias(*s))
}
// FillFrom fills StatsGraph from given interface.
func (s *StatsGraph) FillFrom(from interface {
GetJSON() (value DataJSON)
GetZoomToken() (value string, ok bool)
}) {
s.JSON = from.GetJSON()
if val, ok := from.GetZoomToken(); ok {
s.ZoomToken = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*StatsGraph) TypeID() uint32 {
return StatsGraphTypeID
}
// TypeName returns name of type in TL schema.
func (*StatsGraph) TypeName() string {
return "statsGraph"
}
// TypeInfo returns info about TL type.
func (s *StatsGraph) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "statsGraph",
ID: StatsGraphTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "JSON",
SchemaName: "json",
},
{
Name: "ZoomToken",
SchemaName: "zoom_token",
Null: !s.Flags.Has(0),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (s *StatsGraph) SetFlags() {
if !(s.ZoomToken == "") {
s.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (s *StatsGraph) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode statsGraph#8ea464b6 as nil")
}
b.PutID(StatsGraphTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *StatsGraph) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode statsGraph#8ea464b6 as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode statsGraph#8ea464b6: field flags: %w", err)
}
if err := s.JSON.Encode(b); err != nil {
return fmt.Errorf("unable to encode statsGraph#8ea464b6: field json: %w", err)
}
if s.Flags.Has(0) {
b.PutString(s.ZoomToken)
}
return nil
}
// Decode implements bin.Decoder.
func (s *StatsGraph) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode statsGraph#8ea464b6 to nil")
}
if err := b.ConsumeID(StatsGraphTypeID); err != nil {
return fmt.Errorf("unable to decode statsGraph#8ea464b6: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *StatsGraph) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode statsGraph#8ea464b6 to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode statsGraph#8ea464b6: field flags: %w", err)
}
}
{
if err := s.JSON.Decode(b); err != nil {
return fmt.Errorf("unable to decode statsGraph#8ea464b6: field json: %w", err)
}
}
if s.Flags.Has(0) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode statsGraph#8ea464b6: field zoom_token: %w", err)
}
s.ZoomToken = value
}
return nil
}
// GetJSON returns value of JSON field.
func (s *StatsGraph) GetJSON() (value DataJSON) {
if s == nil {
return
}
return s.JSON
}
// SetZoomToken sets value of ZoomToken conditional field.
func (s *StatsGraph) SetZoomToken(value string) {
s.Flags.Set(0)
s.ZoomToken = value
}
// GetZoomToken returns value of ZoomToken conditional field and
// boolean which is true if field was set.
func (s *StatsGraph) GetZoomToken() (value string, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(0) {
return value, false
}
return s.ZoomToken, true
}
// StatsGraphClassName is schema name of StatsGraphClass.
const StatsGraphClassName = "StatsGraph"
// StatsGraphClass represents StatsGraph generic type.
//
// See https://core.telegram.org/type/StatsGraph for reference.
//
// Example:
// g, err := tg.DecodeStatsGraph(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tg.StatsGraphAsync: // statsGraphAsync#4a27eb2d
// case *tg.StatsGraphError: // statsGraphError#bedc9822
// case *tg.StatsGraph: // statsGraph#8ea464b6
// default: panic(v)
// }
type StatsGraphClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() StatsGraphClass
// 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
}
// DecodeStatsGraph implements binary de-serialization for StatsGraphClass.
func DecodeStatsGraph(buf *bin.Buffer) (StatsGraphClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case StatsGraphAsyncTypeID:
// Decoding statsGraphAsync#4a27eb2d.
v := StatsGraphAsync{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", err)
}
return &v, nil
case StatsGraphErrorTypeID:
// Decoding statsGraphError#bedc9822.
v := StatsGraphError{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", err)
}
return &v, nil
case StatsGraphTypeID:
// Decoding statsGraph#8ea464b6.
v := StatsGraph{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode StatsGraphClass: %w", bin.NewUnexpectedID(id))
}
}
// StatsGraph boxes the StatsGraphClass providing a helper.
type StatsGraphBox struct {
StatsGraph StatsGraphClass
}
// Decode implements bin.Decoder for StatsGraphBox.
func (b *StatsGraphBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode StatsGraphBox to nil")
}
v, err := DecodeStatsGraph(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.StatsGraph = v
return nil
}
// Encode implements bin.Encode for StatsGraphBox.
func (b *StatsGraphBox) Encode(buf *bin.Buffer) error {
if b == nil || b.StatsGraph == nil {
return fmt.Errorf("unable to encode StatsGraphClass as nil")
}
return b.StatsGraph.Encode(buf)
}