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 DocumentEmpty struct {
ID int64
}
const DocumentEmptyTypeID = 0x36f8c871
func (d DocumentEmpty ) construct () DocumentClass { return &d }
var (
_ bin .Encoder = &DocumentEmpty {}
_ bin .Decoder = &DocumentEmpty {}
_ bin .BareEncoder = &DocumentEmpty {}
_ bin .BareDecoder = &DocumentEmpty {}
_ DocumentClass = &DocumentEmpty {}
)
func (d *DocumentEmpty ) Zero () bool {
if d == nil {
return true
}
if !(d .ID == 0 ) {
return false
}
return true
}
func (d *DocumentEmpty ) String () string {
if d == nil {
return "DocumentEmpty(nil)"
}
type Alias DocumentEmpty
return fmt .Sprintf ("DocumentEmpty%+v" , Alias (*d ))
}
func (d *DocumentEmpty ) FillFrom (from interface {
GetID () (value int64 )
}) {
d .ID = from .GetID ()
}
func (*DocumentEmpty ) TypeID () uint32 {
return DocumentEmptyTypeID
}
func (*DocumentEmpty ) TypeName () string {
return "documentEmpty"
}
func (d *DocumentEmpty ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "documentEmpty" ,
ID : DocumentEmptyTypeID ,
}
if d == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "ID" ,
SchemaName : "id" ,
},
}
return typ
}
func (d *DocumentEmpty ) Encode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode documentEmpty#36f8c871 as nil" )
}
b .PutID (DocumentEmptyTypeID )
return d .EncodeBare (b )
}
func (d *DocumentEmpty ) EncodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode documentEmpty#36f8c871 as nil" )
}
b .PutLong (d .ID )
return nil
}
func (d *DocumentEmpty ) Decode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode documentEmpty#36f8c871 to nil" )
}
if err := b .ConsumeID (DocumentEmptyTypeID ); err != nil {
return fmt .Errorf ("unable to decode documentEmpty#36f8c871: %w" , err )
}
return d .DecodeBare (b )
}
func (d *DocumentEmpty ) DecodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode documentEmpty#36f8c871 to nil" )
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode documentEmpty#36f8c871: field id: %w" , err )
}
d .ID = value
}
return nil
}
func (d *DocumentEmpty ) GetID () (value int64 ) {
if d == nil {
return
}
return d .ID
}
type Document struct {
Flags bin .Fields
ID int64
AccessHash int64
FileReference []byte
Date int
MimeType string
Size int64
Thumbs []PhotoSizeClass
VideoThumbs []VideoSizeClass
DCID int
Attributes []DocumentAttributeClass
}
const DocumentTypeID = 0x8fd4c4d8
func (d Document ) construct () DocumentClass { return &d }
var (
_ bin .Encoder = &Document {}
_ bin .Decoder = &Document {}
_ bin .BareEncoder = &Document {}
_ bin .BareDecoder = &Document {}
_ DocumentClass = &Document {}
)
func (d *Document ) Zero () bool {
if d == nil {
return true
}
if !(d .Flags .Zero ()) {
return false
}
if !(d .ID == 0 ) {
return false
}
if !(d .AccessHash == 0 ) {
return false
}
if !(d .FileReference == nil ) {
return false
}
if !(d .Date == 0 ) {
return false
}
if !(d .MimeType == "" ) {
return false
}
if !(d .Size == 0 ) {
return false
}
if !(d .Thumbs == nil ) {
return false
}
if !(d .VideoThumbs == nil ) {
return false
}
if !(d .DCID == 0 ) {
return false
}
if !(d .Attributes == nil ) {
return false
}
return true
}
func (d *Document ) String () string {
if d == nil {
return "Document(nil)"
}
type Alias Document
return fmt .Sprintf ("Document%+v" , Alias (*d ))
}
func (d *Document ) FillFrom (from interface {
GetID () (value int64 )
GetAccessHash () (value int64 )
GetFileReference () (value []byte )
GetDate () (value int )
GetMimeType () (value string )
GetSize () (value int64 )
GetThumbs () (value []PhotoSizeClass , ok bool )
GetVideoThumbs () (value []VideoSizeClass , ok bool )
GetDCID () (value int )
GetAttributes () (value []DocumentAttributeClass )
}) {
d .ID = from .GetID ()
d .AccessHash = from .GetAccessHash ()
d .FileReference = from .GetFileReference ()
d .Date = from .GetDate ()
d .MimeType = from .GetMimeType ()
d .Size = from .GetSize ()
if val , ok := from .GetThumbs (); ok {
d .Thumbs = val
}
if val , ok := from .GetVideoThumbs (); ok {
d .VideoThumbs = val
}
d .DCID = from .GetDCID ()
d .Attributes = from .GetAttributes ()
}
func (*Document ) TypeID () uint32 {
return DocumentTypeID
}
func (*Document ) TypeName () string {
return "document"
}
func (d *Document ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "document" ,
ID : DocumentTypeID ,
}
if d == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "ID" ,
SchemaName : "id" ,
},
{
Name : "AccessHash" ,
SchemaName : "access_hash" ,
},
{
Name : "FileReference" ,
SchemaName : "file_reference" ,
},
{
Name : "Date" ,
SchemaName : "date" ,
},
{
Name : "MimeType" ,
SchemaName : "mime_type" ,
},
{
Name : "Size" ,
SchemaName : "size" ,
},
{
Name : "Thumbs" ,
SchemaName : "thumbs" ,
Null : !d .Flags .Has (0 ),
},
{
Name : "VideoThumbs" ,
SchemaName : "video_thumbs" ,
Null : !d .Flags .Has (1 ),
},
{
Name : "DCID" ,
SchemaName : "dc_id" ,
},
{
Name : "Attributes" ,
SchemaName : "attributes" ,
},
}
return typ
}
func (d *Document ) SetFlags () {
if !(d .Thumbs == nil ) {
d .Flags .Set (0 )
}
if !(d .VideoThumbs == nil ) {
d .Flags .Set (1 )
}
}
func (d *Document ) Encode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode document#8fd4c4d8 as nil" )
}
b .PutID (DocumentTypeID )
return d .EncodeBare (b )
}
func (d *Document ) EncodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode document#8fd4c4d8 as nil" )
}
d .SetFlags ()
if err := d .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field flags: %w" , err )
}
b .PutLong (d .ID )
b .PutLong (d .AccessHash )
b .PutBytes (d .FileReference )
b .PutInt (d .Date )
b .PutString (d .MimeType )
b .PutLong (d .Size )
if d .Flags .Has (0 ) {
b .PutVectorHeader (len (d .Thumbs ))
for idx , v := range d .Thumbs {
if v == nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field thumbs element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field thumbs element with index %d: %w" , idx , err )
}
}
}
if d .Flags .Has (1 ) {
b .PutVectorHeader (len (d .VideoThumbs ))
for idx , v := range d .VideoThumbs {
if v == nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field video_thumbs element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field video_thumbs element with index %d: %w" , idx , err )
}
}
}
b .PutInt (d .DCID )
b .PutVectorHeader (len (d .Attributes ))
for idx , v := range d .Attributes {
if v == nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field attributes element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode document#8fd4c4d8: field attributes element with index %d: %w" , idx , err )
}
}
return nil
}
func (d *Document ) Decode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode document#8fd4c4d8 to nil" )
}
if err := b .ConsumeID (DocumentTypeID ); err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: %w" , err )
}
return d .DecodeBare (b )
}
func (d *Document ) DecodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode document#8fd4c4d8 to nil" )
}
{
if err := d .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field flags: %w" , err )
}
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field id: %w" , err )
}
d .ID = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field access_hash: %w" , err )
}
d .AccessHash = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field file_reference: %w" , err )
}
d .FileReference = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field date: %w" , err )
}
d .Date = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field mime_type: %w" , err )
}
d .MimeType = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field size: %w" , err )
}
d .Size = value
}
if d .Flags .Has (0 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field thumbs: %w" , err )
}
if headerLen > 0 {
d .Thumbs = make ([]PhotoSizeClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodePhotoSize (b )
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field thumbs: %w" , err )
}
d .Thumbs = append (d .Thumbs , value )
}
}
if d .Flags .Has (1 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field video_thumbs: %w" , err )
}
if headerLen > 0 {
d .VideoThumbs = make ([]VideoSizeClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeVideoSize (b )
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field video_thumbs: %w" , err )
}
d .VideoThumbs = append (d .VideoThumbs , value )
}
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field dc_id: %w" , err )
}
d .DCID = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field attributes: %w" , err )
}
if headerLen > 0 {
d .Attributes = make ([]DocumentAttributeClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeDocumentAttribute (b )
if err != nil {
return fmt .Errorf ("unable to decode document#8fd4c4d8: field attributes: %w" , err )
}
d .Attributes = append (d .Attributes , value )
}
}
return nil
}
func (d *Document ) GetID () (value int64 ) {
if d == nil {
return
}
return d .ID
}
func (d *Document ) GetAccessHash () (value int64 ) {
if d == nil {
return
}
return d .AccessHash
}
func (d *Document ) GetFileReference () (value []byte ) {
if d == nil {
return
}
return d .FileReference
}
func (d *Document ) GetDate () (value int ) {
if d == nil {
return
}
return d .Date
}
func (d *Document ) GetMimeType () (value string ) {
if d == nil {
return
}
return d .MimeType
}
func (d *Document ) GetSize () (value int64 ) {
if d == nil {
return
}
return d .Size
}
func (d *Document ) SetThumbs (value []PhotoSizeClass ) {
d .Flags .Set (0 )
d .Thumbs = value
}
func (d *Document ) GetThumbs () (value []PhotoSizeClass , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (0 ) {
return value , false
}
return d .Thumbs , true
}
func (d *Document ) SetVideoThumbs (value []VideoSizeClass ) {
d .Flags .Set (1 )
d .VideoThumbs = value
}
func (d *Document ) GetVideoThumbs () (value []VideoSizeClass , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (1 ) {
return value , false
}
return d .VideoThumbs , true
}
func (d *Document ) GetDCID () (value int ) {
if d == nil {
return
}
return d .DCID
}
func (d *Document ) GetAttributes () (value []DocumentAttributeClass ) {
if d == nil {
return
}
return d .Attributes
}
func (d *Document ) MapThumbs () (value PhotoSizeClassArray , ok bool ) {
if !d .Flags .Has (0 ) {
return value , false
}
return PhotoSizeClassArray (d .Thumbs ), true
}
func (d *Document ) MapVideoThumbs () (value VideoSizeClassArray , ok bool ) {
if !d .Flags .Has (1 ) {
return value , false
}
return VideoSizeClassArray (d .VideoThumbs ), true
}
func (d *Document ) MapAttributes () (value DocumentAttributeClassArray ) {
return DocumentAttributeClassArray (d .Attributes )
}
const DocumentClassName = "Document"
type DocumentClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () DocumentClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
GetID () (value int64 )
AsNotEmpty () (*Document , bool )
}
func (d *Document ) AsInputDocumentFileLocation () *InputDocumentFileLocation {
value := new (InputDocumentFileLocation )
value .ID = d .GetID ()
value .AccessHash = d .GetAccessHash ()
value .FileReference = d .GetFileReference ()
return value
}
func (d *Document ) AsInput () *InputDocument {
value := new (InputDocument )
value .ID = d .GetID ()
value .AccessHash = d .GetAccessHash ()
value .FileReference = d .GetFileReference ()
return value
}
func (d *DocumentEmpty ) AsNotEmpty () (*Document , bool ) {
return nil , false
}
func (d *Document ) AsNotEmpty () (*Document , bool ) {
return d , true
}
func DecodeDocument (buf *bin .Buffer ) (DocumentClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case DocumentEmptyTypeID :
v := DocumentEmpty {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode DocumentClass: %w" , err )
}
return &v , nil
case DocumentTypeID :
v := Document {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode DocumentClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode DocumentClass: %w" , bin .NewUnexpectedID (id ))
}
}
type DocumentBox struct {
Document DocumentClass
}
func (b *DocumentBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode DocumentBox to nil" )
}
v , err := DecodeDocument (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .Document = v
return nil
}
func (b *DocumentBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .Document == nil {
return fmt .Errorf ("unable to encode DocumentClass as nil" )
}
return b .Document .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 .