Skip to main content

Crate layer

Crate layer 

Source
Expand description

§layer: Telegram MTProto library

layer is a modular Rust library for the Telegram MTProto protocol. It consists of four focused sub-crates wired together here for convenience:

Sub-crateRole
layer-tl-parserParse .tl schema files into an AST
layer-tl-genGenerate Rust source from the AST (build-time)
layer-tl-typesAuto-generated types, functions & enums
layer-mtprotoSession state, message framing, transport traits

§Quick start: raw API

use layer::tl::{functions, Serializable, RemoteCall};
use layer::mtproto::{Session, transport::AbridgedTransport};

// Build a raw TL request
let req = functions::help::GetConfig {};
let bytes = req.to_bytes();

// Pack it into an MTProto message
let mut session = Session::new();
let msg = session.pack(&req);
let wire = msg.to_plaintext_bytes();

// Send over your transport…

§Updating the API layer

Replace layer-tl-types/tl/api.tl with the new schema and run cargo build. Everything else regenerates automatically.

Re-exports§

pub use layer_tl_types as tl;
pub use layer_mtproto as mtproto;
pub use layer_crypto as crypto;
pub use layer_tl_parser as parser;parser
pub use layer_tl_gen as codegen;codegen

Modules§

authentication
Sans-IO MTProto authorization key generation.

Structs§

AuthKey
A Telegram authorization key (256 bytes) plus pre-computed identifiers.
EncryptedSession
MTProto 2.0 encrypted session state.
Finished
The final output of a successful auth key handshake.
Session
Tracks per-connection MTProto session state.

Constants§

LAYER
The API layer this code was generated from.

Traits§

Deserializable
Deserialize a value from TL binary format.
Identifiable
Every generated type has a unique 32-bit constructor ID.
RemoteCall
Marks a function type that can be sent to Telegram as an RPC call.
Serializable
Serialize self into TL binary format.

Functions§

finish
Finalise the handshake.
step1
Generate a req_pq_multi request. Returns the request + opaque state.
step2
Process ResPQ and generate req_DH_params.
step3
Process ServerDhParams into a reusable DhParamsForRetry + send the first set_client_DH_params request.