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 Page struct {
Flags bin .Fields
Part bool
Rtl bool
V2 bool
URL string
Blocks []PageBlockClass
Photos []PhotoClass
Documents []DocumentClass
Views int
}
const PageTypeID = 0x98657f0d
var (
_ bin .Encoder = &Page {}
_ bin .Decoder = &Page {}
_ bin .BareEncoder = &Page {}
_ bin .BareDecoder = &Page {}
)
func (p *Page ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .Part == false ) {
return false
}
if !(p .Rtl == false ) {
return false
}
if !(p .V2 == false ) {
return false
}
if !(p .URL == "" ) {
return false
}
if !(p .Blocks == nil ) {
return false
}
if !(p .Photos == nil ) {
return false
}
if !(p .Documents == nil ) {
return false
}
if !(p .Views == 0 ) {
return false
}
return true
}
func (p *Page ) String () string {
if p == nil {
return "Page(nil)"
}
type Alias Page
return fmt .Sprintf ("Page%+v" , Alias (*p ))
}
func (p *Page ) FillFrom (from interface {
GetPart () (value bool )
GetRtl () (value bool )
GetV2 () (value bool )
GetURL () (value string )
GetBlocks () (value []PageBlockClass )
GetPhotos () (value []PhotoClass )
GetDocuments () (value []DocumentClass )
GetViews () (value int , ok bool )
}) {
p .Part = from .GetPart ()
p .Rtl = from .GetRtl ()
p .V2 = from .GetV2 ()
p .URL = from .GetURL ()
p .Blocks = from .GetBlocks ()
p .Photos = from .GetPhotos ()
p .Documents = from .GetDocuments ()
if val , ok := from .GetViews (); ok {
p .Views = val
}
}
func (*Page ) TypeID () uint32 {
return PageTypeID
}
func (*Page ) TypeName () string {
return "page"
}
func (p *Page ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "page" ,
ID : PageTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Part" ,
SchemaName : "part" ,
Null : !p .Flags .Has (0 ),
},
{
Name : "Rtl" ,
SchemaName : "rtl" ,
Null : !p .Flags .Has (1 ),
},
{
Name : "V2" ,
SchemaName : "v2" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "URL" ,
SchemaName : "url" ,
},
{
Name : "Blocks" ,
SchemaName : "blocks" ,
},
{
Name : "Photos" ,
SchemaName : "photos" ,
},
{
Name : "Documents" ,
SchemaName : "documents" ,
},
{
Name : "Views" ,
SchemaName : "views" ,
Null : !p .Flags .Has (3 ),
},
}
return typ
}
func (p *Page ) SetFlags () {
if !(p .Part == false ) {
p .Flags .Set (0 )
}
if !(p .Rtl == false ) {
p .Flags .Set (1 )
}
if !(p .V2 == false ) {
p .Flags .Set (2 )
}
if !(p .Views == 0 ) {
p .Flags .Set (3 )
}
}
func (p *Page ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode page#98657f0d as nil" )
}
b .PutID (PageTypeID )
return p .EncodeBare (b )
}
func (p *Page ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode page#98657f0d as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode page#98657f0d: field flags: %w" , err )
}
b .PutString (p .URL )
b .PutVectorHeader (len (p .Blocks ))
for idx , v := range p .Blocks {
if v == nil {
return fmt .Errorf ("unable to encode page#98657f0d: field blocks element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode page#98657f0d: field blocks element with index %d: %w" , idx , err )
}
}
b .PutVectorHeader (len (p .Photos ))
for idx , v := range p .Photos {
if v == nil {
return fmt .Errorf ("unable to encode page#98657f0d: field photos element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode page#98657f0d: field photos element with index %d: %w" , idx , err )
}
}
b .PutVectorHeader (len (p .Documents ))
for idx , v := range p .Documents {
if v == nil {
return fmt .Errorf ("unable to encode page#98657f0d: field documents element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode page#98657f0d: field documents element with index %d: %w" , idx , err )
}
}
if p .Flags .Has (3 ) {
b .PutInt (p .Views )
}
return nil
}
func (p *Page ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode page#98657f0d to nil" )
}
if err := b .ConsumeID (PageTypeID ); err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: %w" , err )
}
return p .DecodeBare (b )
}
func (p *Page ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode page#98657f0d to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field flags: %w" , err )
}
}
p .Part = p .Flags .Has (0 )
p .Rtl = p .Flags .Has (1 )
p .V2 = p .Flags .Has (2 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field url: %w" , err )
}
p .URL = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field blocks: %w" , err )
}
if headerLen > 0 {
p .Blocks = make ([]PageBlockClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodePageBlock (b )
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field blocks: %w" , err )
}
p .Blocks = append (p .Blocks , value )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field photos: %w" , err )
}
if headerLen > 0 {
p .Photos = make ([]PhotoClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodePhoto (b )
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field photos: %w" , err )
}
p .Photos = append (p .Photos , value )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field documents: %w" , err )
}
if headerLen > 0 {
p .Documents = make ([]DocumentClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeDocument (b )
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field documents: %w" , err )
}
p .Documents = append (p .Documents , value )
}
}
if p .Flags .Has (3 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode page#98657f0d: field views: %w" , err )
}
p .Views = value
}
return nil
}
func (p *Page ) SetPart (value bool ) {
if value {
p .Flags .Set (0 )
p .Part = true
} else {
p .Flags .Unset (0 )
p .Part = false
}
}
func (p *Page ) GetPart () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (0 )
}
func (p *Page ) SetRtl (value bool ) {
if value {
p .Flags .Set (1 )
p .Rtl = true
} else {
p .Flags .Unset (1 )
p .Rtl = false
}
}
func (p *Page ) GetRtl () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (1 )
}
func (p *Page ) SetV2 (value bool ) {
if value {
p .Flags .Set (2 )
p .V2 = true
} else {
p .Flags .Unset (2 )
p .V2 = false
}
}
func (p *Page ) GetV2 () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (2 )
}
func (p *Page ) GetURL () (value string ) {
if p == nil {
return
}
return p .URL
}
func (p *Page ) GetBlocks () (value []PageBlockClass ) {
if p == nil {
return
}
return p .Blocks
}
func (p *Page ) GetPhotos () (value []PhotoClass ) {
if p == nil {
return
}
return p .Photos
}
func (p *Page ) GetDocuments () (value []DocumentClass ) {
if p == nil {
return
}
return p .Documents
}
func (p *Page ) SetViews (value int ) {
p .Flags .Set (3 )
p .Views = value
}
func (p *Page ) GetViews () (value int , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (3 ) {
return value , false
}
return p .Views , true
}
func (p *Page ) MapBlocks () (value PageBlockClassArray ) {
return PageBlockClassArray (p .Blocks )
}
func (p *Page ) MapPhotos () (value PhotoClassArray ) {
return PhotoClassArray (p .Photos )
}
func (p *Page ) MapDocuments () (value DocumentClassArray ) {
return DocumentClassArray (p .Documents )
}
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 .