Files
mautrix-telegram/pkg/gotd/tdapi/tl_giveaway_prize_gen.go
T
2025-06-27 20:03:37 -07:00

503 lines
13 KiB
Go

// Code generated by gotdgen, DO NOT EDIT.
package tdapi
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// GiveawayPrizePremium represents TL type `giveawayPrizePremium#1b12e978`.
type GiveawayPrizePremium struct {
// Number of months the Telegram Premium subscription will be active after code
// activation
MonthCount int32
}
// GiveawayPrizePremiumTypeID is TL type id of GiveawayPrizePremium.
const GiveawayPrizePremiumTypeID = 0x1b12e978
// construct implements constructor of GiveawayPrizeClass.
func (g GiveawayPrizePremium) construct() GiveawayPrizeClass { return &g }
// Ensuring interfaces in compile-time for GiveawayPrizePremium.
var (
_ bin.Encoder = &GiveawayPrizePremium{}
_ bin.Decoder = &GiveawayPrizePremium{}
_ bin.BareEncoder = &GiveawayPrizePremium{}
_ bin.BareDecoder = &GiveawayPrizePremium{}
_ GiveawayPrizeClass = &GiveawayPrizePremium{}
)
func (g *GiveawayPrizePremium) Zero() bool {
if g == nil {
return true
}
if !(g.MonthCount == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (g *GiveawayPrizePremium) String() string {
if g == nil {
return "GiveawayPrizePremium(nil)"
}
type Alias GiveawayPrizePremium
return fmt.Sprintf("GiveawayPrizePremium%+v", Alias(*g))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*GiveawayPrizePremium) TypeID() uint32 {
return GiveawayPrizePremiumTypeID
}
// TypeName returns name of type in TL schema.
func (*GiveawayPrizePremium) TypeName() string {
return "giveawayPrizePremium"
}
// TypeInfo returns info about TL type.
func (g *GiveawayPrizePremium) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "giveawayPrizePremium",
ID: GiveawayPrizePremiumTypeID,
}
if g == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "MonthCount",
SchemaName: "month_count",
},
}
return typ
}
// Encode implements bin.Encoder.
func (g *GiveawayPrizePremium) Encode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode giveawayPrizePremium#1b12e978 as nil")
}
b.PutID(GiveawayPrizePremiumTypeID)
return g.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (g *GiveawayPrizePremium) EncodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode giveawayPrizePremium#1b12e978 as nil")
}
b.PutInt32(g.MonthCount)
return nil
}
// Decode implements bin.Decoder.
func (g *GiveawayPrizePremium) Decode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode giveawayPrizePremium#1b12e978 to nil")
}
if err := b.ConsumeID(GiveawayPrizePremiumTypeID); err != nil {
return fmt.Errorf("unable to decode giveawayPrizePremium#1b12e978: %w", err)
}
return g.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (g *GiveawayPrizePremium) DecodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode giveawayPrizePremium#1b12e978 to nil")
}
{
value, err := b.Int32()
if err != nil {
return fmt.Errorf("unable to decode giveawayPrizePremium#1b12e978: field month_count: %w", err)
}
g.MonthCount = value
}
return nil
}
// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GiveawayPrizePremium) EncodeTDLibJSON(b tdjson.Encoder) error {
if g == nil {
return fmt.Errorf("can't encode giveawayPrizePremium#1b12e978 as nil")
}
b.ObjStart()
b.PutID("giveawayPrizePremium")
b.Comma()
b.FieldStart("month_count")
b.PutInt32(g.MonthCount)
b.Comma()
b.StripComma()
b.ObjEnd()
return nil
}
// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GiveawayPrizePremium) DecodeTDLibJSON(b tdjson.Decoder) error {
if g == nil {
return fmt.Errorf("can't decode giveawayPrizePremium#1b12e978 to nil")
}
return b.Obj(func(b tdjson.Decoder, key []byte) error {
switch string(key) {
case tdjson.TypeField:
if err := b.ConsumeID("giveawayPrizePremium"); err != nil {
return fmt.Errorf("unable to decode giveawayPrizePremium#1b12e978: %w", err)
}
case "month_count":
value, err := b.Int32()
if err != nil {
return fmt.Errorf("unable to decode giveawayPrizePremium#1b12e978: field month_count: %w", err)
}
g.MonthCount = value
default:
return b.Skip()
}
return nil
})
}
// GetMonthCount returns value of MonthCount field.
func (g *GiveawayPrizePremium) GetMonthCount() (value int32) {
if g == nil {
return
}
return g.MonthCount
}
// GiveawayPrizeStars represents TL type `giveawayPrizeStars#954c1fa4`.
type GiveawayPrizeStars struct {
// Number of Telegram Stars that will be shared by all winners
StarCount int64
}
// GiveawayPrizeStarsTypeID is TL type id of GiveawayPrizeStars.
const GiveawayPrizeStarsTypeID = 0x954c1fa4
// construct implements constructor of GiveawayPrizeClass.
func (g GiveawayPrizeStars) construct() GiveawayPrizeClass { return &g }
// Ensuring interfaces in compile-time for GiveawayPrizeStars.
var (
_ bin.Encoder = &GiveawayPrizeStars{}
_ bin.Decoder = &GiveawayPrizeStars{}
_ bin.BareEncoder = &GiveawayPrizeStars{}
_ bin.BareDecoder = &GiveawayPrizeStars{}
_ GiveawayPrizeClass = &GiveawayPrizeStars{}
)
func (g *GiveawayPrizeStars) Zero() bool {
if g == nil {
return true
}
if !(g.StarCount == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (g *GiveawayPrizeStars) String() string {
if g == nil {
return "GiveawayPrizeStars(nil)"
}
type Alias GiveawayPrizeStars
return fmt.Sprintf("GiveawayPrizeStars%+v", Alias(*g))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*GiveawayPrizeStars) TypeID() uint32 {
return GiveawayPrizeStarsTypeID
}
// TypeName returns name of type in TL schema.
func (*GiveawayPrizeStars) TypeName() string {
return "giveawayPrizeStars"
}
// TypeInfo returns info about TL type.
func (g *GiveawayPrizeStars) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "giveawayPrizeStars",
ID: GiveawayPrizeStarsTypeID,
}
if g == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "StarCount",
SchemaName: "star_count",
},
}
return typ
}
// Encode implements bin.Encoder.
func (g *GiveawayPrizeStars) Encode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode giveawayPrizeStars#954c1fa4 as nil")
}
b.PutID(GiveawayPrizeStarsTypeID)
return g.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (g *GiveawayPrizeStars) EncodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode giveawayPrizeStars#954c1fa4 as nil")
}
b.PutInt53(g.StarCount)
return nil
}
// Decode implements bin.Decoder.
func (g *GiveawayPrizeStars) Decode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode giveawayPrizeStars#954c1fa4 to nil")
}
if err := b.ConsumeID(GiveawayPrizeStarsTypeID); err != nil {
return fmt.Errorf("unable to decode giveawayPrizeStars#954c1fa4: %w", err)
}
return g.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (g *GiveawayPrizeStars) DecodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode giveawayPrizeStars#954c1fa4 to nil")
}
{
value, err := b.Int53()
if err != nil {
return fmt.Errorf("unable to decode giveawayPrizeStars#954c1fa4: field star_count: %w", err)
}
g.StarCount = value
}
return nil
}
// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GiveawayPrizeStars) EncodeTDLibJSON(b tdjson.Encoder) error {
if g == nil {
return fmt.Errorf("can't encode giveawayPrizeStars#954c1fa4 as nil")
}
b.ObjStart()
b.PutID("giveawayPrizeStars")
b.Comma()
b.FieldStart("star_count")
b.PutInt53(g.StarCount)
b.Comma()
b.StripComma()
b.ObjEnd()
return nil
}
// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GiveawayPrizeStars) DecodeTDLibJSON(b tdjson.Decoder) error {
if g == nil {
return fmt.Errorf("can't decode giveawayPrizeStars#954c1fa4 to nil")
}
return b.Obj(func(b tdjson.Decoder, key []byte) error {
switch string(key) {
case tdjson.TypeField:
if err := b.ConsumeID("giveawayPrizeStars"); err != nil {
return fmt.Errorf("unable to decode giveawayPrizeStars#954c1fa4: %w", err)
}
case "star_count":
value, err := b.Int53()
if err != nil {
return fmt.Errorf("unable to decode giveawayPrizeStars#954c1fa4: field star_count: %w", err)
}
g.StarCount = value
default:
return b.Skip()
}
return nil
})
}
// GetStarCount returns value of StarCount field.
func (g *GiveawayPrizeStars) GetStarCount() (value int64) {
if g == nil {
return
}
return g.StarCount
}
// GiveawayPrizeClassName is schema name of GiveawayPrizeClass.
const GiveawayPrizeClassName = "GiveawayPrize"
// GiveawayPrizeClass represents GiveawayPrize generic type.
//
// Example:
//
// g, err := tdapi.DecodeGiveawayPrize(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tdapi.GiveawayPrizePremium: // giveawayPrizePremium#1b12e978
// case *tdapi.GiveawayPrizeStars: // giveawayPrizeStars#954c1fa4
// default: panic(v)
// }
type GiveawayPrizeClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() GiveawayPrizeClass
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
TypeID() uint32
// TypeName returns name of type in TL schema.
TypeName() string
// String implements fmt.Stringer.
String() string
// Zero returns true if current object has a zero value.
Zero() bool
EncodeTDLibJSON(b tdjson.Encoder) error
DecodeTDLibJSON(b tdjson.Decoder) error
}
// DecodeGiveawayPrize implements binary de-serialization for GiveawayPrizeClass.
func DecodeGiveawayPrize(buf *bin.Buffer) (GiveawayPrizeClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case GiveawayPrizePremiumTypeID:
// Decoding giveawayPrizePremium#1b12e978.
v := GiveawayPrizePremium{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode GiveawayPrizeClass: %w", err)
}
return &v, nil
case GiveawayPrizeStarsTypeID:
// Decoding giveawayPrizeStars#954c1fa4.
v := GiveawayPrizeStars{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode GiveawayPrizeClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode GiveawayPrizeClass: %w", bin.NewUnexpectedID(id))
}
}
// DecodeTDLibJSONGiveawayPrize implements binary de-serialization for GiveawayPrizeClass.
func DecodeTDLibJSONGiveawayPrize(buf tdjson.Decoder) (GiveawayPrizeClass, error) {
id, err := buf.FindTypeID()
if err != nil {
return nil, err
}
switch id {
case "giveawayPrizePremium":
// Decoding giveawayPrizePremium#1b12e978.
v := GiveawayPrizePremium{}
if err := v.DecodeTDLibJSON(buf); err != nil {
return nil, fmt.Errorf("unable to decode GiveawayPrizeClass: %w", err)
}
return &v, nil
case "giveawayPrizeStars":
// Decoding giveawayPrizeStars#954c1fa4.
v := GiveawayPrizeStars{}
if err := v.DecodeTDLibJSON(buf); err != nil {
return nil, fmt.Errorf("unable to decode GiveawayPrizeClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode GiveawayPrizeClass: %w", tdjson.NewUnexpectedID(id))
}
}
// GiveawayPrize boxes the GiveawayPrizeClass providing a helper.
type GiveawayPrizeBox struct {
GiveawayPrize GiveawayPrizeClass
}
// Decode implements bin.Decoder for GiveawayPrizeBox.
func (b *GiveawayPrizeBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode GiveawayPrizeBox to nil")
}
v, err := DecodeGiveawayPrize(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.GiveawayPrize = v
return nil
}
// Encode implements bin.Encode for GiveawayPrizeBox.
func (b *GiveawayPrizeBox) Encode(buf *bin.Buffer) error {
if b == nil || b.GiveawayPrize == nil {
return fmt.Errorf("unable to encode GiveawayPrizeClass as nil")
}
return b.GiveawayPrize.Encode(buf)
}
// DecodeTDLibJSON implements bin.Decoder for GiveawayPrizeBox.
func (b *GiveawayPrizeBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
if b == nil {
return fmt.Errorf("unable to decode GiveawayPrizeBox to nil")
}
v, err := DecodeTDLibJSONGiveawayPrize(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.GiveawayPrize = v
return nil
}
// EncodeTDLibJSON implements bin.Encode for GiveawayPrizeBox.
func (b *GiveawayPrizeBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
if b == nil || b.GiveawayPrize == nil {
return fmt.Errorf("unable to encode GiveawayPrizeClass as nil")
}
return b.GiveawayPrize.EncodeTDLibJSON(buf)
}