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 HelpCountry struct {
Flags bin .Fields
Hidden bool
ISO2 string
DefaultName string
Name string
CountryCodes []HelpCountryCode
}
const HelpCountryTypeID = 0xc3878e23
var (
_ bin .Encoder = &HelpCountry {}
_ bin .Decoder = &HelpCountry {}
_ bin .BareEncoder = &HelpCountry {}
_ bin .BareDecoder = &HelpCountry {}
)
func (c *HelpCountry ) Zero () bool {
if c == nil {
return true
}
if !(c .Flags .Zero ()) {
return false
}
if !(c .Hidden == false ) {
return false
}
if !(c .ISO2 == "" ) {
return false
}
if !(c .DefaultName == "" ) {
return false
}
if !(c .Name == "" ) {
return false
}
if !(c .CountryCodes == nil ) {
return false
}
return true
}
func (c *HelpCountry ) String () string {
if c == nil {
return "HelpCountry(nil)"
}
type Alias HelpCountry
return fmt .Sprintf ("HelpCountry%+v" , Alias (*c ))
}
func (c *HelpCountry ) FillFrom (from interface {
GetHidden () (value bool )
GetISO2 () (value string )
GetDefaultName () (value string )
GetName () (value string , ok bool )
GetCountryCodes () (value []HelpCountryCode )
}) {
c .Hidden = from .GetHidden ()
c .ISO2 = from .GetISO2 ()
c .DefaultName = from .GetDefaultName ()
if val , ok := from .GetName (); ok {
c .Name = val
}
c .CountryCodes = from .GetCountryCodes ()
}
func (*HelpCountry ) TypeID () uint32 {
return HelpCountryTypeID
}
func (*HelpCountry ) TypeName () string {
return "help.country"
}
func (c *HelpCountry ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "help.country" ,
ID : HelpCountryTypeID ,
}
if c == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Hidden" ,
SchemaName : "hidden" ,
Null : !c .Flags .Has (0 ),
},
{
Name : "ISO2" ,
SchemaName : "iso2" ,
},
{
Name : "DefaultName" ,
SchemaName : "default_name" ,
},
{
Name : "Name" ,
SchemaName : "name" ,
Null : !c .Flags .Has (1 ),
},
{
Name : "CountryCodes" ,
SchemaName : "country_codes" ,
},
}
return typ
}
func (c *HelpCountry ) SetFlags () {
if !(c .Hidden == false ) {
c .Flags .Set (0 )
}
if !(c .Name == "" ) {
c .Flags .Set (1 )
}
}
func (c *HelpCountry ) Encode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode help.country#c3878e23 as nil" )
}
b .PutID (HelpCountryTypeID )
return c .EncodeBare (b )
}
func (c *HelpCountry ) EncodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode help.country#c3878e23 as nil" )
}
c .SetFlags ()
if err := c .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.country#c3878e23: field flags: %w" , err )
}
b .PutString (c .ISO2 )
b .PutString (c .DefaultName )
if c .Flags .Has (1 ) {
b .PutString (c .Name )
}
b .PutVectorHeader (len (c .CountryCodes ))
for idx , v := range c .CountryCodes {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode help.country#c3878e23: field country_codes element with index %d: %w" , idx , err )
}
}
return nil
}
func (c *HelpCountry ) Decode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode help.country#c3878e23 to nil" )
}
if err := b .ConsumeID (HelpCountryTypeID ); err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: %w" , err )
}
return c .DecodeBare (b )
}
func (c *HelpCountry ) DecodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode help.country#c3878e23 to nil" )
}
{
if err := c .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: field flags: %w" , err )
}
}
c .Hidden = c .Flags .Has (0 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: field iso2: %w" , err )
}
c .ISO2 = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: field default_name: %w" , err )
}
c .DefaultName = value
}
if c .Flags .Has (1 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: field name: %w" , err )
}
c .Name = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: field country_codes: %w" , err )
}
if headerLen > 0 {
c .CountryCodes = make ([]HelpCountryCode , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value HelpCountryCode
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode help.country#c3878e23: field country_codes: %w" , err )
}
c .CountryCodes = append (c .CountryCodes , value )
}
}
return nil
}
func (c *HelpCountry ) SetHidden (value bool ) {
if value {
c .Flags .Set (0 )
c .Hidden = true
} else {
c .Flags .Unset (0 )
c .Hidden = false
}
}
func (c *HelpCountry ) GetHidden () (value bool ) {
if c == nil {
return
}
return c .Flags .Has (0 )
}
func (c *HelpCountry ) GetISO2 () (value string ) {
if c == nil {
return
}
return c .ISO2
}
func (c *HelpCountry ) GetDefaultName () (value string ) {
if c == nil {
return
}
return c .DefaultName
}
func (c *HelpCountry ) SetName (value string ) {
c .Flags .Set (1 )
c .Name = value
}
func (c *HelpCountry ) GetName () (value string , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (1 ) {
return value , false
}
return c .Name , true
}
func (c *HelpCountry ) GetCountryCodes () (value []HelpCountryCode ) {
if c == nil {
return
}
return c .CountryCodes
}
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 .