tl

package
v0.0.0-...-7028a79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WordLen   = 4           // размер слова в TL (32 бита)
	LongLen   = WordLen * 2 // int64 8 байт занимает
	DoubleLen = WordLen * 2 // float64 8 байт занимает
	Int128Len = WordLen * 4 // int128 16 байт
	Int256Len = WordLen * 8 // int256 32 байт

	// Блядские магические числа
	FuckingMagicNumber = 0xfe // 253 элемента максимум можно закодировать в массиве элементов

	// https://core.telegram.org/schema/mtproto
	CrcVector = 0x1cb5c415
	CrcFalse  = 0xbc799737
	CrcTrue   = 0x997275b5
	CrcNull   = 0x56730bcc
)

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, v any) error

func Marshal

func Marshal(v any) ([]byte, error)

func RegisterEnums

func RegisterEnums(enums ...Object)

func RegisterObjects

func RegisterObjects(obs ...Object)

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes TL values from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) DumpWithoutRead

func (d *Decoder) DumpWithoutRead() ([]byte, error)

func (*Decoder) GetRestOfMessage

func (d *Decoder) GetRestOfMessage() ([]byte, error)

func (*Decoder) PopBool

func (d *Decoder) PopBool() bool

func (*Decoder) PopCRC

func (d *Decoder) PopCRC() uint32

func (*Decoder) PopDouble

func (d *Decoder) PopDouble() float64

func (*Decoder) PopInt

func (d *Decoder) PopInt() int32

func (*Decoder) PopLong

func (d *Decoder) PopLong() int64

func (*Decoder) PopMessage

func (d *Decoder) PopMessage() []byte

func (*Decoder) PopNull

func (d *Decoder) PopNull()

func (*Decoder) PopRawBytes

func (d *Decoder) PopRawBytes(size int) []byte

func (*Decoder) PopUint

func (d *Decoder) PopUint() uint32

func (*Decoder) PopVector

func (d *Decoder) PopVector(as reflect.Type) any

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) CheckErr

func (e *Encoder) CheckErr() error

CheckErr must call after encoding has been finished. if this func returns not nil value, encoding has failed, and you shouldn't use its result

func (*Encoder) PutBool

func (e *Encoder) PutBool(v bool)

PutBool очень специфичный тип, т.к. есть отдельный конструктор под true и false, то можно считать, что это две crc константы

func (*Encoder) PutCRC

func (e *Encoder) PutCRC(v uint32)

PutCRC is an alias for Encoder.PutUint. It uses only for understanding what your code do (like self-documented code)

func (*Encoder) PutDouble

func (e *Encoder) PutDouble(v float64)

func (*Encoder) PutInt

func (e *Encoder) PutInt(v int32)

func (*Encoder) PutLong

func (e *Encoder) PutLong(v int64)

func (*Encoder) PutMessage

func (e *Encoder) PutMessage(msg []byte)

func (*Encoder) PutRawBytes

func (e *Encoder) PutRawBytes(b []byte)

func (*Encoder) PutString

func (e *Encoder) PutString(msg string)

func (*Encoder) PutUint

func (e *Encoder) PutUint(v uint32)

func (*Encoder) PutVector

func (e *Encoder) PutVector(v any)

type ErrRegisteredObjectNotFound

type ErrRegisteredObjectNotFound struct {
	Crc  uint32
	Data []byte
}

func (ErrRegisteredObjectNotFound) Error

type ErrorPartialWrite

type ErrorPartialWrite struct {
	Has  int
	Want int
}

func (*ErrorPartialWrite) Error

func (e *ErrorPartialWrite) Error() string

type FlagIndexGetter

type FlagIndexGetter interface {
	FlagIndex() int
}

type Int128

type Int128 struct {
	*big.Int
}

Int128 is alias-like type for fixed size of big int (1024 bit value). It using only for tl objects encoding cause native big.Int isn't supported for en(de)coding

func NewInt128

func NewInt128() *Int128

NewInt128 creates int128 with zero value

func RandomInt128

func RandomInt128() *Int128

NewInt128 creates int128 with random value

func (*Int128) MarshalTL

func (i *Int128) MarshalTL(e *Encoder) error

MarshalTL implements tl marshaler from this package. Just don't use it by your hands, tl.Encoder does all what you need

func (*Int128) UnmarshalTL

func (i *Int128) UnmarshalTL(d *Decoder) error

UnmarshalTL implements tl unmarshaler from this package. Just don't use it by your hands, tl.Decoder does all what you need

type Int256

type Int256 struct {
	*big.Int
}

Int256 is alias-like type for fixed size of big int (2048 bit value). It using only for tl objects encoding cause native big.Int isn't supported for en(de)coding

func NewInt256

func NewInt256() *Int256

NewInt256 creates int256 with zero value

func RandomInt256

func RandomInt256() *Int256

NewInt256 creates int256 with random value

func (*Int256) MarshalTL

func (i *Int256) MarshalTL(e *Encoder) error

MarshalTL implements tl marshaler from this package. Just don't use it by your hands, tl.Encoder does all what you need

func (*Int256) UnmarshalTL

func (i *Int256) UnmarshalTL(d *Decoder) error

UnmarshalTL implements tl unmarshaler from this package. Just don't use it by your hands, tl.Decoder does all what you need

type Marshaler

type Marshaler interface {
	MarshalTL(*Encoder) error
}

type Object

type Object interface {
	CRC() uint32
}

func DecodeRegistered

func DecodeRegistered(data []byte) (Object, error)

type Unmarshaler

type Unmarshaler interface {
	UnmarshalTL(*Decoder) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL