Giter VIP home page Giter VIP logo

tlo's Introduction

Type Language Object

Reader of binary serialized Type Language Schema

Example of result in the end of reading TLO

Python

demo python

JavaScript/TypeScript

demo javascript

Declaimer

This code has not been tested sufficiently. It's a rewritten version of original reader in C++. If you are going to use this for code generation, please do additional tests. Recheck my implementation for errors and so on.

Context

The Type Language (TL) was invented many years ago. It was originally used in VK, and now in Telegram. The creators of this language invented and wrote all the necessary tools to work with it. For example, a parser of the language and its binary format for serialization was developed.

What is this for?

To work with TL Schemes using OOP. To generate the client MTProto code using official TL parsers and binary formats.

Many Open Source MTProto client use their own implementation of parsers, which are not ultimatum. They are hardcoded for their minimal task.

Hardcode is not the way of Telegram. Official Telegram's Open Source projects take the right approach. So, for example, tdlib generates several interfaces for different languages and this is how it looks:

Raw TL Schema -> Tl Parser -> binary TL Object -> TLO reader -> code generator.

Step name Description
Raw TL Schema Can be founded here and in official Telegram repositories of client (tdesktop/Telegram/Resources/tl, tdlib/generate/scheme).
Tl Parser Official TL parser written in C++. Now it's a part of tdlib/td/generate/tl-parser. In the input it takes raw TL schema file. The output is TLO file.
binary TL Object The output of Tl Parser.
TLO reader This repository contains implementation of it in Python and JavaScript. Reader of binary file. Provide access to combinators, types, functions, arguments and so on via Object Oriented Programming.
code generator Any code generator. In tdlib/td/generate there is generator for C++, JNI, .NET and JSON interfaces.

Installing

For Python

pip install tlo

For JavaScript/TypeScript

npm install tlo

Usage

You can find TLO files for tests here.

Python (3.6+)

from tlo import read_tl_config_from_file, read_tl_config


# use read_tl_config(data) to pass bytes directly
config = read_tl_config_from_file('td_api.tlo')

JavaScript/TypeScript

const tlo = require('tlo');
//import {read_tl_config_from_file, read_tl_config} from 'tlo';

// use read_tl_config(data) to pass buffer directly
tlo.read_tl_config_from_file('./tlo_for_tests/telegram_api.tlo', (config) => {
    console.log(config);
});

Licence

MIT License

tlo's People

Contributors

marshalx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.