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 KeyboardButton struct {
Flags bin .Fields
Style KeyboardButtonStyle
Text string
Type ButtonTypeClass
}
const KeyboardButtonTypeID = 0x2f67a72f
var (
_ bin .Encoder = &KeyboardButton {}
_ bin .Decoder = &KeyboardButton {}
_ bin .BareEncoder = &KeyboardButton {}
_ bin .BareDecoder = &KeyboardButton {}
)
func (k *KeyboardButton ) Zero () bool {
if k == nil {
return true
}
if !(k .Flags .Zero ()) {
return false
}
if !(k .Style .Zero ()) {
return false
}
if !(k .Text == "" ) {
return false
}
if !(k .Type == nil ) {
return false
}
return true
}
func (k *KeyboardButton ) String () string {
if k == nil {
return "KeyboardButton(nil)"
}
type Alias KeyboardButton
return fmt .Sprintf ("KeyboardButton%+v" , Alias (*k ))
}
func (k *KeyboardButton ) FillFrom (from interface {
GetStyle () (value KeyboardButtonStyle , ok bool )
GetText () (value string )
GetType () (value ButtonTypeClass )
}) {
if val , ok := from .GetStyle (); ok {
k .Style = val
}
k .Text = from .GetText ()
k .Type = from .GetType ()
}
func (*KeyboardButton ) TypeID () uint32 {
return KeyboardButtonTypeID
}
func (*KeyboardButton ) TypeName () string {
return "keyboardButton"
}
func (k *KeyboardButton ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "keyboardButton" ,
ID : KeyboardButtonTypeID ,
}
if k == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Style" ,
SchemaName : "style" ,
Null : !k .Flags .Has (10 ),
},
{
Name : "Text" ,
SchemaName : "text" ,
},
{
Name : "Type" ,
SchemaName : "type" ,
},
}
return typ
}
func (k *KeyboardButton ) SetFlags () {
if !(k .Style .Zero ()) {
k .Flags .Set (10 )
}
}
func (k *KeyboardButton ) Encode (b *bin .Buffer ) error {
if k == nil {
return fmt .Errorf ("can't encode keyboardButton#2f67a72f as nil" )
}
b .PutID (KeyboardButtonTypeID )
return k .EncodeBare (b )
}
func (k *KeyboardButton ) EncodeBare (b *bin .Buffer ) error {
if k == nil {
return fmt .Errorf ("can't encode keyboardButton#2f67a72f as nil" )
}
k .SetFlags ()
if err := k .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode keyboardButton#2f67a72f: field flags: %w" , err )
}
if k .Flags .Has (10 ) {
if err := k .Style .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode keyboardButton#2f67a72f: field style: %w" , err )
}
}
b .PutString (k .Text )
if k .Type == nil {
return fmt .Errorf ("unable to encode keyboardButton#2f67a72f: field type is nil" )
}
if err := k .Type .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode keyboardButton#2f67a72f: field type: %w" , err )
}
return nil
}
func (k *KeyboardButton ) Decode (b *bin .Buffer ) error {
if k == nil {
return fmt .Errorf ("can't decode keyboardButton#2f67a72f to nil" )
}
if err := b .ConsumeID (KeyboardButtonTypeID ); err != nil {
return fmt .Errorf ("unable to decode keyboardButton#2f67a72f: %w" , err )
}
return k .DecodeBare (b )
}
func (k *KeyboardButton ) DecodeBare (b *bin .Buffer ) error {
if k == nil {
return fmt .Errorf ("can't decode keyboardButton#2f67a72f to nil" )
}
{
if err := k .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode keyboardButton#2f67a72f: field flags: %w" , err )
}
}
if k .Flags .Has (10 ) {
if err := k .Style .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode keyboardButton#2f67a72f: field style: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode keyboardButton#2f67a72f: field text: %w" , err )
}
k .Text = value
}
{
value , err := DecodeButtonType (b )
if err != nil {
return fmt .Errorf ("unable to decode keyboardButton#2f67a72f: field type: %w" , err )
}
k .Type = value
}
return nil
}
func (k *KeyboardButton ) SetStyle (value KeyboardButtonStyle ) {
k .Flags .Set (10 )
k .Style = value
}
func (k *KeyboardButton ) GetStyle () (value KeyboardButtonStyle , ok bool ) {
if k == nil {
return
}
if !k .Flags .Has (10 ) {
return value , false
}
return k .Style , true
}
func (k *KeyboardButton ) GetText () (value string ) {
if k == nil {
return
}
return k .Text
}
func (k *KeyboardButton ) GetType () (value ButtonTypeClass ) {
if k == nil {
return
}
return k .Type
}
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 .