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 AuthAuthorization struct {
Flags bin .Fields
SetupPasswordRequired bool
OtherwiseReloginDays int
TmpSessions int
FutureAuthToken []byte
User UserClass
}
const AuthAuthorizationTypeID = 0x2ea2c0d4
func (a AuthAuthorization ) construct () AuthAuthorizationClass { return &a }
var (
_ bin .Encoder = &AuthAuthorization {}
_ bin .Decoder = &AuthAuthorization {}
_ bin .BareEncoder = &AuthAuthorization {}
_ bin .BareDecoder = &AuthAuthorization {}
_ AuthAuthorizationClass = &AuthAuthorization {}
)
func (a *AuthAuthorization ) Zero () bool {
if a == nil {
return true
}
if !(a .Flags .Zero ()) {
return false
}
if !(a .SetupPasswordRequired == false ) {
return false
}
if !(a .OtherwiseReloginDays == 0 ) {
return false
}
if !(a .TmpSessions == 0 ) {
return false
}
if !(a .FutureAuthToken == nil ) {
return false
}
if !(a .User == nil ) {
return false
}
return true
}
func (a *AuthAuthorization ) String () string {
if a == nil {
return "AuthAuthorization(nil)"
}
type Alias AuthAuthorization
return fmt .Sprintf ("AuthAuthorization%+v" , Alias (*a ))
}
func (a *AuthAuthorization ) FillFrom (from interface {
GetSetupPasswordRequired () (value bool )
GetOtherwiseReloginDays () (value int , ok bool )
GetTmpSessions () (value int , ok bool )
GetFutureAuthToken () (value []byte , ok bool )
GetUser () (value UserClass )
}) {
a .SetupPasswordRequired = from .GetSetupPasswordRequired ()
if val , ok := from .GetOtherwiseReloginDays (); ok {
a .OtherwiseReloginDays = val
}
if val , ok := from .GetTmpSessions (); ok {
a .TmpSessions = val
}
if val , ok := from .GetFutureAuthToken (); ok {
a .FutureAuthToken = val
}
a .User = from .GetUser ()
}
func (*AuthAuthorization ) TypeID () uint32 {
return AuthAuthorizationTypeID
}
func (*AuthAuthorization ) TypeName () string {
return "auth.authorization"
}
func (a *AuthAuthorization ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "auth.authorization" ,
ID : AuthAuthorizationTypeID ,
}
if a == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "SetupPasswordRequired" ,
SchemaName : "setup_password_required" ,
Null : !a .Flags .Has (1 ),
},
{
Name : "OtherwiseReloginDays" ,
SchemaName : "otherwise_relogin_days" ,
Null : !a .Flags .Has (1 ),
},
{
Name : "TmpSessions" ,
SchemaName : "tmp_sessions" ,
Null : !a .Flags .Has (0 ),
},
{
Name : "FutureAuthToken" ,
SchemaName : "future_auth_token" ,
Null : !a .Flags .Has (2 ),
},
{
Name : "User" ,
SchemaName : "user" ,
},
}
return typ
}
func (a *AuthAuthorization ) SetFlags () {
if !(a .SetupPasswordRequired == false ) {
a .Flags .Set (1 )
}
if !(a .OtherwiseReloginDays == 0 ) {
a .Flags .Set (1 )
}
if !(a .TmpSessions == 0 ) {
a .Flags .Set (0 )
}
if !(a .FutureAuthToken == nil ) {
a .Flags .Set (2 )
}
}
func (a *AuthAuthorization ) Encode (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't encode auth.authorization#2ea2c0d4 as nil" )
}
b .PutID (AuthAuthorizationTypeID )
return a .EncodeBare (b )
}
func (a *AuthAuthorization ) EncodeBare (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't encode auth.authorization#2ea2c0d4 as nil" )
}
a .SetFlags ()
if err := a .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode auth.authorization#2ea2c0d4: field flags: %w" , err )
}
if a .Flags .Has (1 ) {
b .PutInt (a .OtherwiseReloginDays )
}
if a .Flags .Has (0 ) {
b .PutInt (a .TmpSessions )
}
if a .Flags .Has (2 ) {
b .PutBytes (a .FutureAuthToken )
}
if a .User == nil {
return fmt .Errorf ("unable to encode auth.authorization#2ea2c0d4: field user is nil" )
}
if err := a .User .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode auth.authorization#2ea2c0d4: field user: %w" , err )
}
return nil
}
func (a *AuthAuthorization ) Decode (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't decode auth.authorization#2ea2c0d4 to nil" )
}
if err := b .ConsumeID (AuthAuthorizationTypeID ); err != nil {
return fmt .Errorf ("unable to decode auth.authorization#2ea2c0d4: %w" , err )
}
return a .DecodeBare (b )
}
func (a *AuthAuthorization ) DecodeBare (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't decode auth.authorization#2ea2c0d4 to nil" )
}
{
if err := a .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode auth.authorization#2ea2c0d4: field flags: %w" , err )
}
}
a .SetupPasswordRequired = a .Flags .Has (1 )
if a .Flags .Has (1 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode auth.authorization#2ea2c0d4: field otherwise_relogin_days: %w" , err )
}
a .OtherwiseReloginDays = value
}
if a .Flags .Has (0 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode auth.authorization#2ea2c0d4: field tmp_sessions: %w" , err )
}
a .TmpSessions = value
}
if a .Flags .Has (2 ) {
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode auth.authorization#2ea2c0d4: field future_auth_token: %w" , err )
}
a .FutureAuthToken = value
}
{
value , err := DecodeUser (b )
if err != nil {
return fmt .Errorf ("unable to decode auth.authorization#2ea2c0d4: field user: %w" , err )
}
a .User = value
}
return nil
}
func (a *AuthAuthorization ) SetSetupPasswordRequired (value bool ) {
if value {
a .Flags .Set (1 )
a .SetupPasswordRequired = true
} else {
a .Flags .Unset (1 )
a .SetupPasswordRequired = false
}
}
func (a *AuthAuthorization ) GetSetupPasswordRequired () (value bool ) {
if a == nil {
return
}
return a .Flags .Has (1 )
}
func (a *AuthAuthorization ) SetOtherwiseReloginDays (value int ) {
a .Flags .Set (1 )
a .OtherwiseReloginDays = value
}
func (a *AuthAuthorization ) GetOtherwiseReloginDays () (value int , ok bool ) {
if a == nil {
return
}
if !a .Flags .Has (1 ) {
return value , false
}
return a .OtherwiseReloginDays , true
}
func (a *AuthAuthorization ) SetTmpSessions (value int ) {
a .Flags .Set (0 )
a .TmpSessions = value
}
func (a *AuthAuthorization ) GetTmpSessions () (value int , ok bool ) {
if a == nil {
return
}
if !a .Flags .Has (0 ) {
return value , false
}
return a .TmpSessions , true
}
func (a *AuthAuthorization ) SetFutureAuthToken (value []byte ) {
a .Flags .Set (2 )
a .FutureAuthToken = value
}
func (a *AuthAuthorization ) GetFutureAuthToken () (value []byte , ok bool ) {
if a == nil {
return
}
if !a .Flags .Has (2 ) {
return value , false
}
return a .FutureAuthToken , true
}
func (a *AuthAuthorization ) GetUser () (value UserClass ) {
if a == nil {
return
}
return a .User
}
type AuthAuthorizationSignUpRequired struct {
Flags bin .Fields
TermsOfService HelpTermsOfService
}
const AuthAuthorizationSignUpRequiredTypeID = 0x44747e9a
func (a AuthAuthorizationSignUpRequired ) construct () AuthAuthorizationClass { return &a }
var (
_ bin .Encoder = &AuthAuthorizationSignUpRequired {}
_ bin .Decoder = &AuthAuthorizationSignUpRequired {}
_ bin .BareEncoder = &AuthAuthorizationSignUpRequired {}
_ bin .BareDecoder = &AuthAuthorizationSignUpRequired {}
_ AuthAuthorizationClass = &AuthAuthorizationSignUpRequired {}
)
func (a *AuthAuthorizationSignUpRequired ) Zero () bool {
if a == nil {
return true
}
if !(a .Flags .Zero ()) {
return false
}
if !(a .TermsOfService .Zero ()) {
return false
}
return true
}
func (a *AuthAuthorizationSignUpRequired ) String () string {
if a == nil {
return "AuthAuthorizationSignUpRequired(nil)"
}
type Alias AuthAuthorizationSignUpRequired
return fmt .Sprintf ("AuthAuthorizationSignUpRequired%+v" , Alias (*a ))
}
func (a *AuthAuthorizationSignUpRequired ) FillFrom (from interface {
GetTermsOfService () (value HelpTermsOfService , ok bool )
}) {
if val , ok := from .GetTermsOfService (); ok {
a .TermsOfService = val
}
}
func (*AuthAuthorizationSignUpRequired ) TypeID () uint32 {
return AuthAuthorizationSignUpRequiredTypeID
}
func (*AuthAuthorizationSignUpRequired ) TypeName () string {
return "auth.authorizationSignUpRequired"
}
func (a *AuthAuthorizationSignUpRequired ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "auth.authorizationSignUpRequired" ,
ID : AuthAuthorizationSignUpRequiredTypeID ,
}
if a == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "TermsOfService" ,
SchemaName : "terms_of_service" ,
Null : !a .Flags .Has (0 ),
},
}
return typ
}
func (a *AuthAuthorizationSignUpRequired ) SetFlags () {
if !(a .TermsOfService .Zero ()) {
a .Flags .Set (0 )
}
}
func (a *AuthAuthorizationSignUpRequired ) Encode (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't encode auth.authorizationSignUpRequired#44747e9a as nil" )
}
b .PutID (AuthAuthorizationSignUpRequiredTypeID )
return a .EncodeBare (b )
}
func (a *AuthAuthorizationSignUpRequired ) EncodeBare (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't encode auth.authorizationSignUpRequired#44747e9a as nil" )
}
a .SetFlags ()
if err := a .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode auth.authorizationSignUpRequired#44747e9a: field flags: %w" , err )
}
if a .Flags .Has (0 ) {
if err := a .TermsOfService .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode auth.authorizationSignUpRequired#44747e9a: field terms_of_service: %w" , err )
}
}
return nil
}
func (a *AuthAuthorizationSignUpRequired ) Decode (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't decode auth.authorizationSignUpRequired#44747e9a to nil" )
}
if err := b .ConsumeID (AuthAuthorizationSignUpRequiredTypeID ); err != nil {
return fmt .Errorf ("unable to decode auth.authorizationSignUpRequired#44747e9a: %w" , err )
}
return a .DecodeBare (b )
}
func (a *AuthAuthorizationSignUpRequired ) DecodeBare (b *bin .Buffer ) error {
if a == nil {
return fmt .Errorf ("can't decode auth.authorizationSignUpRequired#44747e9a to nil" )
}
{
if err := a .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode auth.authorizationSignUpRequired#44747e9a: field flags: %w" , err )
}
}
if a .Flags .Has (0 ) {
if err := a .TermsOfService .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode auth.authorizationSignUpRequired#44747e9a: field terms_of_service: %w" , err )
}
}
return nil
}
func (a *AuthAuthorizationSignUpRequired ) SetTermsOfService (value HelpTermsOfService ) {
a .Flags .Set (0 )
a .TermsOfService = value
}
func (a *AuthAuthorizationSignUpRequired ) GetTermsOfService () (value HelpTermsOfService , ok bool ) {
if a == nil {
return
}
if !a .Flags .Has (0 ) {
return value , false
}
return a .TermsOfService , true
}
const AuthAuthorizationClassName = "auth.Authorization"
type AuthAuthorizationClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () AuthAuthorizationClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
}
func DecodeAuthAuthorization (buf *bin .Buffer ) (AuthAuthorizationClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case AuthAuthorizationTypeID :
v := AuthAuthorization {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode AuthAuthorizationClass: %w" , err )
}
return &v , nil
case AuthAuthorizationSignUpRequiredTypeID :
v := AuthAuthorizationSignUpRequired {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode AuthAuthorizationClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode AuthAuthorizationClass: %w" , bin .NewUnexpectedID (id ))
}
}
type AuthAuthorizationBox struct {
Authorization AuthAuthorizationClass
}
func (b *AuthAuthorizationBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode AuthAuthorizationBox to nil" )
}
v , err := DecodeAuthAuthorization (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .Authorization = v
return nil
}
func (b *AuthAuthorizationBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .Authorization == nil {
return fmt .Errorf ("unable to encode AuthAuthorizationClass as nil" )
}
return b .Authorization .Encode (buf )
}
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 .