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 Theme struct {
Flags bin .Fields
Creator bool
Default bool
ForChat bool
ID int64
AccessHash int64
Slug string
Title string
Document DocumentClass
Settings []ThemeSettings
Emoticon string
InstallsCount int
}
const ThemeTypeID = 0xa00e67d6
var (
_ bin .Encoder = &Theme {}
_ bin .Decoder = &Theme {}
_ bin .BareEncoder = &Theme {}
_ bin .BareDecoder = &Theme {}
)
func (t *Theme ) Zero () bool {
if t == nil {
return true
}
if !(t .Flags .Zero ()) {
return false
}
if !(t .Creator == false ) {
return false
}
if !(t .Default == false ) {
return false
}
if !(t .ForChat == false ) {
return false
}
if !(t .ID == 0 ) {
return false
}
if !(t .AccessHash == 0 ) {
return false
}
if !(t .Slug == "" ) {
return false
}
if !(t .Title == "" ) {
return false
}
if !(t .Document == nil ) {
return false
}
if !(t .Settings == nil ) {
return false
}
if !(t .Emoticon == "" ) {
return false
}
if !(t .InstallsCount == 0 ) {
return false
}
return true
}
func (t *Theme ) String () string {
if t == nil {
return "Theme(nil)"
}
type Alias Theme
return fmt .Sprintf ("Theme%+v" , Alias (*t ))
}
func (t *Theme ) FillFrom (from interface {
GetCreator () (value bool )
GetDefault () (value bool )
GetForChat () (value bool )
GetID () (value int64 )
GetAccessHash () (value int64 )
GetSlug () (value string )
GetTitle () (value string )
GetDocument () (value DocumentClass , ok bool )
GetSettings () (value []ThemeSettings , ok bool )
GetEmoticon () (value string , ok bool )
GetInstallsCount () (value int , ok bool )
}) {
t .Creator = from .GetCreator ()
t .Default = from .GetDefault ()
t .ForChat = from .GetForChat ()
t .ID = from .GetID ()
t .AccessHash = from .GetAccessHash ()
t .Slug = from .GetSlug ()
t .Title = from .GetTitle ()
if val , ok := from .GetDocument (); ok {
t .Document = val
}
if val , ok := from .GetSettings (); ok {
t .Settings = val
}
if val , ok := from .GetEmoticon (); ok {
t .Emoticon = val
}
if val , ok := from .GetInstallsCount (); ok {
t .InstallsCount = val
}
}
func (*Theme ) TypeID () uint32 {
return ThemeTypeID
}
func (*Theme ) TypeName () string {
return "theme"
}
func (t *Theme ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "theme" ,
ID : ThemeTypeID ,
}
if t == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Creator" ,
SchemaName : "creator" ,
Null : !t .Flags .Has (0 ),
},
{
Name : "Default" ,
SchemaName : "default" ,
Null : !t .Flags .Has (1 ),
},
{
Name : "ForChat" ,
SchemaName : "for_chat" ,
Null : !t .Flags .Has (5 ),
},
{
Name : "ID" ,
SchemaName : "id" ,
},
{
Name : "AccessHash" ,
SchemaName : "access_hash" ,
},
{
Name : "Slug" ,
SchemaName : "slug" ,
},
{
Name : "Title" ,
SchemaName : "title" ,
},
{
Name : "Document" ,
SchemaName : "document" ,
Null : !t .Flags .Has (2 ),
},
{
Name : "Settings" ,
SchemaName : "settings" ,
Null : !t .Flags .Has (3 ),
},
{
Name : "Emoticon" ,
SchemaName : "emoticon" ,
Null : !t .Flags .Has (6 ),
},
{
Name : "InstallsCount" ,
SchemaName : "installs_count" ,
Null : !t .Flags .Has (4 ),
},
}
return typ
}
func (t *Theme ) SetFlags () {
if !(t .Creator == false ) {
t .Flags .Set (0 )
}
if !(t .Default == false ) {
t .Flags .Set (1 )
}
if !(t .ForChat == false ) {
t .Flags .Set (5 )
}
if !(t .Document == nil ) {
t .Flags .Set (2 )
}
if !(t .Settings == nil ) {
t .Flags .Set (3 )
}
if !(t .Emoticon == "" ) {
t .Flags .Set (6 )
}
if !(t .InstallsCount == 0 ) {
t .Flags .Set (4 )
}
}
func (t *Theme ) Encode (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't encode theme#a00e67d6 as nil" )
}
b .PutID (ThemeTypeID )
return t .EncodeBare (b )
}
func (t *Theme ) EncodeBare (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't encode theme#a00e67d6 as nil" )
}
t .SetFlags ()
if err := t .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode theme#a00e67d6: field flags: %w" , err )
}
b .PutLong (t .ID )
b .PutLong (t .AccessHash )
b .PutString (t .Slug )
b .PutString (t .Title )
if t .Flags .Has (2 ) {
if t .Document == nil {
return fmt .Errorf ("unable to encode theme#a00e67d6: field document is nil" )
}
if err := t .Document .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode theme#a00e67d6: field document: %w" , err )
}
}
if t .Flags .Has (3 ) {
b .PutVectorHeader (len (t .Settings ))
for idx , v := range t .Settings {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode theme#a00e67d6: field settings element with index %d: %w" , idx , err )
}
}
}
if t .Flags .Has (6 ) {
b .PutString (t .Emoticon )
}
if t .Flags .Has (4 ) {
b .PutInt (t .InstallsCount )
}
return nil
}
func (t *Theme ) Decode (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't decode theme#a00e67d6 to nil" )
}
if err := b .ConsumeID (ThemeTypeID ); err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: %w" , err )
}
return t .DecodeBare (b )
}
func (t *Theme ) DecodeBare (b *bin .Buffer ) error {
if t == nil {
return fmt .Errorf ("can't decode theme#a00e67d6 to nil" )
}
{
if err := t .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field flags: %w" , err )
}
}
t .Creator = t .Flags .Has (0 )
t .Default = t .Flags .Has (1 )
t .ForChat = t .Flags .Has (5 )
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field id: %w" , err )
}
t .ID = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field access_hash: %w" , err )
}
t .AccessHash = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field slug: %w" , err )
}
t .Slug = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field title: %w" , err )
}
t .Title = value
}
if t .Flags .Has (2 ) {
value , err := DecodeDocument (b )
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field document: %w" , err )
}
t .Document = value
}
if t .Flags .Has (3 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field settings: %w" , err )
}
if headerLen > 0 {
t .Settings = make ([]ThemeSettings , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value ThemeSettings
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field settings: %w" , err )
}
t .Settings = append (t .Settings , value )
}
}
if t .Flags .Has (6 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field emoticon: %w" , err )
}
t .Emoticon = value
}
if t .Flags .Has (4 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode theme#a00e67d6: field installs_count: %w" , err )
}
t .InstallsCount = value
}
return nil
}
func (t *Theme ) SetCreator (value bool ) {
if value {
t .Flags .Set (0 )
t .Creator = true
} else {
t .Flags .Unset (0 )
t .Creator = false
}
}
func (t *Theme ) GetCreator () (value bool ) {
if t == nil {
return
}
return t .Flags .Has (0 )
}
func (t *Theme ) SetDefault (value bool ) {
if value {
t .Flags .Set (1 )
t .Default = true
} else {
t .Flags .Unset (1 )
t .Default = false
}
}
func (t *Theme ) GetDefault () (value bool ) {
if t == nil {
return
}
return t .Flags .Has (1 )
}
func (t *Theme ) SetForChat (value bool ) {
if value {
t .Flags .Set (5 )
t .ForChat = true
} else {
t .Flags .Unset (5 )
t .ForChat = false
}
}
func (t *Theme ) GetForChat () (value bool ) {
if t == nil {
return
}
return t .Flags .Has (5 )
}
func (t *Theme ) GetID () (value int64 ) {
if t == nil {
return
}
return t .ID
}
func (t *Theme ) GetAccessHash () (value int64 ) {
if t == nil {
return
}
return t .AccessHash
}
func (t *Theme ) GetSlug () (value string ) {
if t == nil {
return
}
return t .Slug
}
func (t *Theme ) GetTitle () (value string ) {
if t == nil {
return
}
return t .Title
}
func (t *Theme ) SetDocument (value DocumentClass ) {
t .Flags .Set (2 )
t .Document = value
}
func (t *Theme ) GetDocument () (value DocumentClass , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (2 ) {
return value , false
}
return t .Document , true
}
func (t *Theme ) SetSettings (value []ThemeSettings ) {
t .Flags .Set (3 )
t .Settings = value
}
func (t *Theme ) GetSettings () (value []ThemeSettings , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (3 ) {
return value , false
}
return t .Settings , true
}
func (t *Theme ) SetEmoticon (value string ) {
t .Flags .Set (6 )
t .Emoticon = value
}
func (t *Theme ) GetEmoticon () (value string , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (6 ) {
return value , false
}
return t .Emoticon , true
}
func (t *Theme ) SetInstallsCount (value int ) {
t .Flags .Set (4 )
t .InstallsCount = value
}
func (t *Theme ) GetInstallsCount () (value int , ok bool ) {
if t == nil {
return
}
if !t .Flags .Has (4 ) {
return value , false
}
return t .InstallsCount , true
}
func (t *Theme ) GetDocumentAsNotEmpty () (*Document , bool ) {
if value , ok := t .GetDocument (); ok {
return value .AsNotEmpty ()
}
return nil , false
}
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 .