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 DraftMessageEmpty struct {
Flags bin .Fields
Date int
}
const DraftMessageEmptyTypeID = 0x1b0c841a
func (d DraftMessageEmpty ) construct () DraftMessageClass { return &d }
var (
_ bin .Encoder = &DraftMessageEmpty {}
_ bin .Decoder = &DraftMessageEmpty {}
_ bin .BareEncoder = &DraftMessageEmpty {}
_ bin .BareDecoder = &DraftMessageEmpty {}
_ DraftMessageClass = &DraftMessageEmpty {}
)
func (d *DraftMessageEmpty ) Zero () bool {
if d == nil {
return true
}
if !(d .Flags .Zero ()) {
return false
}
if !(d .Date == 0 ) {
return false
}
return true
}
func (d *DraftMessageEmpty ) String () string {
if d == nil {
return "DraftMessageEmpty(nil)"
}
type Alias DraftMessageEmpty
return fmt .Sprintf ("DraftMessageEmpty%+v" , Alias (*d ))
}
func (d *DraftMessageEmpty ) FillFrom (from interface {
GetDate () (value int , ok bool )
}) {
if val , ok := from .GetDate (); ok {
d .Date = val
}
}
func (*DraftMessageEmpty ) TypeID () uint32 {
return DraftMessageEmptyTypeID
}
func (*DraftMessageEmpty ) TypeName () string {
return "draftMessageEmpty"
}
func (d *DraftMessageEmpty ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "draftMessageEmpty" ,
ID : DraftMessageEmptyTypeID ,
}
if d == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Date" ,
SchemaName : "date" ,
Null : !d .Flags .Has (0 ),
},
}
return typ
}
func (d *DraftMessageEmpty ) SetFlags () {
if !(d .Date == 0 ) {
d .Flags .Set (0 )
}
}
func (d *DraftMessageEmpty ) Encode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode draftMessageEmpty#1b0c841a as nil" )
}
b .PutID (DraftMessageEmptyTypeID )
return d .EncodeBare (b )
}
func (d *DraftMessageEmpty ) EncodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode draftMessageEmpty#1b0c841a as nil" )
}
d .SetFlags ()
if err := d .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode draftMessageEmpty#1b0c841a: field flags: %w" , err )
}
if d .Flags .Has (0 ) {
b .PutInt (d .Date )
}
return nil
}
func (d *DraftMessageEmpty ) Decode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode draftMessageEmpty#1b0c841a to nil" )
}
if err := b .ConsumeID (DraftMessageEmptyTypeID ); err != nil {
return fmt .Errorf ("unable to decode draftMessageEmpty#1b0c841a: %w" , err )
}
return d .DecodeBare (b )
}
func (d *DraftMessageEmpty ) DecodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode draftMessageEmpty#1b0c841a to nil" )
}
{
if err := d .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode draftMessageEmpty#1b0c841a: field flags: %w" , err )
}
}
if d .Flags .Has (0 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode draftMessageEmpty#1b0c841a: field date: %w" , err )
}
d .Date = value
}
return nil
}
func (d *DraftMessageEmpty ) SetDate (value int ) {
d .Flags .Set (0 )
d .Date = value
}
func (d *DraftMessageEmpty ) GetDate () (value int , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (0 ) {
return value , false
}
return d .Date , true
}
type DraftMessage struct {
Flags bin .Fields
NoWebpage bool
InvertMedia bool
ReplyTo InputReplyToClass
Message string
Entities []MessageEntityClass
Media InputMediaClass
Date int
}
const DraftMessageTypeID = 0x3fccf7ef
func (d DraftMessage ) construct () DraftMessageClass { return &d }
var (
_ bin .Encoder = &DraftMessage {}
_ bin .Decoder = &DraftMessage {}
_ bin .BareEncoder = &DraftMessage {}
_ bin .BareDecoder = &DraftMessage {}
_ DraftMessageClass = &DraftMessage {}
)
func (d *DraftMessage ) Zero () bool {
if d == nil {
return true
}
if !(d .Flags .Zero ()) {
return false
}
if !(d .NoWebpage == false ) {
return false
}
if !(d .InvertMedia == false ) {
return false
}
if !(d .ReplyTo == nil ) {
return false
}
if !(d .Message == "" ) {
return false
}
if !(d .Entities == nil ) {
return false
}
if !(d .Media == nil ) {
return false
}
if !(d .Date == 0 ) {
return false
}
return true
}
func (d *DraftMessage ) String () string {
if d == nil {
return "DraftMessage(nil)"
}
type Alias DraftMessage
return fmt .Sprintf ("DraftMessage%+v" , Alias (*d ))
}
func (d *DraftMessage ) FillFrom (from interface {
GetNoWebpage () (value bool )
GetInvertMedia () (value bool )
GetReplyTo () (value InputReplyToClass , ok bool )
GetMessage () (value string )
GetEntities () (value []MessageEntityClass , ok bool )
GetMedia () (value InputMediaClass , ok bool )
GetDate () (value int )
}) {
d .NoWebpage = from .GetNoWebpage ()
d .InvertMedia = from .GetInvertMedia ()
if val , ok := from .GetReplyTo (); ok {
d .ReplyTo = val
}
d .Message = from .GetMessage ()
if val , ok := from .GetEntities (); ok {
d .Entities = val
}
if val , ok := from .GetMedia (); ok {
d .Media = val
}
d .Date = from .GetDate ()
}
func (*DraftMessage ) TypeID () uint32 {
return DraftMessageTypeID
}
func (*DraftMessage ) TypeName () string {
return "draftMessage"
}
func (d *DraftMessage ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "draftMessage" ,
ID : DraftMessageTypeID ,
}
if d == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "NoWebpage" ,
SchemaName : "no_webpage" ,
Null : !d .Flags .Has (1 ),
},
{
Name : "InvertMedia" ,
SchemaName : "invert_media" ,
Null : !d .Flags .Has (6 ),
},
{
Name : "ReplyTo" ,
SchemaName : "reply_to" ,
Null : !d .Flags .Has (4 ),
},
{
Name : "Message" ,
SchemaName : "message" ,
},
{
Name : "Entities" ,
SchemaName : "entities" ,
Null : !d .Flags .Has (3 ),
},
{
Name : "Media" ,
SchemaName : "media" ,
Null : !d .Flags .Has (5 ),
},
{
Name : "Date" ,
SchemaName : "date" ,
},
}
return typ
}
func (d *DraftMessage ) SetFlags () {
if !(d .NoWebpage == false ) {
d .Flags .Set (1 )
}
if !(d .InvertMedia == false ) {
d .Flags .Set (6 )
}
if !(d .ReplyTo == nil ) {
d .Flags .Set (4 )
}
if !(d .Entities == nil ) {
d .Flags .Set (3 )
}
if !(d .Media == nil ) {
d .Flags .Set (5 )
}
}
func (d *DraftMessage ) Encode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode draftMessage#3fccf7ef as nil" )
}
b .PutID (DraftMessageTypeID )
return d .EncodeBare (b )
}
func (d *DraftMessage ) EncodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't encode draftMessage#3fccf7ef as nil" )
}
d .SetFlags ()
if err := d .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field flags: %w" , err )
}
if d .Flags .Has (4 ) {
if d .ReplyTo == nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field reply_to is nil" )
}
if err := d .ReplyTo .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field reply_to: %w" , err )
}
}
b .PutString (d .Message )
if d .Flags .Has (3 ) {
b .PutVectorHeader (len (d .Entities ))
for idx , v := range d .Entities {
if v == nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field entities element with index %d: %w" , idx , err )
}
}
}
if d .Flags .Has (5 ) {
if d .Media == nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field media is nil" )
}
if err := d .Media .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode draftMessage#3fccf7ef: field media: %w" , err )
}
}
b .PutInt (d .Date )
return nil
}
func (d *DraftMessage ) Decode (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode draftMessage#3fccf7ef to nil" )
}
if err := b .ConsumeID (DraftMessageTypeID ); err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: %w" , err )
}
return d .DecodeBare (b )
}
func (d *DraftMessage ) DecodeBare (b *bin .Buffer ) error {
if d == nil {
return fmt .Errorf ("can't decode draftMessage#3fccf7ef to nil" )
}
{
if err := d .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: field flags: %w" , err )
}
}
d .NoWebpage = d .Flags .Has (1 )
d .InvertMedia = d .Flags .Has (6 )
if d .Flags .Has (4 ) {
value , err := DecodeInputReplyTo (b )
if err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: field reply_to: %w" , err )
}
d .ReplyTo = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: field message: %w" , err )
}
d .Message = value
}
if d .Flags .Has (3 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: field entities: %w" , err )
}
if headerLen > 0 {
d .Entities = 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 draftMessage#3fccf7ef: field entities: %w" , err )
}
d .Entities = append (d .Entities , value )
}
}
if d .Flags .Has (5 ) {
value , err := DecodeInputMedia (b )
if err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: field media: %w" , err )
}
d .Media = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode draftMessage#3fccf7ef: field date: %w" , err )
}
d .Date = value
}
return nil
}
func (d *DraftMessage ) SetNoWebpage (value bool ) {
if value {
d .Flags .Set (1 )
d .NoWebpage = true
} else {
d .Flags .Unset (1 )
d .NoWebpage = false
}
}
func (d *DraftMessage ) GetNoWebpage () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (1 )
}
func (d *DraftMessage ) SetInvertMedia (value bool ) {
if value {
d .Flags .Set (6 )
d .InvertMedia = true
} else {
d .Flags .Unset (6 )
d .InvertMedia = false
}
}
func (d *DraftMessage ) GetInvertMedia () (value bool ) {
if d == nil {
return
}
return d .Flags .Has (6 )
}
func (d *DraftMessage ) SetReplyTo (value InputReplyToClass ) {
d .Flags .Set (4 )
d .ReplyTo = value
}
func (d *DraftMessage ) GetReplyTo () (value InputReplyToClass , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (4 ) {
return value , false
}
return d .ReplyTo , true
}
func (d *DraftMessage ) GetMessage () (value string ) {
if d == nil {
return
}
return d .Message
}
func (d *DraftMessage ) SetEntities (value []MessageEntityClass ) {
d .Flags .Set (3 )
d .Entities = value
}
func (d *DraftMessage ) GetEntities () (value []MessageEntityClass , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (3 ) {
return value , false
}
return d .Entities , true
}
func (d *DraftMessage ) SetMedia (value InputMediaClass ) {
d .Flags .Set (5 )
d .Media = value
}
func (d *DraftMessage ) GetMedia () (value InputMediaClass , ok bool ) {
if d == nil {
return
}
if !d .Flags .Has (5 ) {
return value , false
}
return d .Media , true
}
func (d *DraftMessage ) GetDate () (value int ) {
if d == nil {
return
}
return d .Date
}
func (d *DraftMessage ) MapEntities () (value MessageEntityClassArray , ok bool ) {
if !d .Flags .Has (3 ) {
return value , false
}
return MessageEntityClassArray (d .Entities ), true
}
const DraftMessageClassName = "DraftMessage"
type DraftMessageClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () DraftMessageClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
AsNotEmpty () (*DraftMessage , bool )
}
func (d *DraftMessageEmpty ) AsNotEmpty () (*DraftMessage , bool ) {
return nil , false
}
func (d *DraftMessage ) AsNotEmpty () (*DraftMessage , bool ) {
return d , true
}
func DecodeDraftMessage (buf *bin .Buffer ) (DraftMessageClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case DraftMessageEmptyTypeID :
v := DraftMessageEmpty {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode DraftMessageClass: %w" , err )
}
return &v , nil
case DraftMessageTypeID :
v := DraftMessage {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode DraftMessageClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode DraftMessageClass: %w" , bin .NewUnexpectedID (id ))
}
}
type DraftMessageBox struct {
DraftMessage DraftMessageClass
}
func (b *DraftMessageBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode DraftMessageBox to nil" )
}
v , err := DecodeDraftMessage (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .DraftMessage = v
return nil
}
func (b *DraftMessageBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .DraftMessage == nil {
return fmt .Errorf ("unable to encode DraftMessageClass as nil" )
}
return b .DraftMessage .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 .