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 ChatPhotoEmpty struct {
}
const ChatPhotoEmptyTypeID = 0x37c1011c
func (c ChatPhotoEmpty ) construct () ChatPhotoClass { return &c }
var (
_ bin .Encoder = &ChatPhotoEmpty {}
_ bin .Decoder = &ChatPhotoEmpty {}
_ bin .BareEncoder = &ChatPhotoEmpty {}
_ bin .BareDecoder = &ChatPhotoEmpty {}
_ ChatPhotoClass = &ChatPhotoEmpty {}
)
func (c *ChatPhotoEmpty ) Zero () bool {
if c == nil {
return true
}
return true
}
func (c *ChatPhotoEmpty ) String () string {
if c == nil {
return "ChatPhotoEmpty(nil)"
}
type Alias ChatPhotoEmpty
return fmt .Sprintf ("ChatPhotoEmpty%+v" , Alias (*c ))
}
func (*ChatPhotoEmpty ) TypeID () uint32 {
return ChatPhotoEmptyTypeID
}
func (*ChatPhotoEmpty ) TypeName () string {
return "chatPhotoEmpty"
}
func (c *ChatPhotoEmpty ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "chatPhotoEmpty" ,
ID : ChatPhotoEmptyTypeID ,
}
if c == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {}
return typ
}
func (c *ChatPhotoEmpty ) Encode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode chatPhotoEmpty#37c1011c as nil" )
}
b .PutID (ChatPhotoEmptyTypeID )
return c .EncodeBare (b )
}
func (c *ChatPhotoEmpty ) EncodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode chatPhotoEmpty#37c1011c as nil" )
}
return nil
}
func (c *ChatPhotoEmpty ) Decode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode chatPhotoEmpty#37c1011c to nil" )
}
if err := b .ConsumeID (ChatPhotoEmptyTypeID ); err != nil {
return fmt .Errorf ("unable to decode chatPhotoEmpty#37c1011c: %w" , err )
}
return c .DecodeBare (b )
}
func (c *ChatPhotoEmpty ) DecodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode chatPhotoEmpty#37c1011c to nil" )
}
return nil
}
type ChatPhoto struct {
Flags bin .Fields
HasVideo bool
PhotoID int64
StrippedThumb []byte
DCID int
}
const ChatPhotoTypeID = 0x1c6e1c11
func (c ChatPhoto ) construct () ChatPhotoClass { return &c }
var (
_ bin .Encoder = &ChatPhoto {}
_ bin .Decoder = &ChatPhoto {}
_ bin .BareEncoder = &ChatPhoto {}
_ bin .BareDecoder = &ChatPhoto {}
_ ChatPhotoClass = &ChatPhoto {}
)
func (c *ChatPhoto ) Zero () bool {
if c == nil {
return true
}
if !(c .Flags .Zero ()) {
return false
}
if !(c .HasVideo == false ) {
return false
}
if !(c .PhotoID == 0 ) {
return false
}
if !(c .StrippedThumb == nil ) {
return false
}
if !(c .DCID == 0 ) {
return false
}
return true
}
func (c *ChatPhoto ) String () string {
if c == nil {
return "ChatPhoto(nil)"
}
type Alias ChatPhoto
return fmt .Sprintf ("ChatPhoto%+v" , Alias (*c ))
}
func (c *ChatPhoto ) FillFrom (from interface {
GetHasVideo () (value bool )
GetPhotoID () (value int64 )
GetStrippedThumb () (value []byte , ok bool )
GetDCID () (value int )
}) {
c .HasVideo = from .GetHasVideo ()
c .PhotoID = from .GetPhotoID ()
if val , ok := from .GetStrippedThumb (); ok {
c .StrippedThumb = val
}
c .DCID = from .GetDCID ()
}
func (*ChatPhoto ) TypeID () uint32 {
return ChatPhotoTypeID
}
func (*ChatPhoto ) TypeName () string {
return "chatPhoto"
}
func (c *ChatPhoto ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "chatPhoto" ,
ID : ChatPhotoTypeID ,
}
if c == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "HasVideo" ,
SchemaName : "has_video" ,
Null : !c .Flags .Has (0 ),
},
{
Name : "PhotoID" ,
SchemaName : "photo_id" ,
},
{
Name : "StrippedThumb" ,
SchemaName : "stripped_thumb" ,
Null : !c .Flags .Has (1 ),
},
{
Name : "DCID" ,
SchemaName : "dc_id" ,
},
}
return typ
}
func (c *ChatPhoto ) SetFlags () {
if !(c .HasVideo == false ) {
c .Flags .Set (0 )
}
if !(c .StrippedThumb == nil ) {
c .Flags .Set (1 )
}
}
func (c *ChatPhoto ) Encode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode chatPhoto#1c6e1c11 as nil" )
}
b .PutID (ChatPhotoTypeID )
return c .EncodeBare (b )
}
func (c *ChatPhoto ) EncodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode chatPhoto#1c6e1c11 as nil" )
}
c .SetFlags ()
if err := c .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode chatPhoto#1c6e1c11: field flags: %w" , err )
}
b .PutLong (c .PhotoID )
if c .Flags .Has (1 ) {
b .PutBytes (c .StrippedThumb )
}
b .PutInt (c .DCID )
return nil
}
func (c *ChatPhoto ) Decode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode chatPhoto#1c6e1c11 to nil" )
}
if err := b .ConsumeID (ChatPhotoTypeID ); err != nil {
return fmt .Errorf ("unable to decode chatPhoto#1c6e1c11: %w" , err )
}
return c .DecodeBare (b )
}
func (c *ChatPhoto ) DecodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode chatPhoto#1c6e1c11 to nil" )
}
{
if err := c .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode chatPhoto#1c6e1c11: field flags: %w" , err )
}
}
c .HasVideo = c .Flags .Has (0 )
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode chatPhoto#1c6e1c11: field photo_id: %w" , err )
}
c .PhotoID = value
}
if c .Flags .Has (1 ) {
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode chatPhoto#1c6e1c11: field stripped_thumb: %w" , err )
}
c .StrippedThumb = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode chatPhoto#1c6e1c11: field dc_id: %w" , err )
}
c .DCID = value
}
return nil
}
func (c *ChatPhoto ) SetHasVideo (value bool ) {
if value {
c .Flags .Set (0 )
c .HasVideo = true
} else {
c .Flags .Unset (0 )
c .HasVideo = false
}
}
func (c *ChatPhoto ) GetHasVideo () (value bool ) {
if c == nil {
return
}
return c .Flags .Has (0 )
}
func (c *ChatPhoto ) GetPhotoID () (value int64 ) {
if c == nil {
return
}
return c .PhotoID
}
func (c *ChatPhoto ) SetStrippedThumb (value []byte ) {
c .Flags .Set (1 )
c .StrippedThumb = value
}
func (c *ChatPhoto ) GetStrippedThumb () (value []byte , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (1 ) {
return value , false
}
return c .StrippedThumb , true
}
func (c *ChatPhoto ) GetDCID () (value int ) {
if c == nil {
return
}
return c .DCID
}
const ChatPhotoClassName = "ChatPhoto"
type ChatPhotoClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () ChatPhotoClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
AsNotEmpty () (*ChatPhoto , bool )
}
func (c *ChatPhotoEmpty ) AsNotEmpty () (*ChatPhoto , bool ) {
return nil , false
}
func (c *ChatPhoto ) AsNotEmpty () (*ChatPhoto , bool ) {
return c , true
}
func DecodeChatPhoto (buf *bin .Buffer ) (ChatPhotoClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case ChatPhotoEmptyTypeID :
v := ChatPhotoEmpty {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode ChatPhotoClass: %w" , err )
}
return &v , nil
case ChatPhotoTypeID :
v := ChatPhoto {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode ChatPhotoClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode ChatPhotoClass: %w" , bin .NewUnexpectedID (id ))
}
}
type ChatPhotoBox struct {
ChatPhoto ChatPhotoClass
}
func (b *ChatPhotoBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode ChatPhotoBox to nil" )
}
v , err := DecodeChatPhoto (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .ChatPhoto = v
return nil
}
func (b *ChatPhotoBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .ChatPhoto == nil {
return fmt .Errorf ("unable to encode ChatPhotoClass as nil" )
}
return b .ChatPhoto .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 .