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 PollResults struct {
Flags bin .Fields
Min bool
Results []PollAnswerVoters
TotalVoters int
RecentVoters []PeerClass
Solution string
SolutionEntities []MessageEntityClass
}
const PollResultsTypeID = 0x7adf2420
var (
_ bin .Encoder = &PollResults {}
_ bin .Decoder = &PollResults {}
_ bin .BareEncoder = &PollResults {}
_ bin .BareDecoder = &PollResults {}
)
func (p *PollResults ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .Min == false ) {
return false
}
if !(p .Results == nil ) {
return false
}
if !(p .TotalVoters == 0 ) {
return false
}
if !(p .RecentVoters == nil ) {
return false
}
if !(p .Solution == "" ) {
return false
}
if !(p .SolutionEntities == nil ) {
return false
}
return true
}
func (p *PollResults ) String () string {
if p == nil {
return "PollResults(nil)"
}
type Alias PollResults
return fmt .Sprintf ("PollResults%+v" , Alias (*p ))
}
func (p *PollResults ) FillFrom (from interface {
GetMin () (value bool )
GetResults () (value []PollAnswerVoters , ok bool )
GetTotalVoters () (value int , ok bool )
GetRecentVoters () (value []PeerClass , ok bool )
GetSolution () (value string , ok bool )
GetSolutionEntities () (value []MessageEntityClass , ok bool )
}) {
p .Min = from .GetMin ()
if val , ok := from .GetResults (); ok {
p .Results = val
}
if val , ok := from .GetTotalVoters (); ok {
p .TotalVoters = val
}
if val , ok := from .GetRecentVoters (); ok {
p .RecentVoters = val
}
if val , ok := from .GetSolution (); ok {
p .Solution = val
}
if val , ok := from .GetSolutionEntities (); ok {
p .SolutionEntities = val
}
}
func (*PollResults ) TypeID () uint32 {
return PollResultsTypeID
}
func (*PollResults ) TypeName () string {
return "pollResults"
}
func (p *PollResults ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "pollResults" ,
ID : PollResultsTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Min" ,
SchemaName : "min" ,
Null : !p .Flags .Has (0 ),
},
{
Name : "Results" ,
SchemaName : "results" ,
Null : !p .Flags .Has (1 ),
},
{
Name : "TotalVoters" ,
SchemaName : "total_voters" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "RecentVoters" ,
SchemaName : "recent_voters" ,
Null : !p .Flags .Has (3 ),
},
{
Name : "Solution" ,
SchemaName : "solution" ,
Null : !p .Flags .Has (4 ),
},
{
Name : "SolutionEntities" ,
SchemaName : "solution_entities" ,
Null : !p .Flags .Has (4 ),
},
}
return typ
}
func (p *PollResults ) SetFlags () {
if !(p .Min == false ) {
p .Flags .Set (0 )
}
if !(p .Results == nil ) {
p .Flags .Set (1 )
}
if !(p .TotalVoters == 0 ) {
p .Flags .Set (2 )
}
if !(p .RecentVoters == nil ) {
p .Flags .Set (3 )
}
if !(p .Solution == "" ) {
p .Flags .Set (4 )
}
if !(p .SolutionEntities == nil ) {
p .Flags .Set (4 )
}
}
func (p *PollResults ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode pollResults#7adf2420 as nil" )
}
b .PutID (PollResultsTypeID )
return p .EncodeBare (b )
}
func (p *PollResults ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode pollResults#7adf2420 as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pollResults#7adf2420: field flags: %w" , err )
}
if p .Flags .Has (1 ) {
b .PutVectorHeader (len (p .Results ))
for idx , v := range p .Results {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pollResults#7adf2420: field results element with index %d: %w" , idx , err )
}
}
}
if p .Flags .Has (2 ) {
b .PutInt (p .TotalVoters )
}
if p .Flags .Has (3 ) {
b .PutVectorHeader (len (p .RecentVoters ))
for idx , v := range p .RecentVoters {
if v == nil {
return fmt .Errorf ("unable to encode pollResults#7adf2420: field recent_voters element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pollResults#7adf2420: field recent_voters element with index %d: %w" , idx , err )
}
}
}
if p .Flags .Has (4 ) {
b .PutString (p .Solution )
}
if p .Flags .Has (4 ) {
b .PutVectorHeader (len (p .SolutionEntities ))
for idx , v := range p .SolutionEntities {
if v == nil {
return fmt .Errorf ("unable to encode pollResults#7adf2420: field solution_entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode pollResults#7adf2420: field solution_entities element with index %d: %w" , idx , err )
}
}
}
return nil
}
func (p *PollResults ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode pollResults#7adf2420 to nil" )
}
if err := b .ConsumeID (PollResultsTypeID ); err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PollResults ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode pollResults#7adf2420 to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field flags: %w" , err )
}
}
p .Min = p .Flags .Has (0 )
if p .Flags .Has (1 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field results: %w" , err )
}
if headerLen > 0 {
p .Results = make ([]PollAnswerVoters , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value PollAnswerVoters
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field results: %w" , err )
}
p .Results = append (p .Results , value )
}
}
if p .Flags .Has (2 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field total_voters: %w" , err )
}
p .TotalVoters = value
}
if p .Flags .Has (3 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field recent_voters: %w" , err )
}
if headerLen > 0 {
p .RecentVoters = make ([]PeerClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodePeer (b )
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field recent_voters: %w" , err )
}
p .RecentVoters = append (p .RecentVoters , value )
}
}
if p .Flags .Has (4 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field solution: %w" , err )
}
p .Solution = value
}
if p .Flags .Has (4 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field solution_entities: %w" , err )
}
if headerLen > 0 {
p .SolutionEntities = make ([]MessageEntityClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeMessageEntity (b )
if err != nil {
return fmt .Errorf ("unable to decode pollResults#7adf2420: field solution_entities: %w" , err )
}
p .SolutionEntities = append (p .SolutionEntities , value )
}
}
return nil
}
func (p *PollResults ) SetMin (value bool ) {
if value {
p .Flags .Set (0 )
p .Min = true
} else {
p .Flags .Unset (0 )
p .Min = false
}
}
func (p *PollResults ) GetMin () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (0 )
}
func (p *PollResults ) SetResults (value []PollAnswerVoters ) {
p .Flags .Set (1 )
p .Results = value
}
func (p *PollResults ) GetResults () (value []PollAnswerVoters , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (1 ) {
return value , false
}
return p .Results , true
}
func (p *PollResults ) SetTotalVoters (value int ) {
p .Flags .Set (2 )
p .TotalVoters = value
}
func (p *PollResults ) GetTotalVoters () (value int , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (2 ) {
return value , false
}
return p .TotalVoters , true
}
func (p *PollResults ) SetRecentVoters (value []PeerClass ) {
p .Flags .Set (3 )
p .RecentVoters = value
}
func (p *PollResults ) GetRecentVoters () (value []PeerClass , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (3 ) {
return value , false
}
return p .RecentVoters , true
}
func (p *PollResults ) SetSolution (value string ) {
p .Flags .Set (4 )
p .Solution = value
}
func (p *PollResults ) GetSolution () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (4 ) {
return value , false
}
return p .Solution , true
}
func (p *PollResults ) SetSolutionEntities (value []MessageEntityClass ) {
p .Flags .Set (4 )
p .SolutionEntities = value
}
func (p *PollResults ) GetSolutionEntities () (value []MessageEntityClass , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (4 ) {
return value , false
}
return p .SolutionEntities , true
}
func (p *PollResults ) MapRecentVoters () (value PeerClassArray , ok bool ) {
if !p .Flags .Has (3 ) {
return value , false
}
return PeerClassArray (p .RecentVoters ), true
}
func (p *PollResults ) MapSolutionEntities () (value MessageEntityClassArray , ok bool ) {
if !p .Flags .Has (4 ) {
return value , false
}
return MessageEntityClassArray (p .SolutionEntities ), 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 .