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 DCOption struct {
Flags bin .Fields
Ipv6 bool
MediaOnly bool
TCPObfuscatedOnly bool
CDN bool
Static bool
ThisPortOnly bool
ID int
IPAddress string
Port int
Secret []byte
}
const DCOptionTypeID = 0x18b7a10d
var (
_ bin .Encoder = &DCOption {}
_ bin .Decoder = &DCOption {}
_ bin .BareEncoder = &DCOption {}
_ bin .BareDecoder = &DCOption {}
)
func (d *DCOption ) Zero () bool {
if d == nil {
return true
}
if !(d .Flags .Zero ()) {
return false
}
if !(d .Ipv6 == false ) {
return false
}
if !(d .MediaOnly == false ) {
return false
}
if !(d .TCPObfuscatedOnly == false ) {
return false
}
if !(d .CDN == false ) {
return false
}
if !(d .Static == false ) {
return false
}
if !(d .ThisPortOnly == false ) {
return false
}
if !(d .ID == 0 ) {
return false
}
if !(d .IPAddress == "" ) {
return false
}
if !(d .Port == 0 ) {
return false
}
if !(d .Secret == nil ) {
return false
}
return true
}
func (d *DCOption ) String () string {
if d == nil {
return "DCOption(nil)"
}
type Alias DCOption
return fmt .Sprintf ("DCOption%+v" , Alias (*d ))
}
func (d *DCOption ) FillFrom (from interface {
GetIpv6 () (value bool )
GetMediaOnly () (value bool )
GetTCPObfuscatedOnly () (value bool )
GetCDN () (value bool )
GetStatic () (value bool )
GetThisPortOnly () (value bool )
GetID () (value int )
GetIPAddress () (value string )
GetPort () (value int )
GetSecret () (value []byte , ok bool )
}) {
d .Ipv6 = from .GetIpv6 ()
d .MediaOnly = from .GetMediaOnly ()
d .TCPObfuscatedOnly = from .GetTCPObfuscatedOnly ()
d .CDN = from .GetCDN ()
d .Static = from .GetStatic ()
d .ThisPortOnly = from .GetThisPortOnly ()
d .ID = from .GetID ()
d .IPAddress = from .GetIPAddress ()
d .Port = from .GetPort ()
if val , ok := from .GetSecret (); ok {
d .Secret = val
}
}
func (*DCOption ) TypeID () uint32 {
return DCOptionTypeID
}
func (*DCOption ) TypeName () string {
return "dcOption"
}
func (d *DCOption ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "dcOption" ,
ID : DCOptionTypeID ,
}
if d == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Ipv6" ,
SchemaName : "ipv6" ,
Null : !d .Flags .Has (0 ),
},
{
Name : "MediaOnly" ,
SchemaName : "media_only" ,
Null : !d .Flags .Has (1 ),
},
{
Name : "TCPObfuscatedOnly" ,
SchemaName : "tcpo_only" ,
Null : !d .Flags .Has (2 ),
},
{
Name : "CDN" ,
SchemaName : "cdn" ,
Null : !d .Flags .Has (3 ),
},
{
Name : "Static" ,
SchemaName : "static" ,
Null : !d .Flags .Has (4 ),
},
{
Name : "ThisPortOnly" ,
SchemaName : "this_port_only" ,
Null : !d .Flags .Has (5 ),
},
{
Name : "ID" ,
SchemaName : "id" ,
},
{
Name : "IPAddress" ,
SchemaName : "ip_address" ,
},
{
Name : "Port" ,
SchemaName : "port" ,
},
{
Name : "Secret" ,
SchemaName : "secret" ,
Null : !d .Flags .Has (10 ),
},
}
return typ
}
func (d *DCOption ) SetFlags () {
if !(d .Ipv6 == false ) {
d .Flags .Set (0 )
}
if !(d .MediaOnly == false ) {
d .Flags .Set (1 )
}
if !(d .TCPObfuscatedOnly == false ) {
d .Flags .Set (2 )
}
if !(d .CDN == false ) {
d .Flags .Set (3 )
}
if !(d .Static == false ) {
d .Flags .Set (4 )
}
if !(d .ThisPortOnly == false ) {
d .Flags .Set (5 )
}
if !(d .Secret == nil ) {
d .Flags .Set (10 )
}
}
func (d *DCOption ) Encode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode dcOption#18b7a10d as nil" )
}
b .PutID (DCOptionTypeID )
return d .EncodeBare (b )
}
func (d *DCOption ) EncodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode dcOption#18b7a10d as nil" )
}
d .SetFlags ()
if err := d .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode dcOption#18b7a10d: field flags: %w" , err )
}
b .PutInt (d .ID )
b .PutString (d .IPAddress )
b .PutInt (d .Port )
if d .Flags .Has (10 ) {
b .PutBytes (d .Secret )
}
return nil
}
func (d *DCOption ) Decode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode dcOption#18b7a10d to nil" )
}
if err := b .ConsumeID (DCOptionTypeID ); err != nil {
return fmt .Errorf ("unable to decode dcOption#18b7a10d: %w" , err )
}
return d .DecodeBare (b )
}
func (d *DCOption ) DecodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode dcOption#18b7a10d to nil" )
}
{
if err := d .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode dcOption#18b7a10d: field flags: %w" , err )
}
}
d .Ipv6 = d .Flags .Has (0 )
d .MediaOnly = d .Flags .Has (1 )
d .TCPObfuscatedOnly = d .Flags .Has (2 )
d .CDN = d .Flags .Has (3 )
d .Static = d .Flags .Has (4 )
d .ThisPortOnly = d .Flags .Has (5 )
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode dcOption#18b7a10d: field id: %w" , err )
}
d .ID = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode dcOption#18b7a10d: field ip_address: %w" , err )
}
d .IPAddress = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode dcOption#18b7a10d: field port: %w" , err )
}
d .Port = value
}
if d .Flags .Has (10 ) {
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode dcOption#18b7a10d: field secret: %w" , err )
}
d .Secret = value
}
return nil
}
func (d *DCOption ) SetIpv6 (value bool ) {
if value {
d .Flags .Set (0 )
d .Ipv6 = true
} else {
d .Flags .Unset (0 )
d .Ipv6 = false
}
}
func (d *DCOption ) GetIpv6 () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (0 )
}
func (d *DCOption ) SetMediaOnly (value bool ) {
if value {
d .Flags .Set (1 )
d .MediaOnly = true
} else {
d .Flags .Unset (1 )
d .MediaOnly = false
}
}
func (d *DCOption ) GetMediaOnly () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (1 )
}
func (d *DCOption ) SetTCPObfuscatedOnly (value bool ) {
if value {
d .Flags .Set (2 )
d .TCPObfuscatedOnly = true
} else {
d .Flags .Unset (2 )
d .TCPObfuscatedOnly = false
}
}
func (d *DCOption ) GetTCPObfuscatedOnly () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (2 )
}
func (d *DCOption ) SetCDN (value bool ) {
if value {
d .Flags .Set (3 )
d .CDN = true
} else {
d .Flags .Unset (3 )
d .CDN = false
}
}
func (d *DCOption ) GetCDN () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (3 )
}
func (d *DCOption ) SetStatic (value bool ) {
if value {
d .Flags .Set (4 )
d .Static = true
} else {
d .Flags .Unset (4 )
d .Static = false
}
}
func (d *DCOption ) GetStatic () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (4 )
}
func (d *DCOption ) SetThisPortOnly (value bool ) {
if value {
d .Flags .Set (5 )
d .ThisPortOnly = true
} else {
d .Flags .Unset (5 )
d .ThisPortOnly = false
}
}
func (d *DCOption ) GetThisPortOnly () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (5 )
}
func (d *DCOption ) GetID () (value int ) {
if d == nil {
return
}
return d .ID
}
func (d *DCOption ) GetIPAddress () (value string ) {
if d == nil {
return
}
return d .IPAddress
}
func (d *DCOption ) GetPort () (value int ) {
if d == nil {
return
}
return d .Port
}
func (d *DCOption ) SetSecret (value []byte ) {
d .Flags .Set (10 )
d .Secret = value
}
func (d *DCOption ) GetSecret () (value []byte , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (10 ) {
return value , false
}
return d .Secret , true
}
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 .