Documentation ¶
Overview ¶
Package bin implements binary serialization and deserialization for TL, providing Buffer that can decode and encode basic Type Language types.
This package is not intended to be used directly.
Ref:
Index ¶
- Constants
- func NewUnexpectedID(id uint32) error
- type BareDecoder
- type BareEncoder
- type Buffer
- func (b *Buffer) Bool() (bool, error)
- func (b *Buffer) Bytes() ([]byte, error)
- func (b *Buffer) ConsumeID(id uint32) error
- func (b *Buffer) ConsumeN(target []byte, n int) error
- func (b *Buffer) Copy() []byte
- func (b *Buffer) Decode(d Decoder) error
- func (b *Buffer) Double() (float64, error)
- func (b *Buffer) Encode(e Encoder) error
- func (b *Buffer) Expand(n int)
- func (b *Buffer) ID() (uint32, error)
- func (b *Buffer) Int() (int, error)
- func (b *Buffer) Int128() (Int128, error)
- func (b *Buffer) Int256() (Int256, error)
- func (b *Buffer) Int32() (int32, error)
- func (b Buffer) Len() int
- func (b *Buffer) Long() (int64, error)
- func (b *Buffer) PeekID() (uint32, error)
- func (b *Buffer) PeekN(target []byte, n int) error
- func (b *Buffer) Put(raw []byte)
- func (b *Buffer) PutBool(v bool)
- func (b *Buffer) PutBytes(v []byte)
- func (b *Buffer) PutDouble(v float64)
- func (b *Buffer) PutID(id uint32)
- func (b *Buffer) PutInt(v int)
- func (b *Buffer) PutInt128(v Int128)
- func (b *Buffer) PutInt256(v Int256)
- func (b *Buffer) PutInt32(v int32)
- func (b *Buffer) PutLong(v int64)
- func (b *Buffer) PutString(s string)
- func (b *Buffer) PutUint16(v uint16)
- func (b *Buffer) PutUint32(v uint32)
- func (b *Buffer) PutUint64(v uint64)
- func (b *Buffer) PutVectorHeader(length int)
- func (b Buffer) Raw() []byte
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) Reset()
- func (b *Buffer) ResetN(n int)
- func (b *Buffer) ResetTo(buf []byte)
- func (b *Buffer) Skip(n int)
- func (b *Buffer) String() (string, error)
- func (b *Buffer) Uint32() (uint32, error)
- func (b *Buffer) Uint64() (uint64, error)
- func (b *Buffer) VectorHeader() (int, error)
- type Decoder
- type Encoder
- type Fields
- type Int128
- type Int256
- type InvalidLengthError
- type Object
- type Pool
- type UnexpectedIDErr
Constants ¶
const ( TypeIntID = 0xa8509bda // int = Int (0xa8509bda) TypeLongID = 0x22076cba // long = Long (0x22076cba) TypeDoubleID = 0x2210c154 // double = Double (0x2210c154) TypeStringID = 0xb5286e24 // string = String (0xb5286e24) TypeVector = 0x1cb5c415 // vector {t:Type} # [ t ] = Vector t TypeBytes = 0xe937bb82 // bytes#e937bb82 = Bytes TypeTrue = 0x997275b5 // boolTrue#997275b5 = Bool TypeFalse = 0xbc799737 // boolFalse#bc799737 = Bool )
Basic TL types.
const PreallocateLimit = 1024
PreallocateLimit is a vector pre-allocation limit.
const Word = 4
Word represents 4-byte sequence. Values in TL are generally aligned to Word.
Variables ¶
This section is empty.
Functions ¶
func NewUnexpectedID ¶
NewUnexpectedID return new UnexpectedIDErr.
Types ¶
type BareDecoder ¶ added in v0.30.0
BareDecoder can decode it's binary form from Buffer. BareEncoder is like Encoder, but decodes object as bare.
type BareEncoder ¶ added in v0.30.0
BareEncoder can encode it's binary form to Buffer. BareEncoder is like Encoder, but encodes object as bare.
type Buffer ¶
type Buffer struct {
Buf []byte
}
Buffer implements low level binary (de-)serialization for TL.
func (*Buffer) Bytes ¶
Bytes decodes byte slice from Buffer.
NB: returning value is a copy, it's safe to modify it.
func (*Buffer) ConsumeID ¶
ConsumeID decodes type id from Buffer. If id differs from provided, the *UnexpectedIDErr{ID: gotID} will be returned and buffer will be not consumed.
func (*Buffer) ConsumeN ¶
ConsumeN consumes n bytes from buffer, writing them to target.
Returns io.ErrUnexpectedEOF if buffer contains less that n bytes. Expects that len(target) >= n.
func (*Buffer) PeekN ¶ added in v0.12.0
PeekN returns n bytes from Buffer to target, but does not consume it.
Returns io.ErrUnexpectedEOF if buffer contains less that n bytes. Expects that len(target) >= n.
func (*Buffer) PutInt ¶
PutInt serializes v as signed 32-bit integer.
If v is bigger than 32-bit, `behavior` is undefined.
func (*Buffer) PutVectorHeader ¶
PutVectorHeader serializes vector header with provided length.
func (*Buffer) ResetTo ¶
ResetTo sets internal buffer exactly to provided value.
Buffer will retain buf, so user should not modify or read it concurrently.
func (*Buffer) VectorHeader ¶
VectorHeader decodes vector length from Buffer.
type Fields ¶
type Fields uint32
Fields represent a bitfield value that compactly encodes information about provided conditional fields, e.g. says that fields "1", "5" and "10" were set.
type Int128 ¶
type Int128 [16]byte
Int128 represents signed 128-bit integer.
type Int256 ¶
type Int256 [32]byte
Int256 represents signed 256-bit integer.
type InvalidLengthError ¶ added in v0.50.0
InvalidLengthError is returned when decoder reads invalid length.
func (*InvalidLengthError) Error ¶ added in v0.50.0
func (i *InvalidLengthError) Error() string
type Pool ¶ added in v0.23.0
type Pool struct {
// contains filtered or unexported fields
}
Pool is a bin.Buffer pool.
type UnexpectedIDErr ¶
type UnexpectedIDErr struct {
ID uint32
}
UnexpectedIDErr means that unknown or unexpected type id was decoded.
func (*UnexpectedIDErr) Error ¶
func (e *UnexpectedIDErr) Error() string