Telegram TL v0.0.3-alpha TL

This library allows you to serialize and deserialize elements of the TL Language. It was originally designed to be used by telegram-mt-elixir.

Summary

Functions

Deserialize an object given its type. Available types

Serialize an object given its type. Available types

Functions

build(container, content)

Build a TL object. See core.telegram.org/schema/mtproto and core.telegram.org/schema.

Example

iex> TL.build "ping", %{:ping_id => 666}
<<236, 119, 190, 122, 154, 2, 0, 0, 0, 0, 0, 0>>
deserialize(data, type)

Deserialize an object given its type. Available types :

  • :meta32
  • :meta64
  • :int
  • :int64
  • :int128
  • :int256
  • :long
  • :float
  • :string
  • :bytes
  • :vector @TODO
  • :boxed @TODO

Example

iex(12)> TL.deserialize(<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 91, 205, 21>>, :int128)
123456789
parse(container, content)

Decode a TL object. See core.telegram.org/schema/mtproto and core.telegram.org/schema.

Examples

iex> TL.parse 0x7abe77ec, <<154, 2, 0, 0, 0, 0, 0, 0>>
{%{name: "ping", ping_id: 666}, ""}

iex> TL.parse 0x7abe77ec, <<154, 2, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4>>
{%{name: "ping", ping_id: 666}, <<1, 2, 3, 4>>}
serialize(data, type)

Serialize an object given its type. Available types :

  • :meta32
  • :meta64
  • :int
  • :int64
  • :int128
  • :int256
  • :long
  • :float
  • :string
  • :bytes
  • :vector NOT_YET_IMPLEMENTED

Examples

iex> TL.serialize(123456789, :int128)
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 91, 205, 21>>

iex> TL.serialize("Hello world!", :string)
<<12, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33, 0, 0, 0>>