/tl

⚡️ Native and ultrafast TL parser for your integrations!

Primary LanguageGoMIT LicenseMIT

TypeLang


Full native implementation of TL serializing language. Simple and fast.

english русский

🤔 What is it?

TL is a serialization format, created by Telegram and TON devs. This format slightly looks like Protobuf, but has a lot of exotic differences, which creates some issues with working about this format. This package solve a lot of stuff and handle 90% of your routine, related to serialization (and trust me, this routine could be a pain, that's why we created xelaj/tl).

✨ Features

  • Probably the best golang package for parsing TL schemas
  • Auto code generation of implementation your spec
  • Supports TL-B for TON Blockchain
  • And many many more 😲

👨‍💻 How to use

Here are some usage cases, how you can do some stuff:

Basic usage

package main

import "github.com/xelaj/tl"

type RepoUser struct {
    _       struct{} `tl:"someBitflag,bitflag"`
    Nick    string
    Creator bool `tl:",omitempty:someBitflag:0,implicit"`
    Editor  bool `tl:",omitempty:someBitflag:7,implicit"`
}

func (c *RepoUser) CRC() uint32 { return 0x12345678 }

func main() {
    tl.RegisterObjects((*RepoUser)(nil))

    response := &RepoUser{
        Nick:    "Hello user!",
        Creator: true,
        Editor:  true,
    }

    println(tl.Marshal(response))
    // And boom! 💥 You have decoded object!
}

Run in playground

Run codegen

🔘 $ brew install tlgen

     Processing... Done!

🟢 $ cat schema.tl | tlgen generate \
        --package-name="github.com/username/tonlib" \
        --output="./path/to/generate" \
        --file-prefix="tl" \      # ➡ tl_stuff_gen.go or tl_gen.go
        --split-files             # ➡ split by 4 files depend on object type

🟢 $ ls ./path/to/generate

     drwxr-xr-x+   4 username  staff   3.3K Oct 11 2049 .
     drwxr-xr-x  104 username  staff   224B Oct 11 2049 ..
     -rw-rw-r--    4 username  staff   4.1K Oct 11 2049 tl_enums_gen.go
     -rw-rw-r--    4 username  staff   900B Oct 11 2049 tl_init_gen.go
     -rw-rw-r--    4 username  staff   1.8K Oct 11 2049 tl_interfaces_gen.go
     -rw-rw-r--    4 username  staff   3.2K Oct 11 2049 tl_methods_gen.go

🟢 $ # Tadah! You have multiple files, but you can combine them into single one!

View demo

Parse messages without codegen

TODO

Something else

Code examples are here

Full docs are here

⌚️ Getting started

TODO

Why TL serializing is SO ugly?

Well... Read this issue about TON source code, when it was released first time. Remember: current TON developers are absolutely another guys. Use google translate, this issue will answer to all your questions.

Telegram devs are really strange

🤔 Differences between TL and TL-B

Вы наверняка заметили, что логотип этого проекта это на самом деле два логотипа — telegram и ton. Однако, формат в ton обратно несовместим с тем же форматом в telegram. При этом, между ними очень много общего, поэтому вцелом довольно реально объеденить оба формата в одну библиотеку. При этом, в отличии от разработчиков telegram, разработчики ton более благосклонны к кооперации, так что вполне возможно, что поддержка ton будет даже более качественной

🦊 Who use it

💎 Contributing

Please read contributing guide if you want to help. And the help is very necessary!

Don't want code? Read this page! We love nocoders!

🐛 Security bugs?

Please, don't create issue which describes security bug, this can be too offensive! Instead, please read this notification and follow that steps to notify us about problem.

🏋️ TODO

  • Full implementation of Tl serializing
  • Tool to generate golang code
  • Write amazing docs
  • Create full toolset to support TL
  • make support of TL-B (incompatible version, used by TON)
  • Write RFC specification?
  • write good security policy
  • setup taskfile for markdown linter

📒 Running project scripts

This project uses go-task, it's not important to understand, what's going on, (since you can just see into Taskfile.yaml and see all commands). For better experience, you can download go-task and run tasks e.g. via $ task <taskname>. All tasks can be shown via $ task --list-all

👨‍👩‍👧‍👦 Authors

📝 License

This project is licensed under the MIT License - see the LICENSE file for details

Если вы находитесь в россии, или как-либо связаны с российским правительством, (например, являетесь российским налогоплательщиком) на вас распостраняется отдельная лицензия.

One important thing

Even that maintainers of this project are generally from russia, we still stand up with Ukraine, and from beginning of war, decided to stop paying any taxes, or cooperate in any case with government, and companies, connected with government. This is absolutely nothing compared to how much pain putin brought to the fraternal country. And we are responsible for our inaction, and the only thing we can do is to take at least any actions that harm putin’s regime, and help the victims of regime using all resources available for us.


Created with love 💜 and magic 🦄
Xelaj Software, 2022-2024