-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
tl_channel_messages_filter_gen.go
441 lines (390 loc) · 12.1 KB
/
tl_channel_messages_filter_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
// 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{}
)
// ChannelMessagesFilterEmpty represents TL type `channelMessagesFilterEmpty#94d42ee7`.
// No filter
//
// See https://core.telegram.org/constructor/channelMessagesFilterEmpty for reference.
type ChannelMessagesFilterEmpty struct {
}
// ChannelMessagesFilterEmptyTypeID is TL type id of ChannelMessagesFilterEmpty.
const ChannelMessagesFilterEmptyTypeID = 0x94d42ee7
// construct implements constructor of ChannelMessagesFilterClass.
func (c ChannelMessagesFilterEmpty) construct() ChannelMessagesFilterClass { return &c }
// Ensuring interfaces in compile-time for ChannelMessagesFilterEmpty.
var (
_ bin.Encoder = &ChannelMessagesFilterEmpty{}
_ bin.Decoder = &ChannelMessagesFilterEmpty{}
_ bin.BareEncoder = &ChannelMessagesFilterEmpty{}
_ bin.BareDecoder = &ChannelMessagesFilterEmpty{}
_ ChannelMessagesFilterClass = &ChannelMessagesFilterEmpty{}
)
func (c *ChannelMessagesFilterEmpty) Zero() bool {
if c == nil {
return true
}
return true
}
// String implements fmt.Stringer.
func (c *ChannelMessagesFilterEmpty) String() string {
if c == nil {
return "ChannelMessagesFilterEmpty(nil)"
}
type Alias ChannelMessagesFilterEmpty
return fmt.Sprintf("ChannelMessagesFilterEmpty%+v", Alias(*c))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ChannelMessagesFilterEmpty) TypeID() uint32 {
return ChannelMessagesFilterEmptyTypeID
}
// TypeName returns name of type in TL schema.
func (*ChannelMessagesFilterEmpty) TypeName() string {
return "channelMessagesFilterEmpty"
}
// TypeInfo returns info about TL type.
func (c *ChannelMessagesFilterEmpty) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "channelMessagesFilterEmpty",
ID: ChannelMessagesFilterEmptyTypeID,
}
if c == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{}
return typ
}
// Encode implements bin.Encoder.
func (c *ChannelMessagesFilterEmpty) Encode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode channelMessagesFilterEmpty#94d42ee7 as nil")
}
b.PutID(ChannelMessagesFilterEmptyTypeID)
return c.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (c *ChannelMessagesFilterEmpty) EncodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode channelMessagesFilterEmpty#94d42ee7 as nil")
}
return nil
}
// Decode implements bin.Decoder.
func (c *ChannelMessagesFilterEmpty) Decode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode channelMessagesFilterEmpty#94d42ee7 to nil")
}
if err := b.ConsumeID(ChannelMessagesFilterEmptyTypeID); err != nil {
return fmt.Errorf("unable to decode channelMessagesFilterEmpty#94d42ee7: %w", err)
}
return c.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (c *ChannelMessagesFilterEmpty) DecodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode channelMessagesFilterEmpty#94d42ee7 to nil")
}
return nil
}
// ChannelMessagesFilter represents TL type `channelMessagesFilter#cd77d957`.
// Filter for getting only certain types of channel messages
//
// See https://core.telegram.org/constructor/channelMessagesFilter for reference.
type ChannelMessagesFilter struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Whether to exclude new messages from the search
ExcludeNewMessages bool
// A range of messages to fetch
Ranges []MessageRange
}
// ChannelMessagesFilterTypeID is TL type id of ChannelMessagesFilter.
const ChannelMessagesFilterTypeID = 0xcd77d957
// construct implements constructor of ChannelMessagesFilterClass.
func (c ChannelMessagesFilter) construct() ChannelMessagesFilterClass { return &c }
// Ensuring interfaces in compile-time for ChannelMessagesFilter.
var (
_ bin.Encoder = &ChannelMessagesFilter{}
_ bin.Decoder = &ChannelMessagesFilter{}
_ bin.BareEncoder = &ChannelMessagesFilter{}
_ bin.BareDecoder = &ChannelMessagesFilter{}
_ ChannelMessagesFilterClass = &ChannelMessagesFilter{}
)
func (c *ChannelMessagesFilter) Zero() bool {
if c == nil {
return true
}
if !(c.Flags.Zero()) {
return false
}
if !(c.ExcludeNewMessages == false) {
return false
}
if !(c.Ranges == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (c *ChannelMessagesFilter) String() string {
if c == nil {
return "ChannelMessagesFilter(nil)"
}
type Alias ChannelMessagesFilter
return fmt.Sprintf("ChannelMessagesFilter%+v", Alias(*c))
}
// FillFrom fills ChannelMessagesFilter from given interface.
func (c *ChannelMessagesFilter) FillFrom(from interface {
GetExcludeNewMessages() (value bool)
GetRanges() (value []MessageRange)
}) {
c.ExcludeNewMessages = from.GetExcludeNewMessages()
c.Ranges = from.GetRanges()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ChannelMessagesFilter) TypeID() uint32 {
return ChannelMessagesFilterTypeID
}
// TypeName returns name of type in TL schema.
func (*ChannelMessagesFilter) TypeName() string {
return "channelMessagesFilter"
}
// TypeInfo returns info about TL type.
func (c *ChannelMessagesFilter) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "channelMessagesFilter",
ID: ChannelMessagesFilterTypeID,
}
if c == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "ExcludeNewMessages",
SchemaName: "exclude_new_messages",
Null: !c.Flags.Has(1),
},
{
Name: "Ranges",
SchemaName: "ranges",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (c *ChannelMessagesFilter) SetFlags() {
if !(c.ExcludeNewMessages == false) {
c.Flags.Set(1)
}
}
// Encode implements bin.Encoder.
func (c *ChannelMessagesFilter) Encode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode channelMessagesFilter#cd77d957 as nil")
}
b.PutID(ChannelMessagesFilterTypeID)
return c.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (c *ChannelMessagesFilter) EncodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode channelMessagesFilter#cd77d957 as nil")
}
c.SetFlags()
if err := c.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode channelMessagesFilter#cd77d957: field flags: %w", err)
}
b.PutVectorHeader(len(c.Ranges))
for idx, v := range c.Ranges {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode channelMessagesFilter#cd77d957: field ranges element with index %d: %w", idx, err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (c *ChannelMessagesFilter) Decode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode channelMessagesFilter#cd77d957 to nil")
}
if err := b.ConsumeID(ChannelMessagesFilterTypeID); err != nil {
return fmt.Errorf("unable to decode channelMessagesFilter#cd77d957: %w", err)
}
return c.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (c *ChannelMessagesFilter) DecodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode channelMessagesFilter#cd77d957 to nil")
}
{
if err := c.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode channelMessagesFilter#cd77d957: field flags: %w", err)
}
}
c.ExcludeNewMessages = c.Flags.Has(1)
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode channelMessagesFilter#cd77d957: field ranges: %w", err)
}
if headerLen > 0 {
c.Ranges = make([]MessageRange, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value MessageRange
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode channelMessagesFilter#cd77d957: field ranges: %w", err)
}
c.Ranges = append(c.Ranges, value)
}
}
return nil
}
// SetExcludeNewMessages sets value of ExcludeNewMessages conditional field.
func (c *ChannelMessagesFilter) SetExcludeNewMessages(value bool) {
if value {
c.Flags.Set(1)
c.ExcludeNewMessages = true
} else {
c.Flags.Unset(1)
c.ExcludeNewMessages = false
}
}
// GetExcludeNewMessages returns value of ExcludeNewMessages conditional field.
func (c *ChannelMessagesFilter) GetExcludeNewMessages() (value bool) {
if c == nil {
return
}
return c.Flags.Has(1)
}
// GetRanges returns value of Ranges field.
func (c *ChannelMessagesFilter) GetRanges() (value []MessageRange) {
if c == nil {
return
}
return c.Ranges
}
// ChannelMessagesFilterClassName is schema name of ChannelMessagesFilterClass.
const ChannelMessagesFilterClassName = "ChannelMessagesFilter"
// ChannelMessagesFilterClass represents ChannelMessagesFilter generic type.
//
// See https://core.telegram.org/type/ChannelMessagesFilter for reference.
//
// Example:
// g, err := tg.DecodeChannelMessagesFilter(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tg.ChannelMessagesFilterEmpty: // channelMessagesFilterEmpty#94d42ee7
// case *tg.ChannelMessagesFilter: // channelMessagesFilter#cd77d957
// default: panic(v)
// }
type ChannelMessagesFilterClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() ChannelMessagesFilterClass
// 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 ChannelMessagesFilterClass to ChannelMessagesFilter.
AsNotEmpty() (*ChannelMessagesFilter, bool)
}
// AsNotEmpty tries to map ChannelMessagesFilterEmpty to ChannelMessagesFilter.
func (c *ChannelMessagesFilterEmpty) AsNotEmpty() (*ChannelMessagesFilter, bool) {
return nil, false
}
// AsNotEmpty tries to map ChannelMessagesFilter to ChannelMessagesFilter.
func (c *ChannelMessagesFilter) AsNotEmpty() (*ChannelMessagesFilter, bool) {
return c, true
}
// DecodeChannelMessagesFilter implements binary de-serialization for ChannelMessagesFilterClass.
func DecodeChannelMessagesFilter(buf *bin.Buffer) (ChannelMessagesFilterClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case ChannelMessagesFilterEmptyTypeID:
// Decoding channelMessagesFilterEmpty#94d42ee7.
v := ChannelMessagesFilterEmpty{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode ChannelMessagesFilterClass: %w", err)
}
return &v, nil
case ChannelMessagesFilterTypeID:
// Decoding channelMessagesFilter#cd77d957.
v := ChannelMessagesFilter{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode ChannelMessagesFilterClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode ChannelMessagesFilterClass: %w", bin.NewUnexpectedID(id))
}
}
// ChannelMessagesFilter boxes the ChannelMessagesFilterClass providing a helper.
type ChannelMessagesFilterBox struct {
ChannelMessagesFilter ChannelMessagesFilterClass
}
// Decode implements bin.Decoder for ChannelMessagesFilterBox.
func (b *ChannelMessagesFilterBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode ChannelMessagesFilterBox to nil")
}
v, err := DecodeChannelMessagesFilter(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.ChannelMessagesFilter = v
return nil
}
// Encode implements bin.Encode for ChannelMessagesFilterBox.
func (b *ChannelMessagesFilterBox) Encode(buf *bin.Buffer) error {
if b == nil || b.ChannelMessagesFilter == nil {
return fmt.Errorf("unable to encode ChannelMessagesFilterClass as nil")
}
return b.ChannelMessagesFilter.Encode(buf)
}