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 PeerUser struct {
UserID int64
}
const PeerUserTypeID = 0x59511722
func (p PeerUser ) construct () PeerClass { return &p }
var (
_ bin .Encoder = &PeerUser {}
_ bin .Decoder = &PeerUser {}
_ bin .BareEncoder = &PeerUser {}
_ bin .BareDecoder = &PeerUser {}
_ PeerClass = &PeerUser {}
)
func (p *PeerUser ) Zero () bool {
if p == nil {
return true
}
if !(p .UserID == 0 ) {
return false
}
return true
}
func (p *PeerUser ) String () string {
if p == nil {
return "PeerUser(nil)"
}
type Alias PeerUser
return fmt .Sprintf ("PeerUser%+v" , Alias (*p ))
}
func (p *PeerUser ) FillFrom (from interface {
GetUserID () (value int64 )
}) {
p .UserID = from .GetUserID ()
}
func (*PeerUser ) TypeID () uint32 {
return PeerUserTypeID
}
func (*PeerUser ) TypeName () string {
return "peerUser"
}
func (p *PeerUser ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "peerUser" ,
ID : PeerUserTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "UserID" ,
SchemaName : "user_id" ,
},
}
return typ
}
func (p *PeerUser ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode peerUser#59511722 as nil" )
}
b .PutID (PeerUserTypeID )
return p .EncodeBare (b )
}
func (p *PeerUser ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode peerUser#59511722 as nil" )
}
b .PutLong (p .UserID )
return nil
}
func (p *PeerUser ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode peerUser#59511722 to nil" )
}
if err := b .ConsumeID (PeerUserTypeID ); err != nil {
return fmt .Errorf ("unable to decode peerUser#59511722: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PeerUser ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode peerUser#59511722 to nil" )
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode peerUser#59511722: field user_id: %w" , err )
}
p .UserID = value
}
return nil
}
func (p *PeerUser ) GetUserID () (value int64 ) {
if p == nil {
return
}
return p .UserID
}
type PeerChat struct {
ChatID int64
}
const PeerChatTypeID = 0x36c6019a
func (p PeerChat ) construct () PeerClass { return &p }
var (
_ bin .Encoder = &PeerChat {}
_ bin .Decoder = &PeerChat {}
_ bin .BareEncoder = &PeerChat {}
_ bin .BareDecoder = &PeerChat {}
_ PeerClass = &PeerChat {}
)
func (p *PeerChat ) Zero () bool {
if p == nil {
return true
}
if !(p .ChatID == 0 ) {
return false
}
return true
}
func (p *PeerChat ) String () string {
if p == nil {
return "PeerChat(nil)"
}
type Alias PeerChat
return fmt .Sprintf ("PeerChat%+v" , Alias (*p ))
}
func (p *PeerChat ) FillFrom (from interface {
GetChatID () (value int64 )
}) {
p .ChatID = from .GetChatID ()
}
func (*PeerChat ) TypeID () uint32 {
return PeerChatTypeID
}
func (*PeerChat ) TypeName () string {
return "peerChat"
}
func (p *PeerChat ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "peerChat" ,
ID : PeerChatTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "ChatID" ,
SchemaName : "chat_id" ,
},
}
return typ
}
func (p *PeerChat ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode peerChat#36c6019a as nil" )
}
b .PutID (PeerChatTypeID )
return p .EncodeBare (b )
}
func (p *PeerChat ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode peerChat#36c6019a as nil" )
}
b .PutLong (p .ChatID )
return nil
}
func (p *PeerChat ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode peerChat#36c6019a to nil" )
}
if err := b .ConsumeID (PeerChatTypeID ); err != nil {
return fmt .Errorf ("unable to decode peerChat#36c6019a: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PeerChat ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode peerChat#36c6019a to nil" )
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode peerChat#36c6019a: field chat_id: %w" , err )
}
p .ChatID = value
}
return nil
}
func (p *PeerChat ) GetChatID () (value int64 ) {
if p == nil {
return
}
return p .ChatID
}
type PeerChannel struct {
ChannelID int64
}
const PeerChannelTypeID = 0xa2a5371e
func (p PeerChannel ) construct () PeerClass { return &p }
var (
_ bin .Encoder = &PeerChannel {}
_ bin .Decoder = &PeerChannel {}
_ bin .BareEncoder = &PeerChannel {}
_ bin .BareDecoder = &PeerChannel {}
_ PeerClass = &PeerChannel {}
)
func (p *PeerChannel ) Zero () bool {
if p == nil {
return true
}
if !(p .ChannelID == 0 ) {
return false
}
return true
}
func (p *PeerChannel ) String () string {
if p == nil {
return "PeerChannel(nil)"
}
type Alias PeerChannel
return fmt .Sprintf ("PeerChannel%+v" , Alias (*p ))
}
func (p *PeerChannel ) FillFrom (from interface {
GetChannelID () (value int64 )
}) {
p .ChannelID = from .GetChannelID ()
}
func (*PeerChannel ) TypeID () uint32 {
return PeerChannelTypeID
}
func (*PeerChannel ) TypeName () string {
return "peerChannel"
}
func (p *PeerChannel ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "peerChannel" ,
ID : PeerChannelTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "ChannelID" ,
SchemaName : "channel_id" ,
},
}
return typ
}
func (p *PeerChannel ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode peerChannel#a2a5371e as nil" )
}
b .PutID (PeerChannelTypeID )
return p .EncodeBare (b )
}
func (p *PeerChannel ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode peerChannel#a2a5371e as nil" )
}
b .PutLong (p .ChannelID )
return nil
}
func (p *PeerChannel ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode peerChannel#a2a5371e to nil" )
}
if err := b .ConsumeID (PeerChannelTypeID ); err != nil {
return fmt .Errorf ("unable to decode peerChannel#a2a5371e: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PeerChannel ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode peerChannel#a2a5371e to nil" )
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode peerChannel#a2a5371e: field channel_id: %w" , err )
}
p .ChannelID = value
}
return nil
}
func (p *PeerChannel ) GetChannelID () (value int64 ) {
if p == nil {
return
}
return p .ChannelID
}
const PeerClassName = "Peer"
type PeerClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () PeerClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
}
func (p *PeerChat ) AsInput () *InputPeerChat {
value := new (InputPeerChat )
value .ChatID = p .GetChatID ()
return value
}
func DecodePeer (buf *bin .Buffer ) (PeerClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case PeerUserTypeID :
v := PeerUser {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode PeerClass: %w" , err )
}
return &v , nil
case PeerChatTypeID :
v := PeerChat {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode PeerClass: %w" , err )
}
return &v , nil
case PeerChannelTypeID :
v := PeerChannel {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode PeerClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode PeerClass: %w" , bin .NewUnexpectedID (id ))
}
}
type PeerBox struct {
Peer PeerClass
}
func (b *PeerBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode PeerBox to nil" )
}
v , err := DecodePeer (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .Peer = v
return nil
}
func (b *PeerBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .Peer == nil {
return fmt .Errorf ("unable to encode PeerClass as nil" )
}
return b .Peer .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 .