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 MessageExtendedMediaPreview struct {
Flags bin .Fields
W int
H int
Thumb PhotoSizeClass
VideoDuration int
}
const MessageExtendedMediaPreviewTypeID = 0xad628cc8
func (m MessageExtendedMediaPreview ) construct () MessageExtendedMediaClass { return &m }
var (
_ bin .Encoder = &MessageExtendedMediaPreview {}
_ bin .Decoder = &MessageExtendedMediaPreview {}
_ bin .BareEncoder = &MessageExtendedMediaPreview {}
_ bin .BareDecoder = &MessageExtendedMediaPreview {}
_ MessageExtendedMediaClass = &MessageExtendedMediaPreview {}
)
func (m *MessageExtendedMediaPreview ) Zero () bool {
if m == nil {
return true
}
if !(m .Flags .Zero ()) {
return false
}
if !(m .W == 0 ) {
return false
}
if !(m .H == 0 ) {
return false
}
if !(m .Thumb == nil ) {
return false
}
if !(m .VideoDuration == 0 ) {
return false
}
return true
}
func (m *MessageExtendedMediaPreview ) String () string {
if m == nil {
return "MessageExtendedMediaPreview(nil)"
}
type Alias MessageExtendedMediaPreview
return fmt .Sprintf ("MessageExtendedMediaPreview%+v" , Alias (*m ))
}
func (m *MessageExtendedMediaPreview ) FillFrom (from interface {
GetW () (value int , ok bool )
GetH () (value int , ok bool )
GetThumb () (value PhotoSizeClass , ok bool )
GetVideoDuration () (value int , ok bool )
}) {
if val , ok := from .GetW (); ok {
m .W = val
}
if val , ok := from .GetH (); ok {
m .H = val
}
if val , ok := from .GetThumb (); ok {
m .Thumb = val
}
if val , ok := from .GetVideoDuration (); ok {
m .VideoDuration = val
}
}
func (*MessageExtendedMediaPreview ) TypeID () uint32 {
return MessageExtendedMediaPreviewTypeID
}
func (*MessageExtendedMediaPreview ) TypeName () string {
return "messageExtendedMediaPreview"
}
func (m *MessageExtendedMediaPreview ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messageExtendedMediaPreview" ,
ID : MessageExtendedMediaPreviewTypeID ,
}
if m == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "W" ,
SchemaName : "w" ,
Null : !m .Flags .Has (0 ),
},
{
Name : "H" ,
SchemaName : "h" ,
Null : !m .Flags .Has (0 ),
},
{
Name : "Thumb" ,
SchemaName : "thumb" ,
Null : !m .Flags .Has (1 ),
},
{
Name : "VideoDuration" ,
SchemaName : "video_duration" ,
Null : !m .Flags .Has (2 ),
},
}
return typ
}
func (m *MessageExtendedMediaPreview ) SetFlags () {
if !(m .W == 0 ) {
m .Flags .Set (0 )
}
if !(m .H == 0 ) {
m .Flags .Set (0 )
}
if !(m .Thumb == nil ) {
m .Flags .Set (1 )
}
if !(m .VideoDuration == 0 ) {
m .Flags .Set (2 )
}
}
func (m *MessageExtendedMediaPreview ) Encode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageExtendedMediaPreview#ad628cc8 as nil" )
}
b .PutID (MessageExtendedMediaPreviewTypeID )
return m .EncodeBare (b )
}
func (m *MessageExtendedMediaPreview ) EncodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageExtendedMediaPreview#ad628cc8 as nil" )
}
m .SetFlags ()
if err := m .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageExtendedMediaPreview#ad628cc8: field flags: %w" , err )
}
if m .Flags .Has (0 ) {
b .PutInt (m .W )
}
if m .Flags .Has (0 ) {
b .PutInt (m .H )
}
if m .Flags .Has (1 ) {
if m .Thumb == nil {
return fmt .Errorf ("unable to encode messageExtendedMediaPreview#ad628cc8: field thumb is nil" )
}
if err := m .Thumb .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageExtendedMediaPreview#ad628cc8: field thumb: %w" , err )
}
}
if m .Flags .Has (2 ) {
b .PutInt (m .VideoDuration )
}
return nil
}
func (m *MessageExtendedMediaPreview ) Decode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageExtendedMediaPreview#ad628cc8 to nil" )
}
if err := b .ConsumeID (MessageExtendedMediaPreviewTypeID ); err != nil {
return fmt .Errorf ("unable to decode messageExtendedMediaPreview#ad628cc8: %w" , err )
}
return m .DecodeBare (b )
}
func (m *MessageExtendedMediaPreview ) DecodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageExtendedMediaPreview#ad628cc8 to nil" )
}
{
if err := m .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messageExtendedMediaPreview#ad628cc8: field flags: %w" , err )
}
}
if m .Flags .Has (0 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageExtendedMediaPreview#ad628cc8: field w: %w" , err )
}
m .W = value
}
if m .Flags .Has (0 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageExtendedMediaPreview#ad628cc8: field h: %w" , err )
}
m .H = value
}
if m .Flags .Has (1 ) {
value , err := DecodePhotoSize (b )
if err != nil {
return fmt .Errorf ("unable to decode messageExtendedMediaPreview#ad628cc8: field thumb: %w" , err )
}
m .Thumb = value
}
if m .Flags .Has (2 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messageExtendedMediaPreview#ad628cc8: field video_duration: %w" , err )
}
m .VideoDuration = value
}
return nil
}
func (m *MessageExtendedMediaPreview ) SetW (value int ) {
m .Flags .Set (0 )
m .W = value
}
func (m *MessageExtendedMediaPreview ) GetW () (value int , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (0 ) {
return value , false
}
return m .W , true
}
func (m *MessageExtendedMediaPreview ) SetH (value int ) {
m .Flags .Set (0 )
m .H = value
}
func (m *MessageExtendedMediaPreview ) GetH () (value int , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (0 ) {
return value , false
}
return m .H , true
}
func (m *MessageExtendedMediaPreview ) SetThumb (value PhotoSizeClass ) {
m .Flags .Set (1 )
m .Thumb = value
}
func (m *MessageExtendedMediaPreview ) GetThumb () (value PhotoSizeClass , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (1 ) {
return value , false
}
return m .Thumb , true
}
func (m *MessageExtendedMediaPreview ) SetVideoDuration (value int ) {
m .Flags .Set (2 )
m .VideoDuration = value
}
func (m *MessageExtendedMediaPreview ) GetVideoDuration () (value int , ok bool ) {
if m == nil {
return
}
if !m .Flags .Has (2 ) {
return value , false
}
return m .VideoDuration , true
}
type MessageExtendedMedia struct {
Media MessageMediaClass
}
const MessageExtendedMediaTypeID = 0xee479c64
func (m MessageExtendedMedia ) construct () MessageExtendedMediaClass { return &m }
var (
_ bin .Encoder = &MessageExtendedMedia {}
_ bin .Decoder = &MessageExtendedMedia {}
_ bin .BareEncoder = &MessageExtendedMedia {}
_ bin .BareDecoder = &MessageExtendedMedia {}
_ MessageExtendedMediaClass = &MessageExtendedMedia {}
)
func (m *MessageExtendedMedia ) Zero () bool {
if m == nil {
return true
}
if !(m .Media == nil ) {
return false
}
return true
}
func (m *MessageExtendedMedia ) String () string {
if m == nil {
return "MessageExtendedMedia(nil)"
}
type Alias MessageExtendedMedia
return fmt .Sprintf ("MessageExtendedMedia%+v" , Alias (*m ))
}
func (m *MessageExtendedMedia ) FillFrom (from interface {
GetMedia () (value MessageMediaClass )
}) {
m .Media = from .GetMedia ()
}
func (*MessageExtendedMedia ) TypeID () uint32 {
return MessageExtendedMediaTypeID
}
func (*MessageExtendedMedia ) TypeName () string {
return "messageExtendedMedia"
}
func (m *MessageExtendedMedia ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messageExtendedMedia" ,
ID : MessageExtendedMediaTypeID ,
}
if m == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Media" ,
SchemaName : "media" ,
},
}
return typ
}
func (m *MessageExtendedMedia ) Encode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageExtendedMedia#ee479c64 as nil" )
}
b .PutID (MessageExtendedMediaTypeID )
return m .EncodeBare (b )
}
func (m *MessageExtendedMedia ) EncodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't encode messageExtendedMedia#ee479c64 as nil" )
}
if m .Media == nil {
return fmt .Errorf ("unable to encode messageExtendedMedia#ee479c64: field media is nil" )
}
if err := m .Media .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messageExtendedMedia#ee479c64: field media: %w" , err )
}
return nil
}
func (m *MessageExtendedMedia ) Decode (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageExtendedMedia#ee479c64 to nil" )
}
if err := b .ConsumeID (MessageExtendedMediaTypeID ); err != nil {
return fmt .Errorf ("unable to decode messageExtendedMedia#ee479c64: %w" , err )
}
return m .DecodeBare (b )
}
func (m *MessageExtendedMedia ) DecodeBare (b *bin .Buffer ) error {
if m == nil {
return fmt .Errorf ("can't decode messageExtendedMedia#ee479c64 to nil" )
}
{
value , err := DecodeMessageMedia (b )
if err != nil {
return fmt .Errorf ("unable to decode messageExtendedMedia#ee479c64: field media: %w" , err )
}
m .Media = value
}
return nil
}
func (m *MessageExtendedMedia ) GetMedia () (value MessageMediaClass ) {
if m == nil {
return
}
return m .Media
}
const MessageExtendedMediaClassName = "MessageExtendedMedia"
type MessageExtendedMediaClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () MessageExtendedMediaClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
}
func DecodeMessageExtendedMedia (buf *bin .Buffer ) (MessageExtendedMediaClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case MessageExtendedMediaPreviewTypeID :
v := MessageExtendedMediaPreview {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode MessageExtendedMediaClass: %w" , err )
}
return &v , nil
case MessageExtendedMediaTypeID :
v := MessageExtendedMedia {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode MessageExtendedMediaClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode MessageExtendedMediaClass: %w" , bin .NewUnexpectedID (id ))
}
}
type MessageExtendedMediaBox struct {
MessageExtendedMedia MessageExtendedMediaClass
}
func (b *MessageExtendedMediaBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode MessageExtendedMediaBox to nil" )
}
v , err := DecodeMessageExtendedMedia (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .MessageExtendedMedia = v
return nil
}
func (b *MessageExtendedMediaBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .MessageExtendedMedia == nil {
return fmt .Errorf ("unable to encode MessageExtendedMediaClass as nil" )
}
return b .MessageExtendedMedia .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 .