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

218 lines
4.8 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{}
)
// TestVectorInt represents TL type `testVectorInt#df9eb113`.
type TestVectorInt struct {
// Vector of numbers
Value []int32
}
// TestVectorIntTypeID is TL type id of TestVectorInt.
const TestVectorIntTypeID = 0xdf9eb113
// Ensuring interfaces in compile-time for TestVectorInt.
var (
_ bin.Encoder = &TestVectorInt{}
_ bin.Decoder = &TestVectorInt{}
_ bin.BareEncoder = &TestVectorInt{}
_ bin.BareDecoder = &TestVectorInt{}
)
func (t *TestVectorInt) Zero() bool {
if t == nil {
return true
}
if !(t.Value == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (t *TestVectorInt) String() string {
if t == nil {
return "TestVectorInt(nil)"
}
type Alias TestVectorInt
return fmt.Sprintf("TestVectorInt%+v", Alias(*t))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*TestVectorInt) TypeID() uint32 {
return TestVectorIntTypeID
}
// TypeName returns name of type in TL schema.
func (*TestVectorInt) TypeName() string {
return "testVectorInt"
}
// TypeInfo returns info about TL type.
func (t *TestVectorInt) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "testVectorInt",
ID: TestVectorIntTypeID,
}
if t == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Value",
SchemaName: "value",
},
}
return typ
}
// Encode implements bin.Encoder.
func (t *TestVectorInt) Encode(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't encode testVectorInt#df9eb113 as nil")
}
b.PutID(TestVectorIntTypeID)
return t.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (t *TestVectorInt) EncodeBare(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't encode testVectorInt#df9eb113 as nil")
}
b.PutInt(len(t.Value))
for _, v := range t.Value {
b.PutInt32(v)
}
return nil
}
// Decode implements bin.Decoder.
func (t *TestVectorInt) Decode(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't decode testVectorInt#df9eb113 to nil")
}
if err := b.ConsumeID(TestVectorIntTypeID); err != nil {
return fmt.Errorf("unable to decode testVectorInt#df9eb113: %w", err)
}
return t.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (t *TestVectorInt) DecodeBare(b *bin.Buffer) error {
if t == nil {
return fmt.Errorf("can't decode testVectorInt#df9eb113 to nil")
}
{
headerLen, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode testVectorInt#df9eb113: field value: %w", err)
}
if headerLen > 0 {
t.Value = make([]int32, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := b.Int32()
if err != nil {
return fmt.Errorf("unable to decode testVectorInt#df9eb113: field value: %w", err)
}
t.Value = append(t.Value, value)
}
}
return nil
}
// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (t *TestVectorInt) EncodeTDLibJSON(b tdjson.Encoder) error {
if t == nil {
return fmt.Errorf("can't encode testVectorInt#df9eb113 as nil")
}
b.ObjStart()
b.PutID("testVectorInt")
b.Comma()
b.FieldStart("value")
b.ArrStart()
for _, v := range t.Value {
b.PutInt32(v)
b.Comma()
}
b.StripComma()
b.ArrEnd()
b.Comma()
b.StripComma()
b.ObjEnd()
return nil
}
// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (t *TestVectorInt) DecodeTDLibJSON(b tdjson.Decoder) error {
if t == nil {
return fmt.Errorf("can't decode testVectorInt#df9eb113 to nil")
}
return b.Obj(func(b tdjson.Decoder, key []byte) error {
switch string(key) {
case tdjson.TypeField:
if err := b.ConsumeID("testVectorInt"); err != nil {
return fmt.Errorf("unable to decode testVectorInt#df9eb113: %w", err)
}
case "value":
if err := b.Arr(func(b tdjson.Decoder) error {
value, err := b.Int32()
if err != nil {
return fmt.Errorf("unable to decode testVectorInt#df9eb113: field value: %w", err)
}
t.Value = append(t.Value, value)
return nil
}); err != nil {
return fmt.Errorf("unable to decode testVectorInt#df9eb113: field value: %w", err)
}
default:
return b.Skip()
}
return nil
})
}
// GetValue returns value of Value field.
func (t *TestVectorInt) GetValue() (value []int32) {
if t == nil {
return
}
return t.Value
}