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 BusinessChatLink struct {
Flags bin .Fields
Link string
Message string
Entities []MessageEntityClass
Title string
Views int
}
const BusinessChatLinkTypeID = 0xb4ae666f
var (
_ bin .Encoder = &BusinessChatLink {}
_ bin .Decoder = &BusinessChatLink {}
_ bin .BareEncoder = &BusinessChatLink {}
_ bin .BareDecoder = &BusinessChatLink {}
)
func (b *BusinessChatLink ) Zero () bool {
if b == nil {
return true
}
if !(b .Flags .Zero ()) {
return false
}
if !(b .Link == "" ) {
return false
}
if !(b .Message == "" ) {
return false
}
if !(b .Entities == nil ) {
return false
}
if !(b .Title == "" ) {
return false
}
if !(b .Views == 0 ) {
return false
}
return true
}
func (b *BusinessChatLink ) String () string {
if b == nil {
return "BusinessChatLink(nil)"
}
type Alias BusinessChatLink
return fmt .Sprintf ("BusinessChatLink%+v" , Alias (*b ))
}
func (b *BusinessChatLink ) FillFrom (from interface {
GetLink () (value string )
GetMessage () (value string )
GetEntities () (value []MessageEntityClass , ok bool )
GetTitle () (value string , ok bool )
GetViews () (value int )
}) {
b .Link = from .GetLink ()
b .Message = from .GetMessage ()
if val , ok := from .GetEntities (); ok {
b .Entities = val
}
if val , ok := from .GetTitle (); ok {
b .Title = val
}
b .Views = from .GetViews ()
}
func (*BusinessChatLink ) TypeID () uint32 {
return BusinessChatLinkTypeID
}
func (*BusinessChatLink ) TypeName () string {
return "businessChatLink"
}
func (b *BusinessChatLink ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "businessChatLink" ,
ID : BusinessChatLinkTypeID ,
}
if b == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Link" ,
SchemaName : "link" ,
},
{
Name : "Message" ,
SchemaName : "message" ,
},
{
Name : "Entities" ,
SchemaName : "entities" ,
Null : !b .Flags .Has (0 ),
},
{
Name : "Title" ,
SchemaName : "title" ,
Null : !b .Flags .Has (1 ),
},
{
Name : "Views" ,
SchemaName : "views" ,
},
}
return typ
}
func (b *BusinessChatLink ) SetFlags () {
if !(b .Entities == nil ) {
b .Flags .Set (0 )
}
if !(b .Title == "" ) {
b .Flags .Set (1 )
}
}
func (b *BusinessChatLink ) Encode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't encode businessChatLink#b4ae666f as nil" )
}
buf .PutID (BusinessChatLinkTypeID )
return b .EncodeBare (buf )
}
func (b *BusinessChatLink ) EncodeBare (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't encode businessChatLink#b4ae666f as nil" )
}
b .SetFlags ()
if err := b .Flags .Encode (buf ); err != nil {
return fmt .Errorf ("unable to encode businessChatLink#b4ae666f: field flags: %w" , err )
}
buf .PutString (b .Link )
buf .PutString (b .Message )
if b .Flags .Has (0 ) {
buf .PutVectorHeader (len (b .Entities ))
for idx , v := range b .Entities {
if v == nil {
return fmt .Errorf ("unable to encode businessChatLink#b4ae666f: field entities element with index %d is nil" , idx )
}
if err := v .Encode (buf ); err != nil {
return fmt .Errorf ("unable to encode businessChatLink#b4ae666f: field entities element with index %d: %w" , idx , err )
}
}
}
if b .Flags .Has (1 ) {
buf .PutString (b .Title )
}
buf .PutInt (b .Views )
return nil
}
func (b *BusinessChatLink ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't decode businessChatLink#b4ae666f to nil" )
}
if err := buf .ConsumeID (BusinessChatLinkTypeID ); err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: %w" , err )
}
return b .DecodeBare (buf )
}
func (b *BusinessChatLink ) DecodeBare (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("can't decode businessChatLink#b4ae666f to nil" )
}
{
if err := b .Flags .Decode (buf ); err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field flags: %w" , err )
}
}
{
value , err := buf .String ()
if err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field link: %w" , err )
}
b .Link = value
}
{
value , err := buf .String ()
if err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field message: %w" , err )
}
b .Message = value
}
if b .Flags .Has (0 ) {
headerLen , err := buf .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field entities: %w" , err )
}
if headerLen > 0 {
b .Entities = make ([]MessageEntityClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeMessageEntity (buf )
if err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field entities: %w" , err )
}
b .Entities = append (b .Entities , value )
}
}
if b .Flags .Has (1 ) {
value , err := buf .String ()
if err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field title: %w" , err )
}
b .Title = value
}
{
value , err := buf .Int ()
if err != nil {
return fmt .Errorf ("unable to decode businessChatLink#b4ae666f: field views: %w" , err )
}
b .Views = value
}
return nil
}
func (b *BusinessChatLink ) GetLink () (value string ) {
if b == nil {
return
}
return b .Link
}
func (b *BusinessChatLink ) GetMessage () (value string ) {
if b == nil {
return
}
return b .Message
}
func (b *BusinessChatLink ) SetEntities (value []MessageEntityClass ) {
b .Flags .Set (0 )
b .Entities = value
}
func (b *BusinessChatLink ) GetEntities () (value []MessageEntityClass , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (0 ) {
return value , false
}
return b .Entities , true
}
func (b *BusinessChatLink ) SetTitle (value string ) {
b .Flags .Set (1 )
b .Title = value
}
func (b *BusinessChatLink ) GetTitle () (value string , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (1 ) {
return value , false
}
return b .Title , true
}
func (b *BusinessChatLink ) GetViews () (value int ) {
if b == nil {
return
}
return b .Views
}
func (b *BusinessChatLink ) MapEntities () (value MessageEntityClassArray , ok bool ) {
if !b .Flags .Has (0 ) {
return value , false
}
return MessageEntityClassArray (b .Entities ), true
}
The pages are generated with Golds v0.8.4 . (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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds .