tl

package
v0.0.0-...-0eaabd3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WordLen   = 4           // Size of a word in TL (32 bits)
	LongLen   = WordLen * 2 // int64 occupies 8 bytes
	DoubleLen = WordLen * 2 // float64 occupies 8 bytes
	Int128Len = WordLen * 4 // int128 occupies 16 bytes
	Int256Len = WordLen * 8 // int256 occupies 32 bytes

	// Magic Numbers
	MaxArrayElements = 0xfe // Maximum number of elements that can be encoded in an array

	MagicNumber = 0xfe // 254

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

Variables

This section is empty.

Functions

func BigIntBytes

func BigIntBytes(v *big.Int, bitsize int) []byte

func Decode

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

func Marshal

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

func RandomBytes

func RandomBytes(size int) []byte

func RegisterEnums

func RegisterEnums(enums ...Object)

func RegisterObjects

func RegisterObjects(obs ...Object)

func Sha1

func Sha1(input string) []byte

func Sha1Byte

func Sha1Byte(input []byte) []byte

func UnwrapNativeTypes

func UnwrapNativeTypes(in Object) any

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, error)

NewDecoder returns a new decoder that reads from r.

Note: The decoder cannot work with partial data. The entire input must be read before decoding can begin.

func (*Decoder) DumpWithoutRead

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

func (*Decoder) ExpectTypesInInterface

func (d *Decoder) ExpectTypesInInterface(types ...reflect.Type)

ExpectTypesInInterface defines how the decoder should parse implicit objects.

How `expectedTypes` works:

Imagine you want to parse a `[]int32`, but you might also receive `[]int64`, `SomeCustomType`, or even `[][]bool`. How do you handle this?

`expectedTypes` stores your predictions. For example, if you encounter an unknown type, it will parse it as `int32` instead of `int64`.

If you have predictions deeper than the first unknown type, you can tell the decoder to use those predicted values.

So, next time you have a structure with an `interface{}` field that expects to contain `[]float64` or similar, use this feature via `d.ExpectTypesInInterface()`.

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 be called after encoding has been finished. If this function returns a non-nil value, the encoding has failed, and the resulting data should not be used.

func (*Encoder) PutBool

func (e *Encoder) PutBool(v bool)

PutBool is a very specific type. Since there are separate constructors for true and false, they can be considered as two CRC constants.

func (*Encoder) PutCRC

func (e *Encoder) PutCRC(v uint32)

PutCRC is an alias for Encoder.PutUint. It is used for better code readability and self-documentation.

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(b []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 ErrMustParseSlicesExplicitly

type ErrMustParseSlicesExplicitly struct{}

func (*ErrMustParseSlicesExplicitly) Error

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 DecodeUnknownObject

func DecodeUnknownObject(data []byte, expectNextTypes ...reflect.Type) (Object, error)

type PseudoFalse

type PseudoFalse struct{}

PseudoFalse is a support struct which is required to get native

func (*PseudoFalse) CRC

func (*PseudoFalse) CRC() uint32

type PseudoNil

type PseudoNil struct{}

func (*PseudoNil) CRC

func (*PseudoNil) CRC() uint32

func (*PseudoNil) Unwrap

func (*PseudoNil) Unwrap() any

you won't use it, right?

type PseudoTrue

type PseudoTrue struct{}

PseudoTrue is a support struct which is required to get native

func (*PseudoTrue) CRC

func (*PseudoTrue) CRC() uint32

type Tag

type Tag struct {
	// Key is the tag key, such as json, xml, etc..
	// i.e: `json:"foo,omitempty". Here key is: "json"
	Key string

	// Name is a part of the value
	// i.e: `json:"foo,omitempty". Here name is: "foo"
	Name string

	// Options is a part of the value. It contains a slice of tag options i.e:
	// `json:"foo,omitempty". Here options is: ["omitempty"]
	Options []string
}

Tag defines a single struct's string literal tag

type Tags

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

Tags represent a set of tags from a single struct field

func (*Tags) Get

func (t *Tags) Get(key string) (*Tag, error)

Get returns the tag associated with the given key. If the key is present in the tag the value (which may be empty) is returned. Otherwise the returned value will be the empty string. The ok return value reports whether the tag exists or not (which the return value is nil).

func (*Tags) Set

func (t *Tags) Set(tag *Tag) error

Set sets the given tag. If the tag key already exists it'll override it

type Unmarshaler

type Unmarshaler interface {
	UnmarshalTL(*Decoder) error
}

type WrappedSlice

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

WrappedSlice is pseudo type. YOU SHOULD NOT use it customly, instead, you must encode/decode value by encoder.PutVector or decoder.PopVector

func (*WrappedSlice) CRC

func (*WrappedSlice) CRC() uint32

func (*WrappedSlice) Unwrap

func (w *WrappedSlice) Unwrap() any

Jump to

Keyboard shortcuts

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