-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
tl_messages_get_document_by_hash_gen.go
234 lines (210 loc) · 5.74 KB
/
tl_messages_get_document_by_hash_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
// 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{}
)
// MessagesGetDocumentByHashRequest represents TL type `messages.getDocumentByHash#b1f2061f`.
// Get a document by its SHA256 hash, mainly used for gifs
//
// See https://core.telegram.org/method/messages.getDocumentByHash for reference.
type MessagesGetDocumentByHashRequest struct {
// SHA256 of file
SHA256 []byte
// Size of the file in bytes
Size int64
// Mime type
MimeType string
}
// MessagesGetDocumentByHashRequestTypeID is TL type id of MessagesGetDocumentByHashRequest.
const MessagesGetDocumentByHashRequestTypeID = 0xb1f2061f
// Ensuring interfaces in compile-time for MessagesGetDocumentByHashRequest.
var (
_ bin.Encoder = &MessagesGetDocumentByHashRequest{}
_ bin.Decoder = &MessagesGetDocumentByHashRequest{}
_ bin.BareEncoder = &MessagesGetDocumentByHashRequest{}
_ bin.BareDecoder = &MessagesGetDocumentByHashRequest{}
)
func (g *MessagesGetDocumentByHashRequest) Zero() bool {
if g == nil {
return true
}
if !(g.SHA256 == nil) {
return false
}
if !(g.Size == 0) {
return false
}
if !(g.MimeType == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (g *MessagesGetDocumentByHashRequest) String() string {
if g == nil {
return "MessagesGetDocumentByHashRequest(nil)"
}
type Alias MessagesGetDocumentByHashRequest
return fmt.Sprintf("MessagesGetDocumentByHashRequest%+v", Alias(*g))
}
// FillFrom fills MessagesGetDocumentByHashRequest from given interface.
func (g *MessagesGetDocumentByHashRequest) FillFrom(from interface {
GetSHA256() (value []byte)
GetSize() (value int64)
GetMimeType() (value string)
}) {
g.SHA256 = from.GetSHA256()
g.Size = from.GetSize()
g.MimeType = from.GetMimeType()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessagesGetDocumentByHashRequest) TypeID() uint32 {
return MessagesGetDocumentByHashRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*MessagesGetDocumentByHashRequest) TypeName() string {
return "messages.getDocumentByHash"
}
// TypeInfo returns info about TL type.
func (g *MessagesGetDocumentByHashRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "messages.getDocumentByHash",
ID: MessagesGetDocumentByHashRequestTypeID,
}
if g == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "SHA256",
SchemaName: "sha256",
},
{
Name: "Size",
SchemaName: "size",
},
{
Name: "MimeType",
SchemaName: "mime_type",
},
}
return typ
}
// Encode implements bin.Encoder.
func (g *MessagesGetDocumentByHashRequest) Encode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode messages.getDocumentByHash#b1f2061f as nil")
}
b.PutID(MessagesGetDocumentByHashRequestTypeID)
return g.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (g *MessagesGetDocumentByHashRequest) EncodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode messages.getDocumentByHash#b1f2061f as nil")
}
b.PutBytes(g.SHA256)
b.PutLong(g.Size)
b.PutString(g.MimeType)
return nil
}
// Decode implements bin.Decoder.
func (g *MessagesGetDocumentByHashRequest) Decode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode messages.getDocumentByHash#b1f2061f to nil")
}
if err := b.ConsumeID(MessagesGetDocumentByHashRequestTypeID); err != nil {
return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: %w", err)
}
return g.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (g *MessagesGetDocumentByHashRequest) DecodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode messages.getDocumentByHash#b1f2061f to nil")
}
{
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: field sha256: %w", err)
}
g.SHA256 = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: field size: %w", err)
}
g.Size = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: field mime_type: %w", err)
}
g.MimeType = value
}
return nil
}
// GetSHA256 returns value of SHA256 field.
func (g *MessagesGetDocumentByHashRequest) GetSHA256() (value []byte) {
if g == nil {
return
}
return g.SHA256
}
// GetSize returns value of Size field.
func (g *MessagesGetDocumentByHashRequest) GetSize() (value int64) {
if g == nil {
return
}
return g.Size
}
// GetMimeType returns value of MimeType field.
func (g *MessagesGetDocumentByHashRequest) GetMimeType() (value string) {
if g == nil {
return
}
return g.MimeType
}
// MessagesGetDocumentByHash invokes method messages.getDocumentByHash#b1f2061f returning error if any.
// Get a document by its SHA256 hash, mainly used for gifs
//
// Possible errors:
//
// 400 SHA256_HASH_INVALID: The provided SHA256 hash is invalid.
//
// See https://core.telegram.org/method/messages.getDocumentByHash for reference.
// Can be used by bots.
func (c *Client) MessagesGetDocumentByHash(ctx context.Context, request *MessagesGetDocumentByHashRequest) (DocumentClass, error) {
var result DocumentBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return nil, err
}
return result.Document, nil
}