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 MessagesCreateChatRequest struct {
Flags bin .Fields
Users []InputUserClass
Title string
TTLPeriod int
}
const MessagesCreateChatRequestTypeID = 0x34a818
var (
_ bin .Encoder = &MessagesCreateChatRequest {}
_ bin .Decoder = &MessagesCreateChatRequest {}
_ bin .BareEncoder = &MessagesCreateChatRequest {}
_ bin .BareDecoder = &MessagesCreateChatRequest {}
)
func (c *MessagesCreateChatRequest ) Zero () bool {
if c == nil {
return true
}
if !(c .Flags .Zero ()) {
return false
}
if !(c .Users == nil ) {
return false
}
if !(c .Title == "" ) {
return false
}
if !(c .TTLPeriod == 0 ) {
return false
}
return true
}
func (c *MessagesCreateChatRequest ) String () string {
if c == nil {
return "MessagesCreateChatRequest(nil)"
}
type Alias MessagesCreateChatRequest
return fmt .Sprintf ("MessagesCreateChatRequest%+v" , Alias (*c ))
}
func (c *MessagesCreateChatRequest ) FillFrom (from interface {
GetUsers () (value []InputUserClass )
GetTitle () (value string )
GetTTLPeriod () (value int , ok bool )
}) {
c .Users = from .GetUsers ()
c .Title = from .GetTitle ()
if val , ok := from .GetTTLPeriod (); ok {
c .TTLPeriod = val
}
}
func (*MessagesCreateChatRequest ) TypeID () uint32 {
return MessagesCreateChatRequestTypeID
}
func (*MessagesCreateChatRequest ) TypeName () string {
return "messages.createChat"
}
func (c *MessagesCreateChatRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.createChat" ,
ID : MessagesCreateChatRequestTypeID ,
}
if c == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Users" ,
SchemaName : "users" ,
},
{
Name : "Title" ,
SchemaName : "title" ,
},
{
Name : "TTLPeriod" ,
SchemaName : "ttl_period" ,
Null : !c .Flags .Has (0 ),
},
}
return typ
}
func (c *MessagesCreateChatRequest ) SetFlags () {
if !(c .TTLPeriod == 0 ) {
c .Flags .Set (0 )
}
}
func (c *MessagesCreateChatRequest ) Encode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode messages.createChat#34a818 as nil" )
}
b .PutID (MessagesCreateChatRequestTypeID )
return c .EncodeBare (b )
}
func (c *MessagesCreateChatRequest ) EncodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode messages.createChat#34a818 as nil" )
}
c .SetFlags ()
if err := c .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.createChat#34a818: field flags: %w" , err )
}
b .PutVectorHeader (len (c .Users ))
for idx , v := range c .Users {
if v == nil {
return fmt .Errorf ("unable to encode messages.createChat#34a818: field users element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.createChat#34a818: field users element with index %d: %w" , idx , err )
}
}
b .PutString (c .Title )
if c .Flags .Has (0 ) {
b .PutInt (c .TTLPeriod )
}
return nil
}
func (c *MessagesCreateChatRequest ) Decode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode messages.createChat#34a818 to nil" )
}
if err := b .ConsumeID (MessagesCreateChatRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.createChat#34a818: %w" , err )
}
return c .DecodeBare (b )
}
func (c *MessagesCreateChatRequest ) DecodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode messages.createChat#34a818 to nil" )
}
{
if err := c .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.createChat#34a818: field flags: %w" , err )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.createChat#34a818: field users: %w" , err )
}
if headerLen > 0 {
c .Users = make ([]InputUserClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeInputUser (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.createChat#34a818: field users: %w" , err )
}
c .Users = append (c .Users , value )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode messages.createChat#34a818: field title: %w" , err )
}
c .Title = value
}
if c .Flags .Has (0 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.createChat#34a818: field ttl_period: %w" , err )
}
c .TTLPeriod = value
}
return nil
}
func (c *MessagesCreateChatRequest ) GetUsers () (value []InputUserClass ) {
if c == nil {
return
}
return c .Users
}
func (c *MessagesCreateChatRequest ) GetTitle () (value string ) {
if c == nil {
return
}
return c .Title
}
func (c *MessagesCreateChatRequest ) SetTTLPeriod (value int ) {
c .Flags .Set (0 )
c .TTLPeriod = value
}
func (c *MessagesCreateChatRequest ) GetTTLPeriod () (value int , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (0 ) {
return value , false
}
return c .TTLPeriod , true
}
func (c *MessagesCreateChatRequest ) MapUsers () (value InputUserClassArray ) {
return InputUserClassArray (c .Users )
}
func (c *Client ) MessagesCreateChat (ctx context .Context , request *MessagesCreateChatRequest ) (UpdatesClass , error ) {
var result UpdatesBox
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return nil , err
}
return result .Updates , nil
}
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 .