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 HelpPromoDataEmpty struct {
Expires int
}
const HelpPromoDataEmptyTypeID = 0x98f6ac75
func (p HelpPromoDataEmpty ) construct () HelpPromoDataClass { return &p }
var (
_ bin .Encoder = &HelpPromoDataEmpty {}
_ bin .Decoder = &HelpPromoDataEmpty {}
_ bin .BareEncoder = &HelpPromoDataEmpty {}
_ bin .BareDecoder = &HelpPromoDataEmpty {}
_ HelpPromoDataClass = &HelpPromoDataEmpty {}
)
func (p *HelpPromoDataEmpty ) Zero () bool {
if p == nil {
return true
}
if !(p .Expires == 0 ) {
return false
}
return true
}
func (p *HelpPromoDataEmpty ) String () string {
if p == nil {
return "HelpPromoDataEmpty(nil)"
}
type Alias HelpPromoDataEmpty
return fmt .Sprintf ("HelpPromoDataEmpty%+v" , Alias (*p ))
}
func (p *HelpPromoDataEmpty ) FillFrom (from interface {
GetExpires () (value int )
}) {
p .Expires = from .GetExpires ()
}
func (*HelpPromoDataEmpty ) TypeID () uint32 {
return HelpPromoDataEmptyTypeID
}
func (*HelpPromoDataEmpty ) TypeName () string {
return "help.promoDataEmpty"
}
func (p *HelpPromoDataEmpty ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "help.promoDataEmpty" ,
ID : HelpPromoDataEmptyTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Expires" ,
SchemaName : "expires" ,
},
}
return typ
}
func (p *HelpPromoDataEmpty ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode help.promoDataEmpty#98f6ac75 as nil" )
}
b .PutID (HelpPromoDataEmptyTypeID )
return p .EncodeBare (b )
}
func (p *HelpPromoDataEmpty ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode help.promoDataEmpty#98f6ac75 as nil" )
}
b .PutInt (p .Expires )
return nil
}
func (p *HelpPromoDataEmpty ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode help.promoDataEmpty#98f6ac75 to nil" )
}
if err := b .ConsumeID (HelpPromoDataEmptyTypeID ); err != nil {
return fmt .Errorf ("unable to decode help.promoDataEmpty#98f6ac75: %w" , err )
}
return p .DecodeBare (b )
}
func (p *HelpPromoDataEmpty ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode help.promoDataEmpty#98f6ac75 to nil" )
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode help.promoDataEmpty#98f6ac75: field expires: %w" , err )
}
p .Expires = value
}
return nil
}
func (p *HelpPromoDataEmpty ) GetExpires () (value int ) {
if p == nil {
return
}
return p .Expires
}
type HelpPromoData struct {
Flags bin .Fields
Proxy bool
Expires int
Peer PeerClass
Chats []ChatClass
Users []UserClass
PsaType string
PsaMessage string
}
const HelpPromoDataTypeID = 0x8c39793f
func (p HelpPromoData ) construct () HelpPromoDataClass { return &p }
var (
_ bin .Encoder = &HelpPromoData {}
_ bin .Decoder = &HelpPromoData {}
_ bin .BareEncoder = &HelpPromoData {}
_ bin .BareDecoder = &HelpPromoData {}
_ HelpPromoDataClass = &HelpPromoData {}
)
func (p *HelpPromoData ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .Proxy == false ) {
return false
}
if !(p .Expires == 0 ) {
return false
}
if !(p .Peer == nil ) {
return false
}
if !(p .Chats == nil ) {
return false
}
if !(p .Users == nil ) {
return false
}
if !(p .PsaType == "" ) {
return false
}
if !(p .PsaMessage == "" ) {
return false
}
return true
}
func (p *HelpPromoData ) String () string {
if p == nil {
return "HelpPromoData(nil)"
}
type Alias HelpPromoData
return fmt .Sprintf ("HelpPromoData%+v" , Alias (*p ))
}
func (p *HelpPromoData ) FillFrom (from interface {
GetProxy () (value bool )
GetExpires () (value int )
GetPeer () (value PeerClass )
GetChats () (value []ChatClass )
GetUsers () (value []UserClass )
GetPsaType () (value string , ok bool )
GetPsaMessage () (value string , ok bool )
}) {
p .Proxy = from .GetProxy ()
p .Expires = from .GetExpires ()
p .Peer = from .GetPeer ()
p .Chats = from .GetChats ()
p .Users = from .GetUsers ()
if val , ok := from .GetPsaType (); ok {
p .PsaType = val
}
if val , ok := from .GetPsaMessage (); ok {
p .PsaMessage = val
}
}
func (*HelpPromoData ) TypeID () uint32 {
return HelpPromoDataTypeID
}
func (*HelpPromoData ) TypeName () string {
return "help.promoData"
}
func (p *HelpPromoData ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "help.promoData" ,
ID : HelpPromoDataTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Proxy" ,
SchemaName : "proxy" ,
Null : !p .Flags .Has (0 ),
},
{
Name : "Expires" ,
SchemaName : "expires" ,
},
{
Name : "Peer" ,
SchemaName : "peer" ,
},
{
Name : "Chats" ,
SchemaName : "chats" ,
},
{
Name : "Users" ,
SchemaName : "users" ,
},
{
Name : "PsaType" ,
SchemaName : "psa_type" ,
Null : !p .Flags .Has (1 ),
},
{
Name : "PsaMessage" ,
SchemaName : "psa_message" ,
Null : !p .Flags .Has (2 ),
},
}
return typ
}
func (p *HelpPromoData ) SetFlags () {
if !(p .Proxy == false ) {
p .Flags .Set (0 )
}
if !(p .PsaType == "" ) {
p .Flags .Set (1 )
}
if !(p .PsaMessage == "" ) {
p .Flags .Set (2 )
}
}
func (p *HelpPromoData ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode help.promoData#8c39793f as nil" )
}
b .PutID (HelpPromoDataTypeID )
return p .EncodeBare (b )
}
func (p *HelpPromoData ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode help.promoData#8c39793f as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field flags: %w" , err )
}
b .PutInt (p .Expires )
if p .Peer == nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field peer is nil" )
}
if err := p .Peer .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field peer: %w" , err )
}
b .PutVectorHeader (len (p .Chats ))
for idx , v := range p .Chats {
if v == nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field chats element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field chats element with index %d: %w" , idx , err )
}
}
b .PutVectorHeader (len (p .Users ))
for idx , v := range p .Users {
if v == nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field users element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.promoData#8c39793f: field users element with index %d: %w" , idx , err )
}
}
if p .Flags .Has (1 ) {
b .PutString (p .PsaType )
}
if p .Flags .Has (2 ) {
b .PutString (p .PsaMessage )
}
return nil
}
func (p *HelpPromoData ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode help.promoData#8c39793f to nil" )
}
if err := b .ConsumeID (HelpPromoDataTypeID ); err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: %w" , err )
}
return p .DecodeBare (b )
}
func (p *HelpPromoData ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode help.promoData#8c39793f to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field flags: %w" , err )
}
}
p .Proxy = p .Flags .Has (0 )
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field expires: %w" , err )
}
p .Expires = value
}
{
value , err := DecodePeer (b )
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field peer: %w" , err )
}
p .Peer = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field chats: %w" , err )
}
if headerLen > 0 {
p .Chats = make ([]ChatClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeChat (b )
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field chats: %w" , err )
}
p .Chats = append (p .Chats , value )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field users: %w" , err )
}
if headerLen > 0 {
p .Users = make ([]UserClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeUser (b )
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field users: %w" , err )
}
p .Users = append (p .Users , value )
}
}
if p .Flags .Has (1 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field psa_type: %w" , err )
}
p .PsaType = value
}
if p .Flags .Has (2 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode help.promoData#8c39793f: field psa_message: %w" , err )
}
p .PsaMessage = value
}
return nil
}
func (p *HelpPromoData ) SetProxy (value bool ) {
if value {
p .Flags .Set (0 )
p .Proxy = true
} else {
p .Flags .Unset (0 )
p .Proxy = false
}
}
func (p *HelpPromoData ) GetProxy () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (0 )
}
func (p *HelpPromoData ) GetExpires () (value int ) {
if p == nil {
return
}
return p .Expires
}
func (p *HelpPromoData ) GetPeer () (value PeerClass ) {
if p == nil {
return
}
return p .Peer
}
func (p *HelpPromoData ) GetChats () (value []ChatClass ) {
if p == nil {
return
}
return p .Chats
}
func (p *HelpPromoData ) GetUsers () (value []UserClass ) {
if p == nil {
return
}
return p .Users
}
func (p *HelpPromoData ) SetPsaType (value string ) {
p .Flags .Set (1 )
p .PsaType = value
}
func (p *HelpPromoData ) GetPsaType () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (1 ) {
return value , false
}
return p .PsaType , true
}
func (p *HelpPromoData ) SetPsaMessage (value string ) {
p .Flags .Set (2 )
p .PsaMessage = value
}
func (p *HelpPromoData ) GetPsaMessage () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (2 ) {
return value , false
}
return p .PsaMessage , true
}
func (p *HelpPromoData ) MapChats () (value ChatClassArray ) {
return ChatClassArray (p .Chats )
}
func (p *HelpPromoData ) MapUsers () (value UserClassArray ) {
return UserClassArray (p .Users )
}
const HelpPromoDataClassName = "help.PromoData"
type HelpPromoDataClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () HelpPromoDataClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
GetExpires () (value int )
AsNotEmpty () (*HelpPromoData , bool )
}
func (p *HelpPromoDataEmpty ) AsNotEmpty () (*HelpPromoData , bool ) {
return nil , false
}
func (p *HelpPromoData ) AsNotEmpty () (*HelpPromoData , bool ) {
return p , true
}
func DecodeHelpPromoData (buf *bin .Buffer ) (HelpPromoDataClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case HelpPromoDataEmptyTypeID :
v := HelpPromoDataEmpty {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode HelpPromoDataClass: %w" , err )
}
return &v , nil
case HelpPromoDataTypeID :
v := HelpPromoData {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode HelpPromoDataClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode HelpPromoDataClass: %w" , bin .NewUnexpectedID (id ))
}
}
type HelpPromoDataBox struct {
PromoData HelpPromoDataClass
}
func (b *HelpPromoDataBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode HelpPromoDataBox to nil" )
}
v , err := DecodeHelpPromoData (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .PromoData = v
return nil
}
func (b *HelpPromoDataBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .PromoData == nil {
return fmt .Errorf ("unable to encode HelpPromoDataClass as nil" )
}
return b .PromoData .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 .