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  AccessPointRule  struct  { 
	 
	PhonePrefixRules  string  
	 
	DCID  int  
	 
	IPs  []IPPortClass  
} 
 
 
const  AccessPointRuleTypeID  = 0x4679b65f  
 
 
var  ( 
	_ bin .Encoder      = &AccessPointRule {} 
	_ bin .Decoder      = &AccessPointRule {} 
	_ bin .BareEncoder  = &AccessPointRule {} 
	_ bin .BareDecoder  = &AccessPointRule {} 
) 
 
func  (a  *AccessPointRule ) Zero  () bool  { 
	if  a  == nil  { 
		return  true  
	} 
	if  !(a .PhonePrefixRules  == "" ) { 
		return  false  
	} 
	if  !(a .DCID  == 0 ) { 
		return  false  
	} 
	if  !(a .IPs  == nil ) { 
		return  false  
	} 
 
	return  true  
} 
 
 
func  (a  *AccessPointRule ) String  () string  { 
	if  a  == nil  { 
		return  "AccessPointRule(nil)"  
	} 
	type  Alias  AccessPointRule  
	return  fmt .Sprintf ("AccessPointRule%+v" , Alias (*a )) 
} 
 
 
func  (a  *AccessPointRule ) FillFrom  (from  interface  { 
	GetPhonePrefixRules () (value  string ) 
	GetDCID () (value  int ) 
	GetIPs () (value  []IPPortClass ) 
}) { 
	a .PhonePrefixRules  = from .GetPhonePrefixRules () 
	a .DCID  = from .GetDCID () 
	a .IPs  = from .GetIPs () 
} 
 
 
 
 
func  (*AccessPointRule ) TypeID  () uint32  { 
	return  AccessPointRuleTypeID  
} 
 
 
func  (*AccessPointRule ) TypeName  () string  { 
	return  "accessPointRule"  
} 
 
 
func  (a  *AccessPointRule ) TypeInfo  () tdp .Type  { 
	typ  := tdp .Type { 
		Name : "accessPointRule" , 
		ID :   AccessPointRuleTypeID , 
	} 
	if  a  == nil  { 
		typ .Null  = true  
		return  typ  
	} 
	typ .Fields  = []tdp .Field { 
		{ 
			Name :       "PhonePrefixRules" , 
			SchemaName : "phone_prefix_rules" , 
		}, 
		{ 
			Name :       "DCID" , 
			SchemaName : "dc_id" , 
		}, 
		{ 
			Name :       "IPs" , 
			SchemaName : "ips" , 
		}, 
	} 
	return  typ  
} 
 
 
func  (a  *AccessPointRule ) Encode  (b  *bin .Buffer ) error  { 
	if  a  == nil  { 
		return  fmt .Errorf ("can't encode accessPointRule#4679b65f as nil" ) 
	} 
	b .PutID (AccessPointRuleTypeID ) 
	return  a .EncodeBare (b ) 
} 
 
 
func  (a  *AccessPointRule ) EncodeBare  (b  *bin .Buffer ) error  { 
	if  a  == nil  { 
		return  fmt .Errorf ("can't encode accessPointRule#4679b65f as nil" ) 
	} 
	b .PutString (a .PhonePrefixRules ) 
	b .PutInt (a .DCID ) 
	b .PutInt (len (a .IPs )) 
	for  idx , v  := range  a .IPs  { 
		if  v  == nil  { 
			return  fmt .Errorf ("unable to encode accessPointRule#4679b65f: field ips element with index %d is nil" , idx ) 
		} 
		if  err  := v .EncodeBare (b ); err  != nil  { 
			return  fmt .Errorf ("unable to encode bare accessPointRule#4679b65f: field ips element with index %d: %w" , idx , err ) 
		} 
	} 
	return  nil  
} 
 
 
func  (a  *AccessPointRule ) Decode  (b  *bin .Buffer ) error  { 
	if  a  == nil  { 
		return  fmt .Errorf ("can't decode accessPointRule#4679b65f to nil" ) 
	} 
	if  err  := b .ConsumeID (AccessPointRuleTypeID ); err  != nil  { 
		return  fmt .Errorf ("unable to decode accessPointRule#4679b65f: %w" , err ) 
	} 
	return  a .DecodeBare (b ) 
} 
 
 
func  (a  *AccessPointRule ) DecodeBare  (b  *bin .Buffer ) error  { 
	if  a  == nil  { 
		return  fmt .Errorf ("can't decode accessPointRule#4679b65f to nil" ) 
	} 
	{ 
		value , err  := b .String () 
		if  err  != nil  { 
			return  fmt .Errorf ("unable to decode accessPointRule#4679b65f: field phone_prefix_rules: %w" , err ) 
		} 
		a .PhonePrefixRules  = value  
	} 
	{ 
		value , err  := b .Int () 
		if  err  != nil  { 
			return  fmt .Errorf ("unable to decode accessPointRule#4679b65f: field dc_id: %w" , err ) 
		} 
		a .DCID  = value  
	} 
	{ 
		headerLen , err  := b .Int () 
		if  err  != nil  { 
			return  fmt .Errorf ("unable to decode accessPointRule#4679b65f: field ips: %w" , err ) 
		} 
 
		if  headerLen  > 0  { 
			a .IPs  = make ([]IPPortClass , 0 , headerLen %bin .PreallocateLimit ) 
		} 
		for  idx  := 0 ; idx  < headerLen ; idx ++ { 
			value , err  := DecodeIPPort (b ) 
			if  err  != nil  { 
				return  fmt .Errorf ("unable to decode accessPointRule#4679b65f: field ips: %w" , err ) 
			} 
			a .IPs  = append (a .IPs , value ) 
		} 
	} 
	return  nil  
} 
 
 
func  (a  *AccessPointRule ) GetPhonePrefixRules  () (value  string ) { 
	if  a  == nil  { 
		return  
	} 
	return  a .PhonePrefixRules  
} 
 
 
func  (a  *AccessPointRule ) GetDCID  () (value  int ) { 
	if  a  == nil  { 
		return  
	} 
	return  a .DCID  
} 
 
 
func  (a  *AccessPointRule ) GetIPs  () (value  []IPPortClass ) { 
	if  a  == nil  { 
		return  
	} 
	return  a .IPs  
} 
 
 
func  (a  *AccessPointRule ) MapIPs  () (value  IPPortClassArray ) { 
	return  IPPortClassArray (a .IPs ) 
} 
  
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 .