-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
tl_theme_gen.go
437 lines (402 loc) · 9.08 KB
/
tl_theme_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
// 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{}
)
// Theme represents TL type `theme#28f1114`.
// Theme
//
// See https://core.telegram.org/constructor/theme for reference.
type Theme struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Whether the current user is the creator of this theme
Creator bool
// Whether this is the default theme
Default bool
// Theme ID
ID int64
// Theme access hash
AccessHash int64
// Unique theme ID
Slug string
// Theme name
Title string
// Theme
//
// Use SetDocument and GetDocument helpers.
Document DocumentClass
// Theme settings
//
// Use SetSettings and GetSettings helpers.
Settings ThemeSettings
// Installation count
InstallsCount int
}
// ThemeTypeID is TL type id of Theme.
const ThemeTypeID = 0x28f1114
func (t *Theme) Zero() bool {
if t == nil {
return true
}
if !(t.Flags.Zero()) {
return false
}
if !(t.Creator == false) {
return false
}
if !(t.Default == false) {
return false
}
if !(t.ID == 0) {
return false
}
if !(t.AccessHash == 0) {
return false
}
if !(t.Slug == "") {
return false
}
if !(t.Title == "") {
return false
}
if !(t.Document == nil) {
return false
}
if !(t.Settings.Zero()) {
return false
}
if !(t.InstallsCount == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (t *Theme) String() string {
if t == nil {
return "Theme(nil)"
}
type Alias Theme
return fmt.Sprintf("Theme%+v", Alias(*t))
}
// FillFrom fills Theme from given interface.
func (t *Theme) FillFrom(from interface {
GetCreator() (value bool)
GetDefault() (value bool)
GetID() (value int64)
GetAccessHash() (value int64)
GetSlug() (value string)
GetTitle() (value string)
GetDocument() (value DocumentClass, ok bool)
GetSettings() (value ThemeSettings, ok bool)
GetInstallsCount() (value int)
}) {
t.Creator = from.GetCreator()
t.Default = from.GetDefault()
t.ID = from.GetID()
t.AccessHash = from.GetAccessHash()
t.Slug = from.GetSlug()
t.Title = from.GetTitle()
if val, ok := from.GetDocument(); ok {
t.Document = val
}
if val, ok := from.GetSettings(); ok {
t.Settings = val
}
t.InstallsCount = from.GetInstallsCount()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*Theme) TypeID() uint32 {
return ThemeTypeID
}
// TypeName returns name of type in TL schema.
func (*Theme) TypeName() string {
return "theme"
}
// TypeInfo returns info about TL type.
func (t *Theme) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "theme",
ID: ThemeTypeID,
}
if t == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Creator",
SchemaName: "creator",
Null: !t.Flags.Has(0),
},
{
Name: "Default",
SchemaName: "default",
Null: !t.Flags.Has(1),
},
{
Name: "ID",
SchemaName: "id",
},
{
Name: "AccessHash",
SchemaName: "access_hash",
},
{
Name: "Slug",
SchemaName: "slug",
},
{
Name: "Title",
SchemaName: "title",
},
{
Name: "Document",
SchemaName: "document",
Null: !t.Flags.Has(2),
},
{
Name: "Settings",
SchemaName: "settings",
Null: !t.Flags.Has(3),
},
{
Name: "InstallsCount",
SchemaName: "installs_count",
},
}
return typ
}
// Encode implements bin.Encoder.
func (t *Theme) Encode(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't encode theme#28f1114 as nil")
}
b.PutID(ThemeTypeID)
return t.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (t *Theme) EncodeBare(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't encode theme#28f1114 as nil")
}
if !(t.Creator == false) {
t.Flags.Set(0)
}
if !(t.Default == false) {
t.Flags.Set(1)
}
if !(t.Document == nil) {
t.Flags.Set(2)
}
if !(t.Settings.Zero()) {
t.Flags.Set(3)
}
if err := t.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode theme#28f1114: field flags: %w", err)
}
b.PutLong(t.ID)
b.PutLong(t.AccessHash)
b.PutString(t.Slug)
b.PutString(t.Title)
if t.Flags.Has(2) {
if t.Document == nil {
return fmt.Errorf("unable to encode theme#28f1114: field document is nil")
}
if err := t.Document.Encode(b); err != nil {
return fmt.Errorf("unable to encode theme#28f1114: field document: %w", err)
}
}
if t.Flags.Has(3) {
if err := t.Settings.Encode(b); err != nil {
return fmt.Errorf("unable to encode theme#28f1114: field settings: %w", err)
}
}
b.PutInt(t.InstallsCount)
return nil
}
// SetCreator sets value of Creator conditional field.
func (t *Theme) SetCreator(value bool) {
if value {
t.Flags.Set(0)
t.Creator = true
} else {
t.Flags.Unset(0)
t.Creator = false
}
}
// GetCreator returns value of Creator conditional field.
func (t *Theme) GetCreator() (value bool) {
return t.Flags.Has(0)
}
// SetDefault sets value of Default conditional field.
func (t *Theme) SetDefault(value bool) {
if value {
t.Flags.Set(1)
t.Default = true
} else {
t.Flags.Unset(1)
t.Default = false
}
}
// GetDefault returns value of Default conditional field.
func (t *Theme) GetDefault() (value bool) {
return t.Flags.Has(1)
}
// GetID returns value of ID field.
func (t *Theme) GetID() (value int64) {
return t.ID
}
// GetAccessHash returns value of AccessHash field.
func (t *Theme) GetAccessHash() (value int64) {
return t.AccessHash
}
// GetSlug returns value of Slug field.
func (t *Theme) GetSlug() (value string) {
return t.Slug
}
// GetTitle returns value of Title field.
func (t *Theme) GetTitle() (value string) {
return t.Title
}
// SetDocument sets value of Document conditional field.
func (t *Theme) SetDocument(value DocumentClass) {
t.Flags.Set(2)
t.Document = value
}
// GetDocument returns value of Document conditional field and
// boolean which is true if field was set.
func (t *Theme) GetDocument() (value DocumentClass, ok bool) {
if !t.Flags.Has(2) {
return value, false
}
return t.Document, true
}
// GetDocumentAsNotEmpty returns mapped value of Document conditional field and
// boolean which is true if field was set.
func (t *Theme) GetDocumentAsNotEmpty() (*Document, bool) {
if value, ok := t.GetDocument(); ok {
return value.AsNotEmpty()
}
return nil, false
}
// SetSettings sets value of Settings conditional field.
func (t *Theme) SetSettings(value ThemeSettings) {
t.Flags.Set(3)
t.Settings = value
}
// GetSettings returns value of Settings conditional field and
// boolean which is true if field was set.
func (t *Theme) GetSettings() (value ThemeSettings, ok bool) {
if !t.Flags.Has(3) {
return value, false
}
return t.Settings, true
}
// GetInstallsCount returns value of InstallsCount field.
func (t *Theme) GetInstallsCount() (value int) {
return t.InstallsCount
}
// Decode implements bin.Decoder.
func (t *Theme) Decode(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't decode theme#28f1114 to nil")
}
if err := b.ConsumeID(ThemeTypeID); err != nil {
return fmt.Errorf("unable to decode theme#28f1114: %w", err)
}
return t.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (t *Theme) DecodeBare(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't decode theme#28f1114 to nil")
}
{
if err := t.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field flags: %w", err)
}
}
t.Creator = t.Flags.Has(0)
t.Default = t.Flags.Has(1)
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field id: %w", err)
}
t.ID = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field access_hash: %w", err)
}
t.AccessHash = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field slug: %w", err)
}
t.Slug = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field title: %w", err)
}
t.Title = value
}
if t.Flags.Has(2) {
value, err := DecodeDocument(b)
if err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field document: %w", err)
}
t.Document = value
}
if t.Flags.Has(3) {
if err := t.Settings.Decode(b); err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field settings: %w", err)
}
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode theme#28f1114: field installs_count: %w", err)
}
t.InstallsCount = value
}
return nil
}
// Ensuring interfaces in compile-time for Theme.
var (
_ bin.Encoder = &Theme{}
_ bin.Decoder = &Theme{}
_ bin.BareEncoder = &Theme{}
_ bin.BareDecoder = &Theme{}
)