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 MessageReplyHeader struct {
Flags bin .Fields
ReplyToScheduled bool
ForumTopic bool
Quote bool
ReplyToMsgID int
ReplyToPeerID PeerClass
ReplyFrom MessageFwdHeader
ReplyMedia MessageMediaClass
ReplyToTopID int
QuoteText string
QuoteEntities []MessageEntityClass
QuoteOffset int
}
const MessageReplyHeaderTypeID = 0xafbc09db
func (m MessageReplyHeader ) construct () MessageReplyHeaderClass { return &m }
var (
_ bin .Encoder = &MessageReplyHeader {}
_ bin .Decoder = &MessageReplyHeader {}
_ bin .BareEncoder = &MessageReplyHeader {}
_ bin .BareDecoder = &MessageReplyHeader {}
_ MessageReplyHeaderClass = &MessageReplyHeader {}
)
func (m *MessageReplyHeader ) Zero () bool {
if m == nil {
return true
}
if !(m .Flags .Zero ()) {
return false
}
if !(m .ReplyToScheduled == false ) {
return false
}
if !(m .ForumTopic == false ) {
return false
}
if !(m .Quote == false ) {
return false
}
if !(m .ReplyToMsgID == 0 ) {
return false
}
if !(m .ReplyToPeerID == nil ) {
return false
}
if !(m .ReplyFrom .Zero ()) {
return false
}
if !(m .ReplyMedia == nil ) {
return false
}
if !(m .ReplyToTopID == 0 ) {
return false
}
if !(m .QuoteText == "" ) {
return false
}
if !(m .QuoteEntities == nil ) {
return false
}
if !(m .QuoteOffset == 0 ) {
return false
}
return true
}
func (m *MessageReplyHeader ) String () string {
if m == nil {
return "MessageReplyHeader(nil)"
}
type Alias MessageReplyHeader
return fmt .Sprintf ("MessageReplyHeader%+v" , Alias (*m ))
}
func (m *MessageReplyHeader ) FillFrom (from interface {
GetReplyToScheduled () (value bool )
GetForumTopic () (value bool )
GetQuote () (value bool )
GetReplyToMsgID () (value int , ok bool )
GetReplyToPeerID () (value PeerClass , ok bool )
GetReplyFrom () (value MessageFwdHeader , ok bool )
GetReplyMedia () (value MessageMediaClass , ok bool )
GetReplyToTopID () (value int , ok bool )
GetQuoteText () (value string , ok bool )
GetQuoteEntities () (value []MessageEntityClass , ok bool )
GetQuoteOffset () (value int , ok bool )
}) {
m .ReplyToScheduled = from .GetReplyToScheduled ()
m .ForumTopic = from .GetForumTopic ()
m .Quote = from .GetQuote ()
if val , ok := from .GetReplyToMsgID (); ok {
m .ReplyToMsgID = val
}
if val , ok := from .GetReplyToPeerID (); ok {
m .ReplyToPeerID = val
}
if val , ok := from .GetReplyFrom (); ok {
m .ReplyFrom = val
}
if val , ok := from .GetReplyMedia (); ok {
m .ReplyMedia = val
}
if val , ok := from .GetReplyToTopID (); ok {
m .ReplyToTopID = val
}
if val , ok := from .GetQuoteText (); ok {
m .QuoteText = val
}
if val , ok := from .GetQuoteEntities (); ok {
m .QuoteEntities = val
}
if val , ok := from .GetQuoteOffset (); ok {
m .QuoteOffset = val
}
}
func (*MessageReplyHeader ) TypeID () uint32 {
return MessageReplyHeaderTypeID
}
func (*MessageReplyHeader ) TypeName () string {
return "messageReplyHeader"
}
func (m *MessageReplyHeader ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messageReplyHeader" ,
ID : MessageReplyHeaderTypeID ,
}
if m == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "ReplyToScheduled" ,
SchemaName : "reply_to_scheduled" ,
Null : !m .Flags .Has (2 ),
},
{
Name : "ForumTopic" ,
SchemaName : "forum_topic" ,
Null : !m .Flags .Has (3 ),
},
{
Name : "Quote" ,
SchemaName : "quote" ,
Null : !m .Flags .Has (9 ),
},
{
Name : "ReplyToMsgID" ,
SchemaName : "reply_to_msg_id" ,
Null : !m .Flags .Has (4 ),
},
{
Name : "ReplyToPeerID" ,
SchemaName : "reply_to_peer_id" ,
Null : !m .Flags .Has (0 ),
},
{
Name : "ReplyFrom" ,
SchemaName : "reply_from" ,
Null : !m .Flags .Has (5 ),
},
{
Name : "ReplyMedia" ,
SchemaName : "reply_media" ,
Null : !m .Flags .Has (8 ),
},
{
Name : "ReplyToTopID" ,
SchemaName : "reply_to_top_id" ,
Null : !m .Flags .Has (1 ),
},
{
Name : "QuoteText" ,
SchemaName : "quote_text" ,
Null : !m .Flags .Has (6 ),
},
{
Name : "QuoteEntities" ,
SchemaName : "quote_entities" ,
Null : !m .Flags .Has (7 ),
},
{
Name : "QuoteOffset" ,
SchemaName : "quote_offset" ,
Null : !m .Flags .Has (10 ),
},
}
return typ
}
func (m *MessageReplyHeader ) SetFlags () {
if !(m .ReplyToScheduled == false ) {
m .Flags .Set (2 )
}
if !(m .ForumTopic == false ) {
m .Flags .Set (3 )
}
if !(m .Quote == false ) {
m .Flags .Set (9 )
}
if !(m .ReplyToMsgID == 0 ) {
m .Flags .Set (4 )
}
if !(m .ReplyToPeerID == nil ) {
m .Flags .Set (0 )
}
if !(m .ReplyFrom .Zero ()) {
m .Flags .Set (5 )
}
if !(m .ReplyMedia == nil ) {
m .Flags .Set (8 )
}
if !(m .ReplyToTopID == 0 ) {
m .Flags .Set (1 )
}
if !(m .QuoteText == "" ) {
m .Flags .Set (6 )
}
if !(m .QuoteEntities == nil ) {
m .Flags .Set (7 )
}
if !(m .QuoteOffset == 0 ) {
m .Flags .Set (10 )
}
}
func (m *MessageReplyHeader ) Encode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageReplyHeader#afbc09db as nil" )
}
b .PutID (MessageReplyHeaderTypeID )
return m .EncodeBare (b )
}
func (m *MessageReplyHeader ) EncodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageReplyHeader#afbc09db as nil" )
}
m .SetFlags ()
if err := m .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field flags: %w" , err )
}
if m .Flags .Has (4 ) {
b .PutInt (m .ReplyToMsgID )
}
if m .Flags .Has (0 ) {
if m .ReplyToPeerID == nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field reply_to_peer_id is nil" )
}
if err := m .ReplyToPeerID .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field reply_to_peer_id: %w" , err )
}
}
if m .Flags .Has (5 ) {
if err := m .ReplyFrom .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field reply_from: %w" , err )
}
}
if m .Flags .Has (8 ) {
if m .ReplyMedia == nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field reply_media is nil" )
}
if err := m .ReplyMedia .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field reply_media: %w" , err )
}
}
if m .Flags .Has (1 ) {
b .PutInt (m .ReplyToTopID )
}
if m .Flags .Has (6 ) {
b .PutString (m .QuoteText )
}
if m .Flags .Has (7 ) {
b .PutVectorHeader (len (m .QuoteEntities ))
for idx , v := range m .QuoteEntities {
if v == nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field quote_entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageReplyHeader#afbc09db: field quote_entities element with index %d: %w" , idx , err )
}
}
}
if m .Flags .Has (10 ) {
b .PutInt (m .QuoteOffset )
}
return nil
}
func (m *MessageReplyHeader ) Decode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageReplyHeader#afbc09db to nil" )
}
if err := b .ConsumeID (MessageReplyHeaderTypeID ); err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: %w" , err )
}
return m .DecodeBare (b )
}
func (m *MessageReplyHeader ) DecodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageReplyHeader#afbc09db to nil" )
}
{
if err := m .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field flags: %w" , err )
}
}
m .ReplyToScheduled = m .Flags .Has (2 )
m .ForumTopic = m .Flags .Has (3 )
m .Quote = m .Flags .Has (9 )
if m .Flags .Has (4 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field reply_to_msg_id: %w" , err )
}
m .ReplyToMsgID = value
}
if m .Flags .Has (0 ) {
value , err := DecodePeer (b )
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field reply_to_peer_id: %w" , err )
}
m .ReplyToPeerID = value
}
if m .Flags .Has (5 ) {
if err := m .ReplyFrom .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field reply_from: %w" , err )
}
}
if m .Flags .Has (8 ) {
value , err := DecodeMessageMedia (b )
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field reply_media: %w" , err )
}
m .ReplyMedia = value
}
if m .Flags .Has (1 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field reply_to_top_id: %w" , err )
}
m .ReplyToTopID = value
}
if m .Flags .Has (6 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field quote_text: %w" , err )
}
m .QuoteText = value
}
if m .Flags .Has (7 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field quote_entities: %w" , err )
}
if headerLen > 0 {
m .QuoteEntities = 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 messageReplyHeader#afbc09db: field quote_entities: %w" , err )
}
m .QuoteEntities = append (m .QuoteEntities , value )
}
}
if m .Flags .Has (10 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyHeader#afbc09db: field quote_offset: %w" , err )
}
m .QuoteOffset = value
}
return nil
}
func (m *MessageReplyHeader ) SetReplyToScheduled (value bool ) {
if value {
m .Flags .Set (2 )
m .ReplyToScheduled = true
} else {
m .Flags .Unset (2 )
m .ReplyToScheduled = false
}
}
func (m *MessageReplyHeader ) GetReplyToScheduled () (value bool ) {
if m == nil {
return
}
return m .Flags .Has (2 )
}
func (m *MessageReplyHeader ) SetForumTopic (value bool ) {
if value {
m .Flags .Set (3 )
m .ForumTopic = true
} else {
m .Flags .Unset (3 )
m .ForumTopic = false
}
}
func (m *MessageReplyHeader ) GetForumTopic () (value bool ) {
if m == nil {
return
}
return m .Flags .Has (3 )
}
func (m *MessageReplyHeader ) SetQuote (value bool ) {
if value {
m .Flags .Set (9 )
m .Quote = true
} else {
m .Flags .Unset (9 )
m .Quote = false
}
}
func (m *MessageReplyHeader ) GetQuote () (value bool ) {
if m == nil {
return
}
return m .Flags .Has (9 )
}
func (m *MessageReplyHeader ) SetReplyToMsgID (value int ) {
m .Flags .Set (4 )
m .ReplyToMsgID = value
}
func (m *MessageReplyHeader ) GetReplyToMsgID () (value int , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (4 ) {
return value , false
}
return m .ReplyToMsgID , true
}
func (m *MessageReplyHeader ) SetReplyToPeerID (value PeerClass ) {
m .Flags .Set (0 )
m .ReplyToPeerID = value
}
func (m *MessageReplyHeader ) GetReplyToPeerID () (value PeerClass , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (0 ) {
return value , false
}
return m .ReplyToPeerID , true
}
func (m *MessageReplyHeader ) SetReplyFrom (value MessageFwdHeader ) {
m .Flags .Set (5 )
m .ReplyFrom = value
}
func (m *MessageReplyHeader ) GetReplyFrom () (value MessageFwdHeader , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (5 ) {
return value , false
}
return m .ReplyFrom , true
}
func (m *MessageReplyHeader ) SetReplyMedia (value MessageMediaClass ) {
m .Flags .Set (8 )
m .ReplyMedia = value
}
func (m *MessageReplyHeader ) GetReplyMedia () (value MessageMediaClass , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (8 ) {
return value , false
}
return m .ReplyMedia , true
}
func (m *MessageReplyHeader ) SetReplyToTopID (value int ) {
m .Flags .Set (1 )
m .ReplyToTopID = value
}
func (m *MessageReplyHeader ) GetReplyToTopID () (value int , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (1 ) {
return value , false
}
return m .ReplyToTopID , true
}
func (m *MessageReplyHeader ) SetQuoteText (value string ) {
m .Flags .Set (6 )
m .QuoteText = value
}
func (m *MessageReplyHeader ) GetQuoteText () (value string , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (6 ) {
return value , false
}
return m .QuoteText , true
}
func (m *MessageReplyHeader ) SetQuoteEntities (value []MessageEntityClass ) {
m .Flags .Set (7 )
m .QuoteEntities = value
}
func (m *MessageReplyHeader ) GetQuoteEntities () (value []MessageEntityClass , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (7 ) {
return value , false
}
return m .QuoteEntities , true
}
func (m *MessageReplyHeader ) SetQuoteOffset (value int ) {
m .Flags .Set (10 )
m .QuoteOffset = value
}
func (m *MessageReplyHeader ) GetQuoteOffset () (value int , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (10 ) {
return value , false
}
return m .QuoteOffset , true
}
func (m *MessageReplyHeader ) MapQuoteEntities () (value MessageEntityClassArray , ok bool ) {
if !m .Flags .Has (7 ) {
return value , false
}
return MessageEntityClassArray (m .QuoteEntities ), true
}
type MessageReplyStoryHeader struct {
UserID int64
StoryID int
}
const MessageReplyStoryHeaderTypeID = 0x9c98bfc1
func (m MessageReplyStoryHeader ) construct () MessageReplyHeaderClass { return &m }
var (
_ bin .Encoder = &MessageReplyStoryHeader {}
_ bin .Decoder = &MessageReplyStoryHeader {}
_ bin .BareEncoder = &MessageReplyStoryHeader {}
_ bin .BareDecoder = &MessageReplyStoryHeader {}
_ MessageReplyHeaderClass = &MessageReplyStoryHeader {}
)
func (m *MessageReplyStoryHeader ) Zero () bool {
if m == nil {
return true
}
if !(m .UserID == 0 ) {
return false
}
if !(m .StoryID == 0 ) {
return false
}
return true
}
func (m *MessageReplyStoryHeader ) String () string {
if m == nil {
return "MessageReplyStoryHeader(nil)"
}
type Alias MessageReplyStoryHeader
return fmt .Sprintf ("MessageReplyStoryHeader%+v" , Alias (*m ))
}
func (m *MessageReplyStoryHeader ) FillFrom (from interface {
GetUserID () (value int64 )
GetStoryID () (value int )
}) {
m .UserID = from .GetUserID ()
m .StoryID = from .GetStoryID ()
}
func (*MessageReplyStoryHeader ) TypeID () uint32 {
return MessageReplyStoryHeaderTypeID
}
func (*MessageReplyStoryHeader ) TypeName () string {
return "messageReplyStoryHeader"
}
func (m *MessageReplyStoryHeader ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messageReplyStoryHeader" ,
ID : MessageReplyStoryHeaderTypeID ,
}
if m == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "UserID" ,
SchemaName : "user_id" ,
},
{
Name : "StoryID" ,
SchemaName : "story_id" ,
},
}
return typ
}
func (m *MessageReplyStoryHeader ) Encode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageReplyStoryHeader#9c98bfc1 as nil" )
}
b .PutID (MessageReplyStoryHeaderTypeID )
return m .EncodeBare (b )
}
func (m *MessageReplyStoryHeader ) EncodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageReplyStoryHeader#9c98bfc1 as nil" )
}
b .PutLong (m .UserID )
b .PutInt (m .StoryID )
return nil
}
func (m *MessageReplyStoryHeader ) Decode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageReplyStoryHeader#9c98bfc1 to nil" )
}
if err := b .ConsumeID (MessageReplyStoryHeaderTypeID ); err != nil {
return fmt .Errorf ("unable to decode messageReplyStoryHeader#9c98bfc1: %w" , err )
}
return m .DecodeBare (b )
}
func (m *MessageReplyStoryHeader ) DecodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageReplyStoryHeader#9c98bfc1 to nil" )
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyStoryHeader#9c98bfc1: field user_id: %w" , err )
}
m .UserID = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageReplyStoryHeader#9c98bfc1: field story_id: %w" , err )
}
m .StoryID = value
}
return nil
}
func (m *MessageReplyStoryHeader ) GetUserID () (value int64 ) {
if m == nil {
return
}
return m .UserID
}
func (m *MessageReplyStoryHeader ) GetStoryID () (value int ) {
if m == nil {
return
}
return m .StoryID
}
const MessageReplyHeaderClassName = "MessageReplyHeader"
type MessageReplyHeaderClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () MessageReplyHeaderClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
}
func DecodeMessageReplyHeader (buf *bin .Buffer ) (MessageReplyHeaderClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case MessageReplyHeaderTypeID :
v := MessageReplyHeader {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode MessageReplyHeaderClass: %w" , err )
}
return &v , nil
case MessageReplyStoryHeaderTypeID :
v := MessageReplyStoryHeader {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode MessageReplyHeaderClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode MessageReplyHeaderClass: %w" , bin .NewUnexpectedID (id ))
}
}
type MessageReplyHeaderBox struct {
MessageReplyHeader MessageReplyHeaderClass
}
func (b *MessageReplyHeaderBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode MessageReplyHeaderBox to nil" )
}
v , err := DecodeMessageReplyHeader (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .MessageReplyHeader = v
return nil
}
func (b *MessageReplyHeaderBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .MessageReplyHeader == nil {
return fmt .Errorf ("unable to encode MessageReplyHeaderClass as nil" )
}
return b .MessageReplyHeader .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 .