Documentation ¶
Index ¶
- Constants
- func BigIntBytes(v *big.Int, bitsize int) []byte
- func Decode(data []byte, res any) error
- func Marshal(v any) ([]byte, error)
- func RandomBytes(size int) []byte
- func RegisterEnums(enums ...Object)
- func RegisterObjects(obs ...Object)
- func Sha1(input string) []byte
- func Sha1Byte(input []byte) []byte
- func UnwrapNativeTypes(in Object) any
- type Decoder
- func (d *Decoder) DumpWithoutRead() ([]byte, error)
- func (d *Decoder) ExpectTypesInInterface(types ...reflect.Type)
- func (d *Decoder) GetRestOfMessage() ([]byte, error)
- func (d *Decoder) PopBool() bool
- func (d *Decoder) PopCRC() uint32
- func (d *Decoder) PopDouble() float64
- func (d *Decoder) PopInt() int32
- func (d *Decoder) PopLong() int64
- func (d *Decoder) PopMessage() []byte
- func (d *Decoder) PopNull()
- func (d *Decoder) PopRawBytes(size int) []byte
- func (d *Decoder) PopUint() uint32
- func (d *Decoder) PopVector(as reflect.Type) any
- type Encoder
- func (e *Encoder) CheckErr() error
- func (e *Encoder) PutBool(v bool)
- func (e *Encoder) PutCRC(v uint32)
- func (e *Encoder) PutDouble(v float64)
- func (e *Encoder) PutInt(v int32)
- func (e *Encoder) PutLong(v int64)
- func (e *Encoder) PutMessage(msg []byte)
- func (e *Encoder) PutRawBytes(b []byte)
- func (e *Encoder) PutString(msg string)
- func (e *Encoder) PutUint(v uint32)
- func (e *Encoder) PutVector(v any)
- type ErrMustParseSlicesExplicitly
- type ErrRegisteredObjectNotFound
- type ErrorPartialWrite
- type FlagIndexGetter
- type Int128
- type Int256
- type Marshaler
- type Object
- type PseudoFalse
- type PseudoNil
- type PseudoTrue
- type Tag
- type Tags
- type Unmarshaler
- type WrappedSlice
Constants ¶
const ( WordLen = 4 LongLen = WordLen * 2 // int64 DoubleLen = WordLen * 2 // float64 Int128Len = WordLen * 4 // int128 Int256Len = WordLen * 8 // int256 MagicNumber = 0xfe // 253 // 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 RandomBytes ¶
func RegisterEnums ¶
func RegisterEnums(enums ...Object)
func RegisterObjects ¶
func RegisterObjects(obs ...Object)
func UnwrapNativeTypes ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes TL values from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r. Unfortunately, decoder can't work with part of data, so reader must be read all before decoding.
func (*Decoder) DumpWithoutRead ¶
func (*Decoder) ExpectTypesInInterface ¶
ExpectTypesInInterface defines, how decoder must parse implicit objects. how does expectedTypes works: So, imagine: you want parse []int32, but also you can get []int64, or SomeCustomType, or even [][]bool. How to deal it? expectedTypes store your predictions (like "if you got unknown type, parse it as int32, not int64") also, if you have predictions deeper than first unknown type, you can say decoder to use predicted vals
So, next time, when you'll have strucre object with interface{} which expect contains []float64 or sort of — use this feature via d.ExpectTypesInInterface()
func (*Decoder) GetRestOfMessage ¶
func (*Decoder) PopMessage ¶
func (*Decoder) PopRawBytes ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func (*Encoder) CheckErr ¶
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 ¶
PutBool very specific type, т.к. There is a separate constructor under true and false, then we can calculate that these are two crc constants
func (*Encoder) PutCRC ¶
PutCRC is an alias for Encoder.PutUint. It uses only for understanding what your code do (like self-documented code)
func (*Encoder) PutMessage ¶
func (*Encoder) PutRawBytes ¶
type ErrMustParseSlicesExplicitly ¶
type ErrMustParseSlicesExplicitly struct{}
func (*ErrMustParseSlicesExplicitly) Error ¶
func (e *ErrMustParseSlicesExplicitly) Error() string
type ErrRegisteredObjectNotFound ¶
func (*ErrRegisteredObjectNotFound) Error ¶
func (e *ErrRegisteredObjectNotFound) Error() string
type ErrorPartialWrite ¶
func (*ErrorPartialWrite) Error ¶
func (e *ErrorPartialWrite) Error() string
type FlagIndexGetter ¶
type FlagIndexGetter interface {
FlagIndex() int
}
type Int128 ¶
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 (*Int128) MarshalTL ¶
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 ¶
UnmarshalTL implements tl unmarshaler from this package. Just don't use it by your hands, tl.Decoder does all what you need
type Int256 ¶
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 (*Int256) MarshalTL ¶
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 ¶
UnmarshalTL implements tl unmarshaler from this package. Just don't use it by your hands, tl.Decoder does all what you need
type PseudoFalse ¶
type PseudoFalse struct{}
PseudoFalse is a support struct which is required to get native
func (*PseudoFalse) CRC ¶
func (*PseudoFalse) CRC() uint32
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
type Unmarshaler ¶
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