-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
tl_input_single_media_gen.go
323 lines (295 loc) · 7.65 KB
/
tl_input_single_media_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
// 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{}
)
// InputSingleMedia represents TL type `inputSingleMedia#1cc6e91f`.
// A single media in an album or grouped media¹ sent with messages.sendMultiMedia².
//
// Links:
// 1. https://core.telegram.org/api/files#albums-grouped-media
// 2. https://core.telegram.org/method/messages.sendMultiMedia
//
// See https://core.telegram.org/constructor/inputSingleMedia for reference.
type InputSingleMedia struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// The media
Media InputMediaClass
// Unique client media ID required to prevent message resending
RandomID int64
// A caption for the media
Message string
// Message entities¹ for styled text
//
// Links:
// 1) https://core.telegram.org/api/entities
//
// Use SetEntities and GetEntities helpers.
Entities []MessageEntityClass
}
// InputSingleMediaTypeID is TL type id of InputSingleMedia.
const InputSingleMediaTypeID = 0x1cc6e91f
// Ensuring interfaces in compile-time for InputSingleMedia.
var (
_ bin.Encoder = &InputSingleMedia{}
_ bin.Decoder = &InputSingleMedia{}
_ bin.BareEncoder = &InputSingleMedia{}
_ bin.BareDecoder = &InputSingleMedia{}
)
func (i *InputSingleMedia) Zero() bool {
if i == nil {
return true
}
if !(i.Flags.Zero()) {
return false
}
if !(i.Media == nil) {
return false
}
if !(i.RandomID == 0) {
return false
}
if !(i.Message == "") {
return false
}
if !(i.Entities == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (i *InputSingleMedia) String() string {
if i == nil {
return "InputSingleMedia(nil)"
}
type Alias InputSingleMedia
return fmt.Sprintf("InputSingleMedia%+v", Alias(*i))
}
// FillFrom fills InputSingleMedia from given interface.
func (i *InputSingleMedia) FillFrom(from interface {
GetMedia() (value InputMediaClass)
GetRandomID() (value int64)
GetMessage() (value string)
GetEntities() (value []MessageEntityClass, ok bool)
}) {
i.Media = from.GetMedia()
i.RandomID = from.GetRandomID()
i.Message = from.GetMessage()
if val, ok := from.GetEntities(); ok {
i.Entities = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*InputSingleMedia) TypeID() uint32 {
return InputSingleMediaTypeID
}
// TypeName returns name of type in TL schema.
func (*InputSingleMedia) TypeName() string {
return "inputSingleMedia"
}
// TypeInfo returns info about TL type.
func (i *InputSingleMedia) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "inputSingleMedia",
ID: InputSingleMediaTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Media",
SchemaName: "media",
},
{
Name: "RandomID",
SchemaName: "random_id",
},
{
Name: "Message",
SchemaName: "message",
},
{
Name: "Entities",
SchemaName: "entities",
Null: !i.Flags.Has(0),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (i *InputSingleMedia) SetFlags() {
if !(i.Entities == nil) {
i.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (i *InputSingleMedia) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputSingleMedia#1cc6e91f as nil")
}
b.PutID(InputSingleMediaTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *InputSingleMedia) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputSingleMedia#1cc6e91f as nil")
}
i.SetFlags()
if err := i.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field flags: %w", err)
}
if i.Media == nil {
return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field media is nil")
}
if err := i.Media.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field media: %w", err)
}
b.PutLong(i.RandomID)
b.PutString(i.Message)
if i.Flags.Has(0) {
b.PutVectorHeader(len(i.Entities))
for idx, v := range i.Entities {
if v == nil {
return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field entities element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field entities element with index %d: %w", idx, err)
}
}
}
return nil
}
// Decode implements bin.Decoder.
func (i *InputSingleMedia) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputSingleMedia#1cc6e91f to nil")
}
if err := b.ConsumeID(InputSingleMediaTypeID); err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *InputSingleMedia) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputSingleMedia#1cc6e91f to nil")
}
{
if err := i.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field flags: %w", err)
}
}
{
value, err := DecodeInputMedia(b)
if err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field media: %w", err)
}
i.Media = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field random_id: %w", err)
}
i.RandomID = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field message: %w", err)
}
i.Message = value
}
if i.Flags.Has(0) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field entities: %w", err)
}
if headerLen > 0 {
i.Entities = make([]MessageEntityClass, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeMessageEntity(b)
if err != nil {
return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field entities: %w", err)
}
i.Entities = append(i.Entities, value)
}
}
return nil
}
// GetMedia returns value of Media field.
func (i *InputSingleMedia) GetMedia() (value InputMediaClass) {
if i == nil {
return
}
return i.Media
}
// GetRandomID returns value of RandomID field.
func (i *InputSingleMedia) GetRandomID() (value int64) {
if i == nil {
return
}
return i.RandomID
}
// GetMessage returns value of Message field.
func (i *InputSingleMedia) GetMessage() (value string) {
if i == nil {
return
}
return i.Message
}
// SetEntities sets value of Entities conditional field.
func (i *InputSingleMedia) SetEntities(value []MessageEntityClass) {
i.Flags.Set(0)
i.Entities = value
}
// GetEntities returns value of Entities conditional field and
// boolean which is true if field was set.
func (i *InputSingleMedia) GetEntities() (value []MessageEntityClass, ok bool) {
if i == nil {
return
}
if !i.Flags.Has(0) {
return value, false
}
return i.Entities, true
}
// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func (i *InputSingleMedia) MapEntities() (value MessageEntityClassArray, ok bool) {
if !i.Flags.Has(0) {
return value, false
}
return MessageEntityClassArray(i.Entities), true
}