ton_net_tl/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2026 Nirapod Labs
3
4// A library that decodes bytes from a peer it does not trust must fail by returning, not
5// by unwinding: a panic in a decoder is a denial of service in whatever process embedded
6// it. The lints sit on the library because a test is the opposite case, where an unwrap
7// is the assertion. Arithmetic is deliberately not in the set: every count these formats
8// carry is bounded before it is used, and each subtraction sits within a few lines of the
9// guard that makes it safe, so denying it would bury the real bounds under checked_sub.
10#![deny(
11 clippy::unwrap_used,
12 clippy::expect_used,
13 clippy::panic,
14 clippy::unreachable,
15 clippy::todo,
16 clippy::indexing_slicing
17)]
18
19//! TL codec for ton-net: TON's Type Language wire format.
20//!
21//! This crate defines the TON TL types the client reads and writes, derived over
22//! [`tl_proto`], and re-exports the serialize and deserialize entry points. It
23//! covers the ADNL message envelope ([`adnl`]), the liteserver query and response
24//! types ([`lite`]), and the messages a validator signature covers ([`signed`]).
25//! It performs no I/O, and it checks nothing: a decoded response is the server's
26//! word until `ton-net-block` verifies it.
27//!
28//! A boxed type carries a four-byte constructor id: the CRC32-IEEE of its TL scheme
29//! line, written little-endian on the wire. A bare type, used only as a field of
30//! another type, carries none. Both are handled by the [`tl_proto`] derives, so a
31//! caller serializes and deserializes typed values and never touches the tags.
32//!
33//! # Example
34//!
35//! ```
36//! use ton_net_tl::lite::GetMasterchainInfo;
37//!
38//! // A nullary boxed request serializes to exactly its constructor id.
39//! let bytes = ton_net_tl::serialize(GetMasterchainInfo);
40//! assert_eq!(bytes, [0x2e, 0xe6, 0xb5, 0x89]);
41//! ```
42//!
43//! It is an internal crate of the ton-net client. Most consumers use the `ton-net`
44//! facade rather than this crate directly.
45#![forbid(unsafe_code)]
46#![warn(missing_docs)]
47#![deny(rustdoc::broken_intra_doc_links)]
48
49pub mod adnl;
50pub mod lite;
51pub mod signed;
52
53#[doc(no_inline)]
54pub use tl_proto::{deserialize, serialize, TlError, TlRead, TlResult, TlWrite};
55
56// The README ships to crates.io and cannot be replaced once a version is published,
57// so its examples are compiled here rather than trusted. Doc-only: this does not
58// appear in the rendered documentation.
59#[cfg(doctest)]
60#[doc = include_str!("../README.md")]
61struct Readme;