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 HelpTermsOfService struct {
Flags bin .Fields
Popup bool
ID DataJSON
Text string
Entities []MessageEntityClass
MinAgeConfirm int
}
const HelpTermsOfServiceTypeID = 0x780a0310
var (
_ bin .Encoder = &HelpTermsOfService {}
_ bin .Decoder = &HelpTermsOfService {}
_ bin .BareEncoder = &HelpTermsOfService {}
_ bin .BareDecoder = &HelpTermsOfService {}
)
func (t *HelpTermsOfService ) Zero () bool {
if t == nil {
return true
}
if !(t .Flags .Zero ()) {
return false
}
if !(t .Popup == false ) {
return false
}
if !(t .ID .Zero ()) {
return false
}
if !(t .Text == "" ) {
return false
}
if !(t .Entities == nil ) {
return false
}
if !(t .MinAgeConfirm == 0 ) {
return false
}
return true
}
func (t *HelpTermsOfService ) String () string {
if t == nil {
return "HelpTermsOfService(nil)"
}
type Alias HelpTermsOfService
return fmt .Sprintf ("HelpTermsOfService%+v" , Alias (*t ))
}
func (t *HelpTermsOfService ) FillFrom (from interface {
GetPopup () (value bool )
GetID () (value DataJSON )
GetText () (value string )
GetEntities () (value []MessageEntityClass )
GetMinAgeConfirm () (value int , ok bool )
}) {
t .Popup = from .GetPopup ()
t .ID = from .GetID ()
t .Text = from .GetText ()
t .Entities = from .GetEntities ()
if val , ok := from .GetMinAgeConfirm (); ok {
t .MinAgeConfirm = val
}
}
func (*HelpTermsOfService ) TypeID () uint32 {
return HelpTermsOfServiceTypeID
}
func (*HelpTermsOfService ) TypeName () string {
return "help.termsOfService"
}
func (t *HelpTermsOfService ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "help.termsOfService" ,
ID : HelpTermsOfServiceTypeID ,
}
if t == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Popup" ,
SchemaName : "popup" ,
Null : !t .Flags .Has (0 ),
},
{
Name : "ID" ,
SchemaName : "id" ,
},
{
Name : "Text" ,
SchemaName : "text" ,
},
{
Name : "Entities" ,
SchemaName : "entities" ,
},
{
Name : "MinAgeConfirm" ,
SchemaName : "min_age_confirm" ,
Null : !t .Flags .Has (1 ),
},
}
return typ
}
func (t *HelpTermsOfService ) SetFlags () {
if !(t .Popup == false ) {
t .Flags .Set (0 )
}
if !(t .MinAgeConfirm == 0 ) {
t .Flags .Set (1 )
}
}
func (t *HelpTermsOfService ) Encode (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't encode help.termsOfService#780a0310 as nil" )
}
b .PutID (HelpTermsOfServiceTypeID )
return t .EncodeBare (b )
}
func (t *HelpTermsOfService ) EncodeBare (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't encode help.termsOfService#780a0310 as nil" )
}
t .SetFlags ()
if err := t .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.termsOfService#780a0310: field flags: %w" , err )
}
if err := t .ID .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.termsOfService#780a0310: field id: %w" , err )
}
b .PutString (t .Text )
b .PutVectorHeader (len (t .Entities ))
for idx , v := range t .Entities {
if v == nil {
return fmt .Errorf ("unable to encode help.termsOfService#780a0310: field entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.termsOfService#780a0310: field entities element with index %d: %w" , idx , err )
}
}
if t .Flags .Has (1 ) {
b .PutInt (t .MinAgeConfirm )
}
return nil
}
func (t *HelpTermsOfService ) Decode (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't decode help.termsOfService#780a0310 to nil" )
}
if err := b .ConsumeID (HelpTermsOfServiceTypeID ); err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: %w" , err )
}
return t .DecodeBare (b )
}
func (t *HelpTermsOfService ) DecodeBare (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't decode help.termsOfService#780a0310 to nil" )
}
{
if err := t .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: field flags: %w" , err )
}
}
t .Popup = t .Flags .Has (0 )
{
if err := t .ID .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: field id: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: field text: %w" , err )
}
t .Text = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: field entities: %w" , err )
}
if headerLen > 0 {
t .Entities = make ([]MessageEntityClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeMessageEntity (b )
if err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: field entities: %w" , err )
}
t .Entities = append (t .Entities , value )
}
}
if t .Flags .Has (1 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode help.termsOfService#780a0310: field min_age_confirm: %w" , err )
}
t .MinAgeConfirm = value
}
return nil
}
func (t *HelpTermsOfService ) SetPopup (value bool ) {
if value {
t .Flags .Set (0 )
t .Popup = true
} else {
t .Flags .Unset (0 )
t .Popup = false
}
}
func (t *HelpTermsOfService ) GetPopup () (value bool ) {
if t == nil {
return
}
return t .Flags .Has (0 )
}
func (t *HelpTermsOfService ) GetID () (value DataJSON ) {
if t == nil {
return
}
return t .ID
}
func (t *HelpTermsOfService ) GetText () (value string ) {
if t == nil {
return
}
return t .Text
}
func (t *HelpTermsOfService ) GetEntities () (value []MessageEntityClass ) {
if t == nil {
return
}
return t .Entities
}
func (t *HelpTermsOfService ) SetMinAgeConfirm (value int ) {
t .Flags .Set (1 )
t .MinAgeConfirm = value
}
func (t *HelpTermsOfService ) GetMinAgeConfirm () (value int , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (1 ) {
return value , false
}
return t .MinAgeConfirm , true
}
func (t *HelpTermsOfService ) MapEntities () (value MessageEntityClassArray ) {
return MessageEntityClassArray (t .Entities )
}
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 .