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"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type UploadFile struct {
Type StorageFileTypeClass
Mtime int
Bytes []byte
}
const UploadFileTypeID = 0x96a18d5
func (f UploadFile ) construct () UploadFileClass { return &f }
var (
_ bin .Encoder = &UploadFile {}
_ bin .Decoder = &UploadFile {}
_ bin .BareEncoder = &UploadFile {}
_ bin .BareDecoder = &UploadFile {}
_ UploadFileClass = &UploadFile {}
)
func (f *UploadFile ) Zero () bool {
if f == nil {
return true
}
if !(f .Type == nil ) {
return false
}
if !(f .Mtime == 0 ) {
return false
}
if !(f .Bytes == nil ) {
return false
}
return true
}
func (f *UploadFile ) String () string {
if f == nil {
return "UploadFile(nil)"
}
type Alias UploadFile
return fmt .Sprintf ("UploadFile%+v" , Alias (*f ))
}
func (f *UploadFile ) FillFrom (from interface {
GetType () (value StorageFileTypeClass )
GetMtime () (value int )
GetBytes () (value []byte )
}) {
f .Type = from .GetType ()
f .Mtime = from .GetMtime ()
f .Bytes = from .GetBytes ()
}
func (*UploadFile ) TypeID () uint32 {
return UploadFileTypeID
}
func (*UploadFile ) TypeName () string {
return "upload.file"
}
func (f *UploadFile ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "upload.file" ,
ID : UploadFileTypeID ,
}
if f == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Type" ,
SchemaName : "type" ,
},
{
Name : "Mtime" ,
SchemaName : "mtime" ,
},
{
Name : "Bytes" ,
SchemaName : "bytes" ,
},
}
return typ
}
func (f *UploadFile ) Encode (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't encode upload.file#96a18d5 as nil" )
}
b .PutID (UploadFileTypeID )
return f .EncodeBare (b )
}
func (f *UploadFile ) EncodeBare (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't encode upload.file#96a18d5 as nil" )
}
if f .Type == nil {
return fmt .Errorf ("unable to encode upload.file#96a18d5: field type is nil" )
}
if err := f .Type .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode upload.file#96a18d5: field type: %w" , err )
}
b .PutInt (f .Mtime )
b .PutBytes (f .Bytes )
return nil
}
func (f *UploadFile ) Decode (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't decode upload.file#96a18d5 to nil" )
}
if err := b .ConsumeID (UploadFileTypeID ); err != nil {
return fmt .Errorf ("unable to decode upload.file#96a18d5: %w" , err )
}
return f .DecodeBare (b )
}
func (f *UploadFile ) DecodeBare (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't decode upload.file#96a18d5 to nil" )
}
{
value , err := DecodeStorageFileType (b )
if err != nil {
return fmt .Errorf ("unable to decode upload.file#96a18d5: field type: %w" , err )
}
f .Type = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode upload.file#96a18d5: field mtime: %w" , err )
}
f .Mtime = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode upload.file#96a18d5: field bytes: %w" , err )
}
f .Bytes = value
}
return nil
}
func (f *UploadFile ) GetType () (value StorageFileTypeClass ) {
if f == nil {
return
}
return f .Type
}
func (f *UploadFile ) GetMtime () (value int ) {
if f == nil {
return
}
return f .Mtime
}
func (f *UploadFile ) GetBytes () (value []byte ) {
if f == nil {
return
}
return f .Bytes
}
type UploadFileCDNRedirect struct {
DCID int
FileToken []byte
EncryptionKey []byte
EncryptionIv []byte
FileHashes []FileHash
}
const UploadFileCDNRedirectTypeID = 0xf18cda44
func (f UploadFileCDNRedirect ) construct () UploadFileClass { return &f }
var (
_ bin .Encoder = &UploadFileCDNRedirect {}
_ bin .Decoder = &UploadFileCDNRedirect {}
_ bin .BareEncoder = &UploadFileCDNRedirect {}
_ bin .BareDecoder = &UploadFileCDNRedirect {}
_ UploadFileClass = &UploadFileCDNRedirect {}
)
func (f *UploadFileCDNRedirect ) Zero () bool {
if f == nil {
return true
}
if !(f .DCID == 0 ) {
return false
}
if !(f .FileToken == nil ) {
return false
}
if !(f .EncryptionKey == nil ) {
return false
}
if !(f .EncryptionIv == nil ) {
return false
}
if !(f .FileHashes == nil ) {
return false
}
return true
}
func (f *UploadFileCDNRedirect ) String () string {
if f == nil {
return "UploadFileCDNRedirect(nil)"
}
type Alias UploadFileCDNRedirect
return fmt .Sprintf ("UploadFileCDNRedirect%+v" , Alias (*f ))
}
func (f *UploadFileCDNRedirect ) FillFrom (from interface {
GetDCID () (value int )
GetFileToken () (value []byte )
GetEncryptionKey () (value []byte )
GetEncryptionIv () (value []byte )
GetFileHashes () (value []FileHash )
}) {
f .DCID = from .GetDCID ()
f .FileToken = from .GetFileToken ()
f .EncryptionKey = from .GetEncryptionKey ()
f .EncryptionIv = from .GetEncryptionIv ()
f .FileHashes = from .GetFileHashes ()
}
func (*UploadFileCDNRedirect ) TypeID () uint32 {
return UploadFileCDNRedirectTypeID
}
func (*UploadFileCDNRedirect ) TypeName () string {
return "upload.fileCdnRedirect"
}
func (f *UploadFileCDNRedirect ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "upload.fileCdnRedirect" ,
ID : UploadFileCDNRedirectTypeID ,
}
if f == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "DCID" ,
SchemaName : "dc_id" ,
},
{
Name : "FileToken" ,
SchemaName : "file_token" ,
},
{
Name : "EncryptionKey" ,
SchemaName : "encryption_key" ,
},
{
Name : "EncryptionIv" ,
SchemaName : "encryption_iv" ,
},
{
Name : "FileHashes" ,
SchemaName : "file_hashes" ,
},
}
return typ
}
func (f *UploadFileCDNRedirect ) Encode (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't encode upload.fileCdnRedirect#f18cda44 as nil" )
}
b .PutID (UploadFileCDNRedirectTypeID )
return f .EncodeBare (b )
}
func (f *UploadFileCDNRedirect ) EncodeBare (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't encode upload.fileCdnRedirect#f18cda44 as nil" )
}
b .PutInt (f .DCID )
b .PutBytes (f .FileToken )
b .PutBytes (f .EncryptionKey )
b .PutBytes (f .EncryptionIv )
b .PutVectorHeader (len (f .FileHashes ))
for idx , v := range f .FileHashes {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode upload.fileCdnRedirect#f18cda44: field file_hashes element with index %d: %w" , idx , err )
}
}
return nil
}
func (f *UploadFileCDNRedirect ) Decode (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't decode upload.fileCdnRedirect#f18cda44 to nil" )
}
if err := b .ConsumeID (UploadFileCDNRedirectTypeID ); err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: %w" , err )
}
return f .DecodeBare (b )
}
func (f *UploadFileCDNRedirect ) DecodeBare (b *bin .Buffer ) error {
if f == nil {
return fmt .Errorf ("can't decode upload.fileCdnRedirect#f18cda44 to nil" )
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: field dc_id: %w" , err )
}
f .DCID = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: field file_token: %w" , err )
}
f .FileToken = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: field encryption_key: %w" , err )
}
f .EncryptionKey = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: field encryption_iv: %w" , err )
}
f .EncryptionIv = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: field file_hashes: %w" , err )
}
if headerLen > 0 {
f .FileHashes = make ([]FileHash , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value FileHash
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode upload.fileCdnRedirect#f18cda44: field file_hashes: %w" , err )
}
f .FileHashes = append (f .FileHashes , value )
}
}
return nil
}
func (f *UploadFileCDNRedirect ) GetDCID () (value int ) {
if f == nil {
return
}
return f .DCID
}
func (f *UploadFileCDNRedirect ) GetFileToken () (value []byte ) {
if f == nil {
return
}
return f .FileToken
}
func (f *UploadFileCDNRedirect ) GetEncryptionKey () (value []byte ) {
if f == nil {
return
}
return f .EncryptionKey
}
func (f *UploadFileCDNRedirect ) GetEncryptionIv () (value []byte ) {
if f == nil {
return
}
return f .EncryptionIv
}
func (f *UploadFileCDNRedirect ) GetFileHashes () (value []FileHash ) {
if f == nil {
return
}
return f .FileHashes
}
const UploadFileClassName = "upload.File"
type UploadFileClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () UploadFileClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
}
func DecodeUploadFile (buf *bin .Buffer ) (UploadFileClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case UploadFileTypeID :
v := UploadFile {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode UploadFileClass: %w" , err )
}
return &v , nil
case UploadFileCDNRedirectTypeID :
v := UploadFileCDNRedirect {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode UploadFileClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode UploadFileClass: %w" , bin .NewUnexpectedID (id ))
}
}
type UploadFileBox struct {
File UploadFileClass
}
func (b *UploadFileBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode UploadFileBox to nil" )
}
v , err := DecodeUploadFile (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .File = v
return nil
}
func (b *UploadFileBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .File == nil {
return fmt .Errorf ("unable to encode UploadFileClass as nil" )
}
return b .File .Encode (buf )
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .