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 WebDocument struct {
URL string
AccessHash int64
Size int
MimeType string
Attributes []DocumentAttributeClass
}
const WebDocumentTypeID = 0x1c570ed1
func (w WebDocument ) construct () WebDocumentClass { return &w }
var (
_ bin .Encoder = &WebDocument {}
_ bin .Decoder = &WebDocument {}
_ bin .BareEncoder = &WebDocument {}
_ bin .BareDecoder = &WebDocument {}
_ WebDocumentClass = &WebDocument {}
)
func (w *WebDocument ) Zero () bool {
if w == nil {
return true
}
if !(w .URL == "" ) {
return false
}
if !(w .AccessHash == 0 ) {
return false
}
if !(w .Size == 0 ) {
return false
}
if !(w .MimeType == "" ) {
return false
}
if !(w .Attributes == nil ) {
return false
}
return true
}
func (w *WebDocument ) String () string {
if w == nil {
return "WebDocument(nil)"
}
type Alias WebDocument
return fmt .Sprintf ("WebDocument%+v" , Alias (*w ))
}
func (w *WebDocument ) FillFrom (from interface {
GetURL () (value string )
GetAccessHash () (value int64 )
GetSize () (value int )
GetMimeType () (value string )
GetAttributes () (value []DocumentAttributeClass )
}) {
w .URL = from .GetURL ()
w .AccessHash = from .GetAccessHash ()
w .Size = from .GetSize ()
w .MimeType = from .GetMimeType ()
w .Attributes = from .GetAttributes ()
}
func (*WebDocument ) TypeID () uint32 {
return WebDocumentTypeID
}
func (*WebDocument ) TypeName () string {
return "webDocument"
}
func (w *WebDocument ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "webDocument" ,
ID : WebDocumentTypeID ,
}
if w == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "URL" ,
SchemaName : "url" ,
},
{
Name : "AccessHash" ,
SchemaName : "access_hash" ,
},
{
Name : "Size" ,
SchemaName : "size" ,
},
{
Name : "MimeType" ,
SchemaName : "mime_type" ,
},
{
Name : "Attributes" ,
SchemaName : "attributes" ,
},
}
return typ
}
func (w *WebDocument ) Encode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode webDocument#1c570ed1 as nil" )
}
b .PutID (WebDocumentTypeID )
return w .EncodeBare (b )
}
func (w *WebDocument ) EncodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode webDocument#1c570ed1 as nil" )
}
b .PutString (w .URL )
b .PutLong (w .AccessHash )
b .PutInt (w .Size )
b .PutString (w .MimeType )
b .PutVectorHeader (len (w .Attributes ))
for idx , v := range w .Attributes {
if v == nil {
return fmt .Errorf ("unable to encode webDocument#1c570ed1: field attributes element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode webDocument#1c570ed1: field attributes element with index %d: %w" , idx , err )
}
}
return nil
}
func (w *WebDocument ) Decode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode webDocument#1c570ed1 to nil" )
}
if err := b .ConsumeID (WebDocumentTypeID ); err != nil {
return fmt .Errorf ("unable to decode webDocument#1c570ed1: %w" , err )
}
return w .DecodeBare (b )
}
func (w *WebDocument ) DecodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode webDocument#1c570ed1 to nil" )
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode webDocument#1c570ed1: field url: %w" , err )
}
w .URL = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode webDocument#1c570ed1: field access_hash: %w" , err )
}
w .AccessHash = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode webDocument#1c570ed1: field size: %w" , err )
}
w .Size = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode webDocument#1c570ed1: field mime_type: %w" , err )
}
w .MimeType = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode webDocument#1c570ed1: field attributes: %w" , err )
}
if headerLen > 0 {
w .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 webDocument#1c570ed1: field attributes: %w" , err )
}
w .Attributes = append (w .Attributes , value )
}
}
return nil
}
func (w *WebDocument ) GetURL () (value string ) {
if w == nil {
return
}
return w .URL
}
func (w *WebDocument ) GetAccessHash () (value int64 ) {
if w == nil {
return
}
return w .AccessHash
}
func (w *WebDocument ) GetSize () (value int ) {
if w == nil {
return
}
return w .Size
}
func (w *WebDocument ) GetMimeType () (value string ) {
if w == nil {
return
}
return w .MimeType
}
func (w *WebDocument ) GetAttributes () (value []DocumentAttributeClass ) {
if w == nil {
return
}
return w .Attributes
}
func (w *WebDocument ) MapAttributes () (value DocumentAttributeClassArray ) {
return DocumentAttributeClassArray (w .Attributes )
}
type WebDocumentNoProxy struct {
URL string
Size int
MimeType string
Attributes []DocumentAttributeClass
}
const WebDocumentNoProxyTypeID = 0xf9c8bcc6
func (w WebDocumentNoProxy ) construct () WebDocumentClass { return &w }
var (
_ bin .Encoder = &WebDocumentNoProxy {}
_ bin .Decoder = &WebDocumentNoProxy {}
_ bin .BareEncoder = &WebDocumentNoProxy {}
_ bin .BareDecoder = &WebDocumentNoProxy {}
_ WebDocumentClass = &WebDocumentNoProxy {}
)
func (w *WebDocumentNoProxy ) Zero () bool {
if w == nil {
return true
}
if !(w .URL == "" ) {
return false
}
if !(w .Size == 0 ) {
return false
}
if !(w .MimeType == "" ) {
return false
}
if !(w .Attributes == nil ) {
return false
}
return true
}
func (w *WebDocumentNoProxy ) String () string {
if w == nil {
return "WebDocumentNoProxy(nil)"
}
type Alias WebDocumentNoProxy
return fmt .Sprintf ("WebDocumentNoProxy%+v" , Alias (*w ))
}
func (w *WebDocumentNoProxy ) FillFrom (from interface {
GetURL () (value string )
GetSize () (value int )
GetMimeType () (value string )
GetAttributes () (value []DocumentAttributeClass )
}) {
w .URL = from .GetURL ()
w .Size = from .GetSize ()
w .MimeType = from .GetMimeType ()
w .Attributes = from .GetAttributes ()
}
func (*WebDocumentNoProxy ) TypeID () uint32 {
return WebDocumentNoProxyTypeID
}
func (*WebDocumentNoProxy ) TypeName () string {
return "webDocumentNoProxy"
}
func (w *WebDocumentNoProxy ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "webDocumentNoProxy" ,
ID : WebDocumentNoProxyTypeID ,
}
if w == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "URL" ,
SchemaName : "url" ,
},
{
Name : "Size" ,
SchemaName : "size" ,
},
{
Name : "MimeType" ,
SchemaName : "mime_type" ,
},
{
Name : "Attributes" ,
SchemaName : "attributes" ,
},
}
return typ
}
func (w *WebDocumentNoProxy ) Encode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode webDocumentNoProxy#f9c8bcc6 as nil" )
}
b .PutID (WebDocumentNoProxyTypeID )
return w .EncodeBare (b )
}
func (w *WebDocumentNoProxy ) EncodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode webDocumentNoProxy#f9c8bcc6 as nil" )
}
b .PutString (w .URL )
b .PutInt (w .Size )
b .PutString (w .MimeType )
b .PutVectorHeader (len (w .Attributes ))
for idx , v := range w .Attributes {
if v == nil {
return fmt .Errorf ("unable to encode webDocumentNoProxy#f9c8bcc6: field attributes element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode webDocumentNoProxy#f9c8bcc6: field attributes element with index %d: %w" , idx , err )
}
}
return nil
}
func (w *WebDocumentNoProxy ) Decode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode webDocumentNoProxy#f9c8bcc6 to nil" )
}
if err := b .ConsumeID (WebDocumentNoProxyTypeID ); err != nil {
return fmt .Errorf ("unable to decode webDocumentNoProxy#f9c8bcc6: %w" , err )
}
return w .DecodeBare (b )
}
func (w *WebDocumentNoProxy ) DecodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode webDocumentNoProxy#f9c8bcc6 to nil" )
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode webDocumentNoProxy#f9c8bcc6: field url: %w" , err )
}
w .URL = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode webDocumentNoProxy#f9c8bcc6: field size: %w" , err )
}
w .Size = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode webDocumentNoProxy#f9c8bcc6: field mime_type: %w" , err )
}
w .MimeType = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode webDocumentNoProxy#f9c8bcc6: field attributes: %w" , err )
}
if headerLen > 0 {
w .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 webDocumentNoProxy#f9c8bcc6: field attributes: %w" , err )
}
w .Attributes = append (w .Attributes , value )
}
}
return nil
}
func (w *WebDocumentNoProxy ) GetURL () (value string ) {
if w == nil {
return
}
return w .URL
}
func (w *WebDocumentNoProxy ) GetSize () (value int ) {
if w == nil {
return
}
return w .Size
}
func (w *WebDocumentNoProxy ) GetMimeType () (value string ) {
if w == nil {
return
}
return w .MimeType
}
func (w *WebDocumentNoProxy ) GetAttributes () (value []DocumentAttributeClass ) {
if w == nil {
return
}
return w .Attributes
}
func (w *WebDocumentNoProxy ) MapAttributes () (value DocumentAttributeClassArray ) {
return DocumentAttributeClassArray (w .Attributes )
}
const WebDocumentClassName = "WebDocument"
type WebDocumentClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () WebDocumentClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
GetURL () (value string )
GetSize () (value int )
GetMimeType () (value string )
GetAttributes () (value []DocumentAttributeClass )
MapAttributes () (value DocumentAttributeClassArray )
}
func (w *WebDocument ) AsInput () *InputWebDocument {
value := new (InputWebDocument )
value .URL = w .GetURL ()
value .Size = w .GetSize ()
value .MimeType = w .GetMimeType ()
value .Attributes = w .GetAttributes ()
return value
}
func DecodeWebDocument (buf *bin .Buffer ) (WebDocumentClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case WebDocumentTypeID :
v := WebDocument {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode WebDocumentClass: %w" , err )
}
return &v , nil
case WebDocumentNoProxyTypeID :
v := WebDocumentNoProxy {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode WebDocumentClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode WebDocumentClass: %w" , bin .NewUnexpectedID (id ))
}
}
type WebDocumentBox struct {
WebDocument WebDocumentClass
}
func (b *WebDocumentBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode WebDocumentBox to nil" )
}
v , err := DecodeWebDocument (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .WebDocument = v
return nil
}
func (b *WebDocumentBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .WebDocument == nil {
return fmt .Errorf ("unable to encode WebDocumentClass as nil" )
}
return b .WebDocument .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 .