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 OnrampAvailability struct {
Flags bin .Fields
Allowed bool
BuyAllowed bool
CountryCode string
State string
Methods []OnrampMethodAvailability
}
const OnrampAvailabilityTypeID = 0xf9c84973
var (
_ bin .Encoder = &OnrampAvailability {}
_ bin .Decoder = &OnrampAvailability {}
_ bin .BareEncoder = &OnrampAvailability {}
_ bin .BareDecoder = &OnrampAvailability {}
)
func (o *OnrampAvailability ) Zero () bool {
if o == nil {
return true
}
if !(o .Flags .Zero ()) {
return false
}
if !(o .Allowed == false ) {
return false
}
if !(o .BuyAllowed == false ) {
return false
}
if !(o .CountryCode == "" ) {
return false
}
if !(o .State == "" ) {
return false
}
if !(o .Methods == nil ) {
return false
}
return true
}
func (o *OnrampAvailability ) String () string {
if o == nil {
return "OnrampAvailability(nil)"
}
type Alias OnrampAvailability
return fmt .Sprintf ("OnrampAvailability%+v" , Alias (*o ))
}
func (o *OnrampAvailability ) FillFrom (from interface {
GetAllowed () (value bool )
GetBuyAllowed () (value bool )
GetCountryCode () (value string )
GetState () (value string , ok bool )
GetMethods () (value []OnrampMethodAvailability )
}) {
o .Allowed = from .GetAllowed ()
o .BuyAllowed = from .GetBuyAllowed ()
o .CountryCode = from .GetCountryCode ()
if val , ok := from .GetState (); ok {
o .State = val
}
o .Methods = from .GetMethods ()
}
func (*OnrampAvailability ) TypeID () uint32 {
return OnrampAvailabilityTypeID
}
func (*OnrampAvailability ) TypeName () string {
return "onrampAvailability"
}
func (o *OnrampAvailability ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "onrampAvailability" ,
ID : OnrampAvailabilityTypeID ,
}
if o == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Allowed" ,
SchemaName : "allowed" ,
Null : !o .Flags .Has (0 ),
},
{
Name : "BuyAllowed" ,
SchemaName : "buy_allowed" ,
Null : !o .Flags .Has (1 ),
},
{
Name : "CountryCode" ,
SchemaName : "country_code" ,
},
{
Name : "State" ,
SchemaName : "state" ,
Null : !o .Flags .Has (2 ),
},
{
Name : "Methods" ,
SchemaName : "methods" ,
},
}
return typ
}
func (o *OnrampAvailability ) SetFlags () {
if !(o .Allowed == false ) {
o .Flags .Set (0 )
}
if !(o .BuyAllowed == false ) {
o .Flags .Set (1 )
}
if !(o .State == "" ) {
o .Flags .Set (2 )
}
}
func (o *OnrampAvailability ) Encode (b *bin .Buffer ) error {
if o == nil {
return fmt .Errorf ("can't encode onrampAvailability#f9c84973 as nil" )
}
b .PutID (OnrampAvailabilityTypeID )
return o .EncodeBare (b )
}
func (o *OnrampAvailability ) EncodeBare (b *bin .Buffer ) error {
if o == nil {
return fmt .Errorf ("can't encode onrampAvailability#f9c84973 as nil" )
}
o .SetFlags ()
if err := o .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode onrampAvailability#f9c84973: field flags: %w" , err )
}
b .PutString (o .CountryCode )
if o .Flags .Has (2 ) {
b .PutString (o .State )
}
b .PutVectorHeader (len (o .Methods ))
for idx , v := range o .Methods {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode onrampAvailability#f9c84973: field methods element with index %d: %w" , idx , err )
}
}
return nil
}
func (o *OnrampAvailability ) Decode (b *bin .Buffer ) error {
if o == nil {
return fmt .Errorf ("can't decode onrampAvailability#f9c84973 to nil" )
}
if err := b .ConsumeID (OnrampAvailabilityTypeID ); err != nil {
return fmt .Errorf ("unable to decode onrampAvailability#f9c84973: %w" , err )
}
return o .DecodeBare (b )
}
func (o *OnrampAvailability ) DecodeBare (b *bin .Buffer ) error {
if o == nil {
return fmt .Errorf ("can't decode onrampAvailability#f9c84973 to nil" )
}
{
if err := o .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode onrampAvailability#f9c84973: field flags: %w" , err )
}
}
o .Allowed = o .Flags .Has (0 )
o .BuyAllowed = o .Flags .Has (1 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode onrampAvailability#f9c84973: field country_code: %w" , err )
}
o .CountryCode = value
}
if o .Flags .Has (2 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode onrampAvailability#f9c84973: field state: %w" , err )
}
o .State = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode onrampAvailability#f9c84973: field methods: %w" , err )
}
if headerLen > 0 {
o .Methods = make ([]OnrampMethodAvailability , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value OnrampMethodAvailability
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode onrampAvailability#f9c84973: field methods: %w" , err )
}
o .Methods = append (o .Methods , value )
}
}
return nil
}
func (o *OnrampAvailability ) SetAllowed (value bool ) {
if value {
o .Flags .Set (0 )
o .Allowed = true
} else {
o .Flags .Unset (0 )
o .Allowed = false
}
}
func (o *OnrampAvailability ) GetAllowed () (value bool ) {
if o == nil {
return
}
return o .Flags .Has (0 )
}
func (o *OnrampAvailability ) SetBuyAllowed (value bool ) {
if value {
o .Flags .Set (1 )
o .BuyAllowed = true
} else {
o .Flags .Unset (1 )
o .BuyAllowed = false
}
}
func (o *OnrampAvailability ) GetBuyAllowed () (value bool ) {
if o == nil {
return
}
return o .Flags .Has (1 )
}
func (o *OnrampAvailability ) GetCountryCode () (value string ) {
if o == nil {
return
}
return o .CountryCode
}
func (o *OnrampAvailability ) SetState (value string ) {
o .Flags .Set (2 )
o .State = value
}
func (o *OnrampAvailability ) GetState () (value string , ok bool ) {
if o == nil {
return
}
if !o .Flags .Has (2 ) {
return value , false
}
return o .State , true
}
func (o *OnrampAvailability ) GetMethods () (value []OnrampMethodAvailability ) {
if o == nil {
return
}
return o .Methods
}
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 .