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 PageButton struct {
Flags bin .Fields
Text RichTextClass
Type InlineButtonTypeClass
Style RichButtonStyle
}
const PageButtonTypeID = 0x692a5488
var (
_ bin .Encoder = &PageButton {}
_ bin .Decoder = &PageButton {}
_ bin .BareEncoder = &PageButton {}
_ bin .BareDecoder = &PageButton {}
)
func (p *PageButton ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .Text == nil ) {
return false
}
if !(p .Type == nil ) {
return false
}
if !(p .Style .Zero ()) {
return false
}
return true
}
func (p *PageButton ) String () string {
if p == nil {
return "PageButton(nil)"
}
type Alias PageButton
return fmt .Sprintf ("PageButton%+v" , Alias (*p ))
}
func (p *PageButton ) FillFrom (from interface {
GetText () (value RichTextClass )
GetType () (value InlineButtonTypeClass )
GetStyle () (value RichButtonStyle , ok bool )
}) {
p .Text = from .GetText ()
p .Type = from .GetType ()
if val , ok := from .GetStyle (); ok {
p .Style = val
}
}
func (*PageButton ) TypeID () uint32 {
return PageButtonTypeID
}
func (*PageButton ) TypeName () string {
return "pageButton"
}
func (p *PageButton ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "pageButton" ,
ID : PageButtonTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Text" ,
SchemaName : "text" ,
},
{
Name : "Type" ,
SchemaName : "type" ,
},
{
Name : "Style" ,
SchemaName : "style" ,
Null : !p .Flags .Has (0 ),
},
}
return typ
}
func (p *PageButton ) SetFlags () {
if !(p .Style .Zero ()) {
p .Flags .Set (0 )
}
}
func (p *PageButton ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode pageButton#692a5488 as nil" )
}
b .PutID (PageButtonTypeID )
return p .EncodeBare (b )
}
func (p *PageButton ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode pageButton#692a5488 as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pageButton#692a5488: field flags: %w" , err )
}
if p .Text == nil {
return fmt .Errorf ("unable to encode pageButton#692a5488: field text is nil" )
}
if err := p .Text .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pageButton#692a5488: field text: %w" , err )
}
if p .Type == nil {
return fmt .Errorf ("unable to encode pageButton#692a5488: field type is nil" )
}
if err := p .Type .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pageButton#692a5488: field type: %w" , err )
}
if p .Flags .Has (0 ) {
if err := p .Style .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pageButton#692a5488: field style: %w" , err )
}
}
return nil
}
func (p *PageButton ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode pageButton#692a5488 to nil" )
}
if err := b .ConsumeID (PageButtonTypeID ); err != nil {
return fmt .Errorf ("unable to decode pageButton#692a5488: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PageButton ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode pageButton#692a5488 to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode pageButton#692a5488: field flags: %w" , err )
}
}
{
value , err := DecodeRichText (b )
if err != nil {
return fmt .Errorf ("unable to decode pageButton#692a5488: field text: %w" , err )
}
p .Text = value
}
{
value , err := DecodeInlineButtonType (b )
if err != nil {
return fmt .Errorf ("unable to decode pageButton#692a5488: field type: %w" , err )
}
p .Type = value
}
if p .Flags .Has (0 ) {
if err := p .Style .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode pageButton#692a5488: field style: %w" , err )
}
}
return nil
}
func (p *PageButton ) GetText () (value RichTextClass ) {
if p == nil {
return
}
return p .Text
}
func (p *PageButton ) GetType () (value InlineButtonTypeClass ) {
if p == nil {
return
}
return p .Type
}
func (p *PageButton ) SetStyle (value RichButtonStyle ) {
p .Flags .Set (0 )
p .Style = value
}
func (p *PageButton ) GetStyle () (value RichButtonStyle , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (0 ) {
return value , false
}
return p .Style , true
}
The pages are generated with Golds v0.8.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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds .