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 PhotosPhoto struct {
Photo PhotoClass
Users []UserClass
}
const PhotosPhotoTypeID = 0x20212ca8
var (
_ bin .Encoder = &PhotosPhoto {}
_ bin .Decoder = &PhotosPhoto {}
_ bin .BareEncoder = &PhotosPhoto {}
_ bin .BareDecoder = &PhotosPhoto {}
)
func (p *PhotosPhoto ) Zero () bool {
if p == nil {
return true
}
if !(p .Photo == nil ) {
return false
}
if !(p .Users == nil ) {
return false
}
return true
}
func (p *PhotosPhoto ) String () string {
if p == nil {
return "PhotosPhoto(nil)"
}
type Alias PhotosPhoto
return fmt .Sprintf ("PhotosPhoto%+v" , Alias (*p ))
}
func (p *PhotosPhoto ) FillFrom (from interface {
GetPhoto () (value PhotoClass )
GetUsers () (value []UserClass )
}) {
p .Photo = from .GetPhoto ()
p .Users = from .GetUsers ()
}
func (*PhotosPhoto ) TypeID () uint32 {
return PhotosPhotoTypeID
}
func (*PhotosPhoto ) TypeName () string {
return "photos.photo"
}
func (p *PhotosPhoto ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "photos.photo" ,
ID : PhotosPhotoTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Photo" ,
SchemaName : "photo" ,
},
{
Name : "Users" ,
SchemaName : "users" ,
},
}
return typ
}
func (p *PhotosPhoto ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode photos.photo#20212ca8 as nil" )
}
b .PutID (PhotosPhotoTypeID )
return p .EncodeBare (b )
}
func (p *PhotosPhoto ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode photos.photo#20212ca8 as nil" )
}
if p .Photo == nil {
return fmt .Errorf ("unable to encode photos.photo#20212ca8: field photo is nil" )
}
if err := p .Photo .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode photos.photo#20212ca8: field photo: %w" , err )
}
b .PutVectorHeader (len (p .Users ))
for idx , v := range p .Users {
if v == nil {
return fmt .Errorf ("unable to encode photos.photo#20212ca8: field users element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode photos.photo#20212ca8: field users element with index %d: %w" , idx , err )
}
}
return nil
}
func (p *PhotosPhoto ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode photos.photo#20212ca8 to nil" )
}
if err := b .ConsumeID (PhotosPhotoTypeID ); err != nil {
return fmt .Errorf ("unable to decode photos.photo#20212ca8: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PhotosPhoto ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode photos.photo#20212ca8 to nil" )
}
{
value , err := DecodePhoto (b )
if err != nil {
return fmt .Errorf ("unable to decode photos.photo#20212ca8: field photo: %w" , err )
}
p .Photo = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode photos.photo#20212ca8: field users: %w" , err )
}
if headerLen > 0 {
p .Users = make ([]UserClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeUser (b )
if err != nil {
return fmt .Errorf ("unable to decode photos.photo#20212ca8: field users: %w" , err )
}
p .Users = append (p .Users , value )
}
}
return nil
}
func (p *PhotosPhoto ) GetPhoto () (value PhotoClass ) {
if p == nil {
return
}
return p .Photo
}
func (p *PhotosPhoto ) GetUsers () (value []UserClass ) {
if p == nil {
return
}
return p .Users
}
func (p *PhotosPhoto ) GetPhotoAsNotEmpty () (*Photo , bool ) {
return p .Photo .AsNotEmpty ()
}
func (p *PhotosPhoto ) MapUsers () (value UserClassArray ) {
return UserClassArray (p .Users )
}
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 .