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 MessagesSponsoredMessages struct {
Flags bin .Fields
PostsBetween int
Messages []SponsoredMessage
Chats []ChatClass
Users []UserClass
}
const MessagesSponsoredMessagesTypeID = 0xc9ee1d87
func (s MessagesSponsoredMessages ) construct () MessagesSponsoredMessagesClass { return &s }
var (
_ bin .Encoder = &MessagesSponsoredMessages {}
_ bin .Decoder = &MessagesSponsoredMessages {}
_ bin .BareEncoder = &MessagesSponsoredMessages {}
_ bin .BareDecoder = &MessagesSponsoredMessages {}
_ MessagesSponsoredMessagesClass = &MessagesSponsoredMessages {}
)
func (s *MessagesSponsoredMessages ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .PostsBetween == 0 ) {
return false
}
if !(s .Messages == nil ) {
return false
}
if !(s .Chats == nil ) {
return false
}
if !(s .Users == nil ) {
return false
}
return true
}
func (s *MessagesSponsoredMessages ) String () string {
if s == nil {
return "MessagesSponsoredMessages(nil)"
}
type Alias MessagesSponsoredMessages
return fmt .Sprintf ("MessagesSponsoredMessages%+v" , Alias (*s ))
}
func (s *MessagesSponsoredMessages ) FillFrom (from interface {
GetPostsBetween () (value int , ok bool )
GetMessages () (value []SponsoredMessage )
GetChats () (value []ChatClass )
GetUsers () (value []UserClass )
}) {
if val , ok := from .GetPostsBetween (); ok {
s .PostsBetween = val
}
s .Messages = from .GetMessages ()
s .Chats = from .GetChats ()
s .Users = from .GetUsers ()
}
func (*MessagesSponsoredMessages ) TypeID () uint32 {
return MessagesSponsoredMessagesTypeID
}
func (*MessagesSponsoredMessages ) TypeName () string {
return "messages.sponsoredMessages"
}
func (s *MessagesSponsoredMessages ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.sponsoredMessages" ,
ID : MessagesSponsoredMessagesTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "PostsBetween" ,
SchemaName : "posts_between" ,
Null : !s .Flags .Has (0 ),
},
{
Name : "Messages" ,
SchemaName : "messages" ,
},
{
Name : "Chats" ,
SchemaName : "chats" ,
},
{
Name : "Users" ,
SchemaName : "users" ,
},
}
return typ
}
func (s *MessagesSponsoredMessages ) SetFlags () {
if !(s .PostsBetween == 0 ) {
s .Flags .Set (0 )
}
}
func (s *MessagesSponsoredMessages ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.sponsoredMessages#c9ee1d87 as nil" )
}
b .PutID (MessagesSponsoredMessagesTypeID )
return s .EncodeBare (b )
}
func (s *MessagesSponsoredMessages ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.sponsoredMessages#c9ee1d87 as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.sponsoredMessages#c9ee1d87: field flags: %w" , err )
}
if s .Flags .Has (0 ) {
b .PutInt (s .PostsBetween )
}
b .PutVectorHeader (len (s .Messages ))
for idx , v := range s .Messages {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.sponsoredMessages#c9ee1d87: field messages element with index %d: %w" , idx , err )
}
}
b .PutVectorHeader (len (s .Chats ))
for idx , v := range s .Chats {
if v == nil {
return fmt .Errorf ("unable to encode messages.sponsoredMessages#c9ee1d87: field chats element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.sponsoredMessages#c9ee1d87: field chats element with index %d: %w" , idx , err )
}
}
b .PutVectorHeader (len (s .Users ))
for idx , v := range s .Users {
if v == nil {
return fmt .Errorf ("unable to encode messages.sponsoredMessages#c9ee1d87: field users element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.sponsoredMessages#c9ee1d87: field users element with index %d: %w" , idx , err )
}
}
return nil
}
func (s *MessagesSponsoredMessages ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.sponsoredMessages#c9ee1d87 to nil" )
}
if err := b .ConsumeID (MessagesSponsoredMessagesTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: %w" , err )
}
return s .DecodeBare (b )
}
func (s *MessagesSponsoredMessages ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.sponsoredMessages#c9ee1d87 to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field flags: %w" , err )
}
}
if s .Flags .Has (0 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field posts_between: %w" , err )
}
s .PostsBetween = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field messages: %w" , err )
}
if headerLen > 0 {
s .Messages = make ([]SponsoredMessage , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value SponsoredMessage
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field messages: %w" , err )
}
s .Messages = append (s .Messages , value )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field chats: %w" , err )
}
if headerLen > 0 {
s .Chats = make ([]ChatClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeChat (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field chats: %w" , err )
}
s .Chats = append (s .Chats , value )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field users: %w" , err )
}
if headerLen > 0 {
s .Users = make ([]UserClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeUser (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessages#c9ee1d87: field users: %w" , err )
}
s .Users = append (s .Users , value )
}
}
return nil
}
func (s *MessagesSponsoredMessages ) SetPostsBetween (value int ) {
s .Flags .Set (0 )
s .PostsBetween = value
}
func (s *MessagesSponsoredMessages ) GetPostsBetween () (value int , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (0 ) {
return value , false
}
return s .PostsBetween , true
}
func (s *MessagesSponsoredMessages ) GetMessages () (value []SponsoredMessage ) {
if s == nil {
return
}
return s .Messages
}
func (s *MessagesSponsoredMessages ) GetChats () (value []ChatClass ) {
if s == nil {
return
}
return s .Chats
}
func (s *MessagesSponsoredMessages ) GetUsers () (value []UserClass ) {
if s == nil {
return
}
return s .Users
}
func (s *MessagesSponsoredMessages ) MapChats () (value ChatClassArray ) {
return ChatClassArray (s .Chats )
}
func (s *MessagesSponsoredMessages ) MapUsers () (value UserClassArray ) {
return UserClassArray (s .Users )
}
type MessagesSponsoredMessagesEmpty struct {
}
const MessagesSponsoredMessagesEmptyTypeID = 0x1839490f
func (s MessagesSponsoredMessagesEmpty ) construct () MessagesSponsoredMessagesClass { return &s }
var (
_ bin .Encoder = &MessagesSponsoredMessagesEmpty {}
_ bin .Decoder = &MessagesSponsoredMessagesEmpty {}
_ bin .BareEncoder = &MessagesSponsoredMessagesEmpty {}
_ bin .BareDecoder = &MessagesSponsoredMessagesEmpty {}
_ MessagesSponsoredMessagesClass = &MessagesSponsoredMessagesEmpty {}
)
func (s *MessagesSponsoredMessagesEmpty ) Zero () bool {
if s == nil {
return true
}
return true
}
func (s *MessagesSponsoredMessagesEmpty ) String () string {
if s == nil {
return "MessagesSponsoredMessagesEmpty(nil)"
}
type Alias MessagesSponsoredMessagesEmpty
return fmt .Sprintf ("MessagesSponsoredMessagesEmpty%+v" , Alias (*s ))
}
func (*MessagesSponsoredMessagesEmpty ) TypeID () uint32 {
return MessagesSponsoredMessagesEmptyTypeID
}
func (*MessagesSponsoredMessagesEmpty ) TypeName () string {
return "messages.sponsoredMessagesEmpty"
}
func (s *MessagesSponsoredMessagesEmpty ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.sponsoredMessagesEmpty" ,
ID : MessagesSponsoredMessagesEmptyTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {}
return typ
}
func (s *MessagesSponsoredMessagesEmpty ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.sponsoredMessagesEmpty#1839490f as nil" )
}
b .PutID (MessagesSponsoredMessagesEmptyTypeID )
return s .EncodeBare (b )
}
func (s *MessagesSponsoredMessagesEmpty ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.sponsoredMessagesEmpty#1839490f as nil" )
}
return nil
}
func (s *MessagesSponsoredMessagesEmpty ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.sponsoredMessagesEmpty#1839490f to nil" )
}
if err := b .ConsumeID (MessagesSponsoredMessagesEmptyTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.sponsoredMessagesEmpty#1839490f: %w" , err )
}
return s .DecodeBare (b )
}
func (s *MessagesSponsoredMessagesEmpty ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.sponsoredMessagesEmpty#1839490f to nil" )
}
return nil
}
const MessagesSponsoredMessagesClassName = "messages.SponsoredMessages"
type MessagesSponsoredMessagesClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () MessagesSponsoredMessagesClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
AsNotEmpty () (*MessagesSponsoredMessages , bool )
}
func (s *MessagesSponsoredMessages ) AsNotEmpty () (*MessagesSponsoredMessages , bool ) {
return s , true
}
func (s *MessagesSponsoredMessagesEmpty ) AsNotEmpty () (*MessagesSponsoredMessages , bool ) {
return nil , false
}
func DecodeMessagesSponsoredMessages (buf *bin .Buffer ) (MessagesSponsoredMessagesClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case MessagesSponsoredMessagesTypeID :
v := MessagesSponsoredMessages {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode MessagesSponsoredMessagesClass: %w" , err )
}
return &v , nil
case MessagesSponsoredMessagesEmptyTypeID :
v := MessagesSponsoredMessagesEmpty {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode MessagesSponsoredMessagesClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode MessagesSponsoredMessagesClass: %w" , bin .NewUnexpectedID (id ))
}
}
type MessagesSponsoredMessagesBox struct {
SponsoredMessages MessagesSponsoredMessagesClass
}
func (b *MessagesSponsoredMessagesBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode MessagesSponsoredMessagesBox to nil" )
}
v , err := DecodeMessagesSponsoredMessages (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .SponsoredMessages = v
return nil
}
func (b *MessagesSponsoredMessagesBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .SponsoredMessages == nil {
return fmt .Errorf ("unable to encode MessagesSponsoredMessagesClass as nil" )
}
return b .SponsoredMessages .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 .