tlmodel

package
v0.0.0-...-988111e Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VectorCrc32Hex = "1cb5c415"
	VectorCrc32    = 0x1cb5c415 // 481674261

	BoolFalseCrc32Hex = "bc799737"
	BoolFalseCrc32    = 0xbc799737 // 3161706375

	BoolTrueCrc32Hex = "997275b5"
	BoolTrueCrc32    = 0x997275b5 // 2574592005
)

Variables

View Source
var (
	ErrLayerNotFound         = fmt.Errorf("layer not found")
	ErrCrc32HexNotFound      = fmt.Errorf("crc32Hex not found")
	ErrTypeNameNotFound      = fmt.Errorf("typeName not found")
	ErrInputTypeNotTLSubType = fmt.Errorf("input type not TLSubType")
	ErrInputTypeNil          = fmt.Errorf("input type is nil")

	DecodeErrDataTooShort      = fmt.Errorf("decode: data too short")
	DecodeErrCrc32HexNotMatch  = fmt.Errorf("decode: crc32Hex not match")
	DecodeErrUnknownVectorSize = fmt.Errorf("decode: unknown vector size")
)
View Source
var SubTypeCrc32Map = make(map[int32]map[string]string) // layer -> typeName -> crc32Hex
View Source
var SubTypeMap = make(map[int32]map[string]*SubType) // layer -> crc32Hex -> SubType
View Source
var TypeMap = make(map[int32]map[string]*Type) // layer -> typeName -> Type

Functions

func CalcCrc32

func CalcCrc32(line string) uint32

Types

type Decoder

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

func NewDecoder

func NewDecoder(layer int32, buf []byte) *Decoder

func (*Decoder) Bool

func (d *Decoder) Bool() bool

func (*Decoder) Bytes

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

func (*Decoder) Decode

func (d *Decoder) Decode() *TLObject

func (*Decoder) Double

func (d *Decoder) Double() float64

func (*Decoder) Error

func (d *Decoder) Error() error

func (*Decoder) GetOffset

func (d *Decoder) GetOffset() int

func (*Decoder) GetSize

func (d *Decoder) GetSize() int

func (*Decoder) Int

func (d *Decoder) Int() int32

func (*Decoder) Long

func (d *Decoder) Long() int64

func (*Decoder) SetError

func (d *Decoder) SetError(err error)

func (*Decoder) String

func (d *Decoder) String() string

func (*Decoder) UInt

func (d *Decoder) UInt() uint32

func (*Decoder) VectorBytes

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

func (*Decoder) VectorDecode

func (d *Decoder) VectorDecode() []*TLObject

func (*Decoder) VectorDouble

func (d *Decoder) VectorDouble() []float64

func (*Decoder) VectorInt

func (d *Decoder) VectorInt() []int32

func (*Decoder) VectorLong

func (d *Decoder) VectorLong() []int64

func (*Decoder) VectorString

func (d *Decoder) VectorString() []string

type Encoder

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

func NewEncoder

func NewEncoder(layer int32) *Encoder

func (*Encoder) Bytes

func (e *Encoder) Bytes(s []byte)

func (*Encoder) BytesVector

func (e *Encoder) BytesVector(v [][]byte)

func (*Encoder) Double

func (e *Encoder) Double(v float64)

func (*Encoder) Encode

func (e *Encoder) Encode(
	line string,
	values any,
) ([]byte, error)

Encode 编码 layer: 层级 line: 一行,或crc32Hex Values: 参数,可以是[]any,也可以是map[string]any

func (*Encoder) Int

func (e *Encoder) Int(v int32)

func (*Encoder) IntVector

func (e *Encoder) IntVector(v []int32)

func (*Encoder) Long

func (e *Encoder) Long(v int64)

func (*Encoder) LongVector

func (e *Encoder) LongVector(v []int64)

func (*Encoder) String

func (e *Encoder) String(v string)

func (*Encoder) StringVector

func (e *Encoder) StringVector(v []string)

func (*Encoder) UInt

func (e *Encoder) UInt(v uint32)

func (*Encoder) VectorDouble

func (e *Encoder) VectorDouble(v []float64)

func (*Encoder) VectorFlag

func (e *Encoder) VectorFlag(length uint32)

type Optional

type Optional struct {
	IsOptional bool
	FlagsName  string // flags / flags2 / flags3 ...
	FlagIndex  int    // 0 / 1 / 2 ...
}

type SubType

type SubType struct {
	SubTypeName string
	Crc32Hex    string
	Params      []*TypeParam
	TypeName    string
}

type TLObject

type TLObject struct {
	SubTypeName string
	Crc32Hex    string
	Values      map[string]any
}

func (*TLObject) GetBool

func (o *TLObject) GetBool(key string) bool

func (*TLObject) GetBytes

func (o *TLObject) GetBytes(key string) []byte

func (*TLObject) GetBytesSlice

func (o *TLObject) GetBytesSlice(key string) [][]byte

func (*TLObject) GetFloat64

func (o *TLObject) GetFloat64(key string) (float64, bool)

func (*TLObject) GetFloat64Slice

func (o *TLObject) GetFloat64Slice(key string) []float64

func (*TLObject) GetInt32

func (o *TLObject) GetInt32(key string) (int32, bool)

func (*TLObject) GetInt32Slice

func (o *TLObject) GetInt32Slice(key string) []int32

func (*TLObject) GetInt64

func (o *TLObject) GetInt64(key string) (int64, bool)

func (*TLObject) GetInt64Slice

func (o *TLObject) GetInt64Slice(key string) []int64

func (*TLObject) GetString

func (o *TLObject) GetString(key string) (string, bool)

func (*TLObject) GetStringSlice

func (o *TLObject) GetStringSlice(key string) []string

func (*TLObject) GetTLObject

func (o *TLObject) GetTLObject(key string) (*TLObject, bool)

func (*TLObject) GetTLObjectSlice

func (o *TLObject) GetTLObjectSlice(key string) []*TLObject

func (*TLObject) GetUInt32

func (o *TLObject) GetUInt32(key string) (uint32, bool)

func (*TLObject) GetUInt32Slice

func (o *TLObject) GetUInt32Slice(key string) []uint32

func (*TLObject) GetUInt64

func (o *TLObject) GetUInt64(key string) (uint64, bool)

func (*TLObject) GetUInt64Slice

func (o *TLObject) GetUInt64Slice(key string) []uint64

type TLSubType

type TLSubType struct {
	Line string
	Args any
}

type Type

type Type struct {
	SubTypes []*SubType
	TypeName string
}

type TypeParam

type TypeParam struct {
	ParamName     string
	ParamTypeName string
	Optional      *Optional
	IsFlags       bool
	IsVector      bool
}

Jump to

Keyboard shortcuts

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