-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
tl_attach_menu_bot_icon_gen.go
279 lines (252 loc) · 6.46 KB
/
tl_attach_menu_bot_icon_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
// 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{}
)
// AttachMenuBotIcon represents TL type `attachMenuBotIcon#b2a7386b`.
//
// See https://core.telegram.org/constructor/attachMenuBotIcon for reference.
type AttachMenuBotIcon struct {
// Flags field of AttachMenuBotIcon.
Flags bin.Fields
// Name field of AttachMenuBotIcon.
Name string
// Icon field of AttachMenuBotIcon.
Icon DocumentClass
// Colors field of AttachMenuBotIcon.
//
// Use SetColors and GetColors helpers.
Colors []AttachMenuBotIconColor
}
// AttachMenuBotIconTypeID is TL type id of AttachMenuBotIcon.
const AttachMenuBotIconTypeID = 0xb2a7386b
// Ensuring interfaces in compile-time for AttachMenuBotIcon.
var (
_ bin.Encoder = &AttachMenuBotIcon{}
_ bin.Decoder = &AttachMenuBotIcon{}
_ bin.BareEncoder = &AttachMenuBotIcon{}
_ bin.BareDecoder = &AttachMenuBotIcon{}
)
func (a *AttachMenuBotIcon) Zero() bool {
if a == nil {
return true
}
if !(a.Flags.Zero()) {
return false
}
if !(a.Name == "") {
return false
}
if !(a.Icon == nil) {
return false
}
if !(a.Colors == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (a *AttachMenuBotIcon) String() string {
if a == nil {
return "AttachMenuBotIcon(nil)"
}
type Alias AttachMenuBotIcon
return fmt.Sprintf("AttachMenuBotIcon%+v", Alias(*a))
}
// FillFrom fills AttachMenuBotIcon from given interface.
func (a *AttachMenuBotIcon) FillFrom(from interface {
GetName() (value string)
GetIcon() (value DocumentClass)
GetColors() (value []AttachMenuBotIconColor, ok bool)
}) {
a.Name = from.GetName()
a.Icon = from.GetIcon()
if val, ok := from.GetColors(); ok {
a.Colors = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*AttachMenuBotIcon) TypeID() uint32 {
return AttachMenuBotIconTypeID
}
// TypeName returns name of type in TL schema.
func (*AttachMenuBotIcon) TypeName() string {
return "attachMenuBotIcon"
}
// TypeInfo returns info about TL type.
func (a *AttachMenuBotIcon) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "attachMenuBotIcon",
ID: AttachMenuBotIconTypeID,
}
if a == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Name",
SchemaName: "name",
},
{
Name: "Icon",
SchemaName: "icon",
},
{
Name: "Colors",
SchemaName: "colors",
Null: !a.Flags.Has(0),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (a *AttachMenuBotIcon) SetFlags() {
if !(a.Colors == nil) {
a.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (a *AttachMenuBotIcon) Encode(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't encode attachMenuBotIcon#b2a7386b as nil")
}
b.PutID(AttachMenuBotIconTypeID)
return a.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (a *AttachMenuBotIcon) EncodeBare(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't encode attachMenuBotIcon#b2a7386b as nil")
}
a.SetFlags()
if err := a.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode attachMenuBotIcon#b2a7386b: field flags: %w", err)
}
b.PutString(a.Name)
if a.Icon == nil {
return fmt.Errorf("unable to encode attachMenuBotIcon#b2a7386b: field icon is nil")
}
if err := a.Icon.Encode(b); err != nil {
return fmt.Errorf("unable to encode attachMenuBotIcon#b2a7386b: field icon: %w", err)
}
if a.Flags.Has(0) {
b.PutVectorHeader(len(a.Colors))
for idx, v := range a.Colors {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode attachMenuBotIcon#b2a7386b: field colors element with index %d: %w", idx, err)
}
}
}
return nil
}
// Decode implements bin.Decoder.
func (a *AttachMenuBotIcon) Decode(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't decode attachMenuBotIcon#b2a7386b to nil")
}
if err := b.ConsumeID(AttachMenuBotIconTypeID); err != nil {
return fmt.Errorf("unable to decode attachMenuBotIcon#b2a7386b: %w", err)
}
return a.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (a *AttachMenuBotIcon) DecodeBare(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't decode attachMenuBotIcon#b2a7386b to nil")
}
{
if err := a.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode attachMenuBotIcon#b2a7386b: field flags: %w", err)
}
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode attachMenuBotIcon#b2a7386b: field name: %w", err)
}
a.Name = value
}
{
value, err := DecodeDocument(b)
if err != nil {
return fmt.Errorf("unable to decode attachMenuBotIcon#b2a7386b: field icon: %w", err)
}
a.Icon = value
}
if a.Flags.Has(0) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode attachMenuBotIcon#b2a7386b: field colors: %w", err)
}
if headerLen > 0 {
a.Colors = make([]AttachMenuBotIconColor, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value AttachMenuBotIconColor
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode attachMenuBotIcon#b2a7386b: field colors: %w", err)
}
a.Colors = append(a.Colors, value)
}
}
return nil
}
// GetName returns value of Name field.
func (a *AttachMenuBotIcon) GetName() (value string) {
if a == nil {
return
}
return a.Name
}
// GetIcon returns value of Icon field.
func (a *AttachMenuBotIcon) GetIcon() (value DocumentClass) {
if a == nil {
return
}
return a.Icon
}
// SetColors sets value of Colors conditional field.
func (a *AttachMenuBotIcon) SetColors(value []AttachMenuBotIconColor) {
a.Flags.Set(0)
a.Colors = value
}
// GetColors returns value of Colors conditional field and
// boolean which is true if field was set.
func (a *AttachMenuBotIcon) GetColors() (value []AttachMenuBotIconColor, ok bool) {
if a == nil {
return
}
if !a.Flags.Has(0) {
return value, false
}
return a.Colors, true
}
// GetIconAsNotEmpty returns mapped value of Icon field.
func (a *AttachMenuBotIcon) GetIconAsNotEmpty() (*Document, bool) {
return a.Icon.AsNotEmpty()
}