Documentation
¶
Overview ¶
Package tl implements TL schema parser and writer.
TL ("Type Language") is used in MTProto, Telegram binary protocol.
See https://core.telegram.org/mtproto/TL for reference.
Index ¶
Constants ¶
const ( // AnnotationDescription is description of definition or class. AnnotationDescription = "description" // AnnotationClass is annotation for class. AnnotationClass = "class" // AnnotationParamDescription is annotation for parameter named "description". AnnotationParamDescription = "param_description" )
Common values for Annotation.Name.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotation ¶
type Annotation struct {
// Name of annotation.
//
// Can be:
// * "description" if Value is class or definition description
// * "class" if Value is class name, like //@class Foo @description Foo class
// * "param_description" if Value is description for "description" parameter
// Otherwise, it is description of Name parameter.
Name string `json:"name"`
// Value of annotation. Can be description or class name if Name is "class".
Value string `json:"value"`
}
Annotation represents an annotation comment, like //@name value.
func (Annotation) String ¶
func (a Annotation) String() string
type Category ¶
type Category byte
Category of Definition.
func (Category) MarshalText ¶
func (*Category) UnmarshalText ¶
type Class ¶
Class describes a non-bare Type with one or more constructors.
Example: `//@class InputChatPhoto @description Describes input chat photo`.
type Definition ¶
type Definition struct {
Namespace []string `json:"namespace,omitempty"` // blank if global
Name string `json:"name"` // name of definition, aka "predicate" or "method"
ID uint32 `json:"id"` // crc32(definition) or explicitly specified
Params []Parameter `json:"params,omitempty"` // can be empty
Type Type `json:"type"` // type of definition
Base bool `json:"base,omitempty"` // base type?
GenericParams []string `json:"generic_params,omitempty"` // like {T:Type}
}
Definition represents "Type Language" definition.
See https://core.telegram.org/mtproto/TL for reference.
func (*Definition) Parse ¶
func (d *Definition) Parse(line string) error
Parse TL definition line like `foo#123 code:int name:string = Message;`.
func (Definition) String ¶
func (d Definition) String() string
type Flag ¶
type Flag struct {
// Name of the parameter.
Name string `json:"name"`
// Index represent bit index.
Index int `json:"index"`
}
Flag describes conditional parameter.
type Parameter ¶
type Parameter struct {
// Name of Parameter.
Name string `json:"name,omitempty"`
// Type of Parameter.
Type Type `json:"type"`
// Flag specifies flag name and index if parameter is conditional.
Flag *Flag `json:"flag,omitempty"`
// Flags denotes whether Parameter is flags field (uint32).
//
// If true, Type and Flag are blank.
Flags bool `json:"flags,omitempty"`
// contains filtered or unexported fields
}
Parameter with Name and Type.
func (Parameter) Conditional ¶
type Schema ¶
type Schema struct {
Layer int `json:"layer,omitempty"`
Definitions []SchemaDefinition `json:"definitions"`
Classes []Class `json:"classes,omitempty"`
}
Schema represents single TL file with information about definitions and so called "Classes" aka non-bare types with one or multiple constructors.
type SchemaDefinition ¶
type SchemaDefinition struct {
Annotations []Annotation `json:"annotations,omitempty"` // annotations (comments)
Definition Definition `json:"definition"` // definition
Category Category `json:"category"` // category of definition (function or type)
}
SchemaDefinition is annotated Definition with Category.
type Type ¶
type Type struct {
Namespace []string `json:"namespace,omitempty"` // namespace components of the type
Name string `json:"name,omitempty"` // the name of the type
Bare bool `json:"bare,omitempty"` // whether this type is bare or boxed
Percent bool `json:"-"` // whether this type has percent in name (like %Message)
GenericRef bool `json:"generic_ref,omitempty"` // whether the type name refers to a generic definition
GenericArg *Type `json:"generic_arg,omitempty"` // generic arguments of the type
}
Type of a Definition or a Parameter.