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 GeoPointAddress struct {
Flags bin .Fields
CountryISO2 string
State string
City string
Street string
}
const GeoPointAddressTypeID = 0xde4c5d93
var (
_ bin .Encoder = &GeoPointAddress {}
_ bin .Decoder = &GeoPointAddress {}
_ bin .BareEncoder = &GeoPointAddress {}
_ bin .BareDecoder = &GeoPointAddress {}
)
func (g *GeoPointAddress ) Zero () bool {
if g == nil {
return true
}
if !(g .Flags .Zero ()) {
return false
}
if !(g .CountryISO2 == "" ) {
return false
}
if !(g .State == "" ) {
return false
}
if !(g .City == "" ) {
return false
}
if !(g .Street == "" ) {
return false
}
return true
}
func (g *GeoPointAddress ) String () string {
if g == nil {
return "GeoPointAddress(nil)"
}
type Alias GeoPointAddress
return fmt .Sprintf ("GeoPointAddress%+v" , Alias (*g ))
}
func (g *GeoPointAddress ) FillFrom (from interface {
GetCountryISO2 () (value string )
GetState () (value string , ok bool )
GetCity () (value string , ok bool )
GetStreet () (value string , ok bool )
}) {
g .CountryISO2 = from .GetCountryISO2 ()
if val , ok := from .GetState (); ok {
g .State = val
}
if val , ok := from .GetCity (); ok {
g .City = val
}
if val , ok := from .GetStreet (); ok {
g .Street = val
}
}
func (*GeoPointAddress ) TypeID () uint32 {
return GeoPointAddressTypeID
}
func (*GeoPointAddress ) TypeName () string {
return "geoPointAddress"
}
func (g *GeoPointAddress ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "geoPointAddress" ,
ID : GeoPointAddressTypeID ,
}
if g == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "CountryISO2" ,
SchemaName : "country_iso2" ,
},
{
Name : "State" ,
SchemaName : "state" ,
Null : !g .Flags .Has (0 ),
},
{
Name : "City" ,
SchemaName : "city" ,
Null : !g .Flags .Has (1 ),
},
{
Name : "Street" ,
SchemaName : "street" ,
Null : !g .Flags .Has (2 ),
},
}
return typ
}
func (g *GeoPointAddress ) SetFlags () {
if !(g .State == "" ) {
g .Flags .Set (0 )
}
if !(g .City == "" ) {
g .Flags .Set (1 )
}
if !(g .Street == "" ) {
g .Flags .Set (2 )
}
}
func (g *GeoPointAddress ) Encode (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't encode geoPointAddress#de4c5d93 as nil" )
}
b .PutID (GeoPointAddressTypeID )
return g .EncodeBare (b )
}
func (g *GeoPointAddress ) EncodeBare (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't encode geoPointAddress#de4c5d93 as nil" )
}
g .SetFlags ()
if err := g .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode geoPointAddress#de4c5d93: field flags: %w" , err )
}
b .PutString (g .CountryISO2 )
if g .Flags .Has (0 ) {
b .PutString (g .State )
}
if g .Flags .Has (1 ) {
b .PutString (g .City )
}
if g .Flags .Has (2 ) {
b .PutString (g .Street )
}
return nil
}
func (g *GeoPointAddress ) Decode (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't decode geoPointAddress#de4c5d93 to nil" )
}
if err := b .ConsumeID (GeoPointAddressTypeID ); err != nil {
return fmt .Errorf ("unable to decode geoPointAddress#de4c5d93: %w" , err )
}
return g .DecodeBare (b )
}
func (g *GeoPointAddress ) DecodeBare (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't decode geoPointAddress#de4c5d93 to nil" )
}
{
if err := g .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode geoPointAddress#de4c5d93: field flags: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode geoPointAddress#de4c5d93: field country_iso2: %w" , err )
}
g .CountryISO2 = value
}
if g .Flags .Has (0 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode geoPointAddress#de4c5d93: field state: %w" , err )
}
g .State = value
}
if g .Flags .Has (1 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode geoPointAddress#de4c5d93: field city: %w" , err )
}
g .City = value
}
if g .Flags .Has (2 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode geoPointAddress#de4c5d93: field street: %w" , err )
}
g .Street = value
}
return nil
}
func (g *GeoPointAddress ) GetCountryISO2 () (value string ) {
if g == nil {
return
}
return g .CountryISO2
}
func (g *GeoPointAddress ) SetState (value string ) {
g .Flags .Set (0 )
g .State = value
}
func (g *GeoPointAddress ) GetState () (value string , ok bool ) {
if g == nil {
return
}
if !g .Flags .Has (0 ) {
return value , false
}
return g .State , true
}
func (g *GeoPointAddress ) SetCity (value string ) {
g .Flags .Set (1 )
g .City = value
}
func (g *GeoPointAddress ) GetCity () (value string , ok bool ) {
if g == nil {
return
}
if !g .Flags .Has (1 ) {
return value , false
}
return g .City , true
}
func (g *GeoPointAddress ) SetStreet (value string ) {
g .Flags .Set (2 )
g .Street = value
}
func (g *GeoPointAddress ) GetStreet () (value string , ok bool ) {
if g == nil {
return
}
if !g .Flags .Has (2 ) {
return value , false
}
return g .Street , true
}
The pages are generated with Golds v0.8.4 . (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 .