Documentation
¶
Index ¶
- Constants
- Variables
- func GetFieldTypeFromGoType(t reflect.Type) fieldType
- func Marshal(v any) ([]byte, error)
- func RegisterCustom[T Object](r *ObjectRegistry, constructor func(uint32) T, crcs ...uint32)
- func RegisterCustomDefault[T Object](constructor func(uint32) T, crcs ...uint32)
- func RegisterEnum[T Object](r *ObjectRegistry, enums ...T)
- func RegisterEnumDefault[T Object](enums ...T)
- func RegisterObject[T Object](r *ObjectRegistry)
- func RegisterObjectDefault[T Object]()
- func Unmarshal(b []byte, res any) error
- type Bitflag
- type BitflagBit
- type Decoder
- type ErrInvalidBoolCRC
- type ErrInvalidCRC
- type ErrObjectNotRegistered
- type ErrPartialWrite
- type ErrPath
- type ErrRegisteredObjectNotFound
- type ErrUnsupportedType
- type Int128
- type Int256
- type MarshalState
- type Marshaler
- type Object
- type ObjectRegistry
- type RealEncoder
- type Registry
- type StructTag
- type UnmarshalState
- type Unmarshaler
Constants ¶
const ( ErrUnexpectedNil = errorConst("unexpected nil value") ErrImplicitInt = errorConst("value must be converted to int32, int64 or uint32 explicitly") ErrBitflagTooHigh = errorConst("trigger bit is more than 32") ErrImplicitNoTarget = errorConst(implicitFlag + " defined without target field to trigger") ErrImplicitBitflag = errorConst("'" + implicitFlag + "' and '" + isBitflagFlag + "' can't be combined") ErrTagNameEmpty = errorConst("tag name is empty") ErrInvalidTagOption = errorConst("invalid option") ErrInvalidTagFormat = errorConst("invalid tag format") ErrTypeIsEmpty = errorConst("tl field type is empty") )
const ( MapCrcKey = "_crc" MapTypeKey = "_type" WordLen = 32 / bitsInByte // length of word in tl is 32 bits LongLen = 64 / bitsInByte // int64 size in bytes DoubleLen = 64 / bitsInByte // float64 size in bytes Int128Len = 128 / bitsInByte // int128 size in bytes Int256Len = 256 / bitsInByte // int256 size in bytes )
Variables ¶
var ( BitflagType = fieldBitflags{} ImplicitBoolType = fieldImplicitBool{} )
Functions ¶
func GetFieldTypeFromGoType ¶
func RegisterCustom ¶
func RegisterCustom[T Object](r *ObjectRegistry, constructor func(uint32) T, crcs ...uint32)
func RegisterCustomDefault ¶
func RegisterEnum ¶
func RegisterEnum[T Object](r *ObjectRegistry, enums ...T)
func RegisterEnumDefault ¶
func RegisterEnumDefault[T Object](enums ...T)
func RegisterObject ¶
func RegisterObject[T Object](r *ObjectRegistry)
func RegisterObjectDefault ¶
func RegisterObjectDefault[T Object]()
Types ¶
type BitflagBit ¶
type Decoder ¶
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
func NewDecoderWithSize ¶
NewDecoderWithSize works absolutely like NewDecoder, but it sets buffer with size that you want. It could be useful, when you want to debug serialized data. You can combine this constructor with DumpWithoutRead method, which returns all data, until cache of bufio will be full, or until reader reach end of file.
To make correct cache, in most of cases, you will get length of all serialized message. pass this length and few more bytes (50-60 bytes will be enough). Note that DumpWithoutRead can't guarantee to be stable, so use it only for debugging.
type ErrInvalidBoolCRC ¶
type ErrInvalidBoolCRC crc32
func (ErrInvalidBoolCRC) Error ¶
func (e ErrInvalidBoolCRC) Error() string
type ErrInvalidCRC ¶
type ErrInvalidCRC struct { Got crc32 Want crc32 }
func (ErrInvalidCRC) Error ¶
func (e ErrInvalidCRC) Error() string
type ErrObjectNotRegistered ¶
type ErrObjectNotRegistered crc32
func (ErrObjectNotRegistered) Error ¶
func (e ErrObjectNotRegistered) Error() string
type ErrPartialWrite ¶
func (ErrPartialWrite) Error ¶
func (e ErrPartialWrite) Error() string
type ErrRegisteredObjectNotFound ¶
func (ErrRegisteredObjectNotFound) Error ¶
func (e ErrRegisteredObjectNotFound) Error() string
type ErrUnsupportedType ¶
func (ErrUnsupportedType) Error ¶
func (e ErrUnsupportedType) Error() string
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 ¶
func (i *Int128) MarshalTL(s MarshalState) 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(s UnmarshalState) 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 ¶
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 ¶
func (i *Int256) MarshalTL(s MarshalState) 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(s UnmarshalState) error
UnmarshalTL implements tl unmarshaler from this package. Just don't use it by your hands, tl.Decoder does all what you need.
type MarshalState ¶
type MarshalState interface { // if object will write bytes the size of which is not divided by the length // of the word, it will throw specific error io.Writer PutBool(bool) error PutInt(int32) error PutLong(int64) error PutCRC(crc32) error PutMessage([]byte) error }
MarshalState provides set of different methods to marshal binary message into specific struct. It's working absolutely like fmt.State, you just need to write data to this abstraction.
type Marshaler ¶
type Marshaler interface {
MarshalTL(MarshalState) error
}
type Object ¶
type Object interface {
CRC() crc32
}
Object is default interface, which ANY struct must implement to decode it in tl format.
type ObjectRegistry ¶
type ObjectRegistry struct {
// contains filtered or unexported fields
}
ObjectRegistry is a type, which handles code generated schema, and could be useful for spawning TL objects. Unlike RawSchemaRegistry, it can work only with predefined go types.
If you are not able to use codegen, use RawSchemaRegistry, it could be slower, but more flexible.
func DefaultRegistry ¶
func DefaultRegistry() *ObjectRegistry
func NewRegistry ¶
func NewRegistry() *ObjectRegistry
func (*ObjectRegistry) ConstructObject ¶
func (r *ObjectRegistry) ConstructObject(crc crc32) (Object, bool)
ConstructObject spawns new object by crc code from registry.
type RealEncoder ¶
func NewEncoder ¶
func NewEncoder(w io.Writer) RealEncoder
type StructTag ¶
func ParseStructTags ¶
func ParseStructTags(s Object) ([]StructTag, map[int]BitflagBit, error)
func ParseTag ¶
ParseTag is a function which parses struct field tag for structes, defined by you.
- `tag` parameter is a text representation of struct field tag.
- `defaultName` is a name of struct field, if it's not defined in tag.
how tag could look:
// field named somefield, it could be empty, value is boolean, so it can // be encoded implicitly, value stored in some_flag value `tl:"somefield,omitempty:some_flag:3,implicit"` // value is abcd, it's required to exist in serialized `tl:"abcd"`
type UnmarshalState ¶
type UnmarshalState interface { // ReadWords reads words from unmarshaler with fixed size of word. io.Reader ReadAll() ([]byte, error) Peek(seek, size int) ([]byte, error) SkipBytes(int) PopBool() (bool, error) PopInt() (int32, error) PopLong() (int64, error) PopCRC() (crc32, error) PopMessage() ([]byte, error) }
type Unmarshaler ¶
type Unmarshaler interface {
UnmarshalTL(UnmarshalState) error
}