tdjson

package
v0.0.0-...-5942ca8 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tdjson contains some helpers to use jx with TL objects.

Index

Constants

View Source
const TypeField = "@type"

TypeField is a type field name.

Variables

View Source
var ErrTypeIDNotFound = errors.New("@type field is expected, but not found")

ErrTypeIDNotFound means that @type field is expected, but not found.

Functions

func NewUnexpectedID

func NewUnexpectedID(id string) error

NewUnexpectedID return new UnexpectedIDError.

Types

type Decoder

type Decoder struct {
	*jx.Decoder
}

Decoder is a simple wrapper around jx.Decoder to conform TL type system.

func (Decoder) Arr

func (b Decoder) Arr(cb func(d Decoder) error) error

Arr decodes array and invokes callback on each array element.

func (Decoder) Bool

func (b Decoder) Bool() (bool, error)

Bool deserializes boolean.

func (Decoder) Bytes

func (b Decoder) Bytes() ([]byte, error)

Bytes deserializes bare byte string.

func (Decoder) ConsumeID

func (b Decoder) ConsumeID(id string) error

ConsumeID deserializes given typeID.

func (Decoder) Double

func (b Decoder) Double() (float64, error)

Double deserializes 64-bit floating point.

func (Decoder) FindTypeID

func (b Decoder) FindTypeID() (string, error)

FindTypeID tries to find @type field or returns error.

func (Decoder) ID

func (b Decoder) ID() (string, error)

ID deserializes given typeID.

func (Decoder) Int

func (b Decoder) Int() (int, error)

Int deserializes signed 32-bit integer.

func (Decoder) Int128

func (b Decoder) Int128() (bin.Int128, error)

Int128 deserializes 128-bit signed integer.

func (Decoder) Int256

func (b Decoder) Int256() (bin.Int256, error)

Int256 deserializes 256-bit signed integer.

func (Decoder) Int32

func (b Decoder) Int32() (int32, error)

Int32 deserializes signed 32-bit integer.

func (Decoder) Int53

func (b Decoder) Int53() (int64, error)

Int53 deserializes int53.

func (Decoder) Long

func (b Decoder) Long() (int64, error)

Long deserializes int64.

func (Decoder) Obj

func (b Decoder) Obj(cb func(d Decoder, key []byte) error) error

Obj calls f for every key in object, using byte slice as key.

The key value is valid only until f is not returned.

func (Decoder) String

func (b Decoder) String() (string, error)

String deserializes bare string.

func (Decoder) Uint16

func (b Decoder) Uint16() (uint16, error)

Uint16 deserializes unsigned 16-bit integer.

func (Decoder) Uint32

func (b Decoder) Uint32() (uint32, error)

Uint32 deserializes unsigned 32-bit integer.

func (Decoder) Uint64

func (b Decoder) Uint64() (uint64, error)

Uint64 deserializes unsigned 64-bit integer.

type Encoder

type Encoder struct {
	*jx.Writer
}

Encoder is a simple wrapper around jx.Encoder to conform TL type system.

func (Encoder) PutBool

func (b Encoder) PutBool(v bool)

PutBool serializes boolean.

func (Encoder) PutBytes

func (b Encoder) PutBytes(v []byte)

PutBytes serializes bare byte string.

func (Encoder) PutDouble

func (b Encoder) PutDouble(v float64)

PutDouble serializes v as 64-bit floating point.

func (Encoder) PutID

func (b Encoder) PutID(typeID string)

PutID serializes given typeID.

func (Encoder) PutInt

func (b Encoder) PutInt(v int)

PutInt serializes v as signed 32-bit integer.

func (Encoder) PutInt128

func (b Encoder) PutInt128(v bin.Int128)

PutInt128 serializes v as 128-bit signed integer.

func (Encoder) PutInt256

func (b Encoder) PutInt256(v bin.Int256)

PutInt256 serializes v as 256-bit signed integer.

func (Encoder) PutInt32

func (b Encoder) PutInt32(v int32)

PutInt32 serializes signed 32-bit integer.

func (Encoder) PutInt53

func (b Encoder) PutInt53(v int64)

PutInt53 serializes v as int53.

func (Encoder) PutLong

func (b Encoder) PutLong(v int64)

PutLong serializes v as int64.

func (Encoder) PutString

func (b Encoder) PutString(s string)

PutString serializes bare string.

func (Encoder) PutUint16

func (b Encoder) PutUint16(v uint16)

PutUint16 serializes unsigned 16-bit integer.

func (Encoder) PutUint32

func (b Encoder) PutUint32(v uint32)

PutUint32 serializes unsigned 32-bit integer.

func (Encoder) PutUint64

func (b Encoder) PutUint64(v uint64)

PutUint64 serializes v as unsigned 64-bit integer.

func (Encoder) StripComma

func (b Encoder) StripComma()

StripComma deletes last comma, if any.

Useful for code generation to avoid last field/element tracking.

type TDLibDecoder

type TDLibDecoder interface {
	DecodeTDLibJSON(Decoder) error
}

TDLibDecoder represents TDLib JSON API decoder.

type TDLibEncoder

type TDLibEncoder interface {
	EncodeTDLibJSON(Encoder) error
}

TDLibEncoder represents TDLib JSON API encoder.

type UnexpectedIDError

type UnexpectedIDError struct {
	ID string
}

UnexpectedIDError means that unknown or unexpected type id was decoded.

func (*UnexpectedIDError) Error

func (e *UnexpectedIDError) Error() string

Jump to

Keyboard shortcuts

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