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 Username struct {
Flags bin .Fields
Editable bool
Active bool
Username string
}
const UsernameTypeID = 0xb4073647
var (
_ bin .Encoder = &Username {}
_ bin .Decoder = &Username {}
_ bin .BareEncoder = &Username {}
_ bin .BareDecoder = &Username {}
)
func (u *Username ) Zero () bool {
if u == nil {
return true
}
if !(u .Flags .Zero ()) {
return false
}
if !(u .Editable == false ) {
return false
}
if !(u .Active == false ) {
return false
}
if !(u .Username == "" ) {
return false
}
return true
}
func (u *Username ) String () string {
if u == nil {
return "Username(nil)"
}
type Alias Username
return fmt .Sprintf ("Username%+v" , Alias (*u ))
}
func (u *Username ) FillFrom (from interface {
GetEditable () (value bool )
GetActive () (value bool )
GetUsername () (value string )
}) {
u .Editable = from .GetEditable ()
u .Active = from .GetActive ()
u .Username = from .GetUsername ()
}
func (*Username ) TypeID () uint32 {
return UsernameTypeID
}
func (*Username ) TypeName () string {
return "username"
}
func (u *Username ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "username" ,
ID : UsernameTypeID ,
}
if u == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Editable" ,
SchemaName : "editable" ,
Null : !u .Flags .Has (0 ),
},
{
Name : "Active" ,
SchemaName : "active" ,
Null : !u .Flags .Has (1 ),
},
{
Name : "Username" ,
SchemaName : "username" ,
},
}
return typ
}
func (u *Username ) SetFlags () {
if !(u .Editable == false ) {
u .Flags .Set (0 )
}
if !(u .Active == false ) {
u .Flags .Set (1 )
}
}
func (u *Username ) Encode (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't encode username#b4073647 as nil" )
}
b .PutID (UsernameTypeID )
return u .EncodeBare (b )
}
func (u *Username ) EncodeBare (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't encode username#b4073647 as nil" )
}
u .SetFlags ()
if err := u .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode username#b4073647: field flags: %w" , err )
}
b .PutString (u .Username )
return nil
}
func (u *Username ) Decode (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't decode username#b4073647 to nil" )
}
if err := b .ConsumeID (UsernameTypeID ); err != nil {
return fmt .Errorf ("unable to decode username#b4073647: %w" , err )
}
return u .DecodeBare (b )
}
func (u *Username ) DecodeBare (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't decode username#b4073647 to nil" )
}
{
if err := u .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode username#b4073647: field flags: %w" , err )
}
}
u .Editable = u .Flags .Has (0 )
u .Active = u .Flags .Has (1 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode username#b4073647: field username: %w" , err )
}
u .Username = value
}
return nil
}
func (u *Username ) SetEditable (value bool ) {
if value {
u .Flags .Set (0 )
u .Editable = true
} else {
u .Flags .Unset (0 )
u .Editable = false
}
}
func (u *Username ) GetEditable () (value bool ) {
if u == nil {
return
}
return u .Flags .Has (0 )
}
func (u *Username ) SetActive (value bool ) {
if value {
u .Flags .Set (1 )
u .Active = true
} else {
u .Flags .Unset (1 )
u .Active = false
}
}
func (u *Username ) GetActive () (value bool ) {
if u == nil {
return
}
return u .Flags .Has (1 )
}
func (u *Username ) GetUsername () (value string ) {
if u == nil {
return
}
return u .Username
}
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 .