miniproto_native::tl
Provenance
Section titled “Provenance”- Crate:
miniproto_native - Rust visibility:
crate - Source:
rust/miniproto/src/tl.rs - Python exposure: Not evidenced by static PyO3 attributes.
Documented items
Section titled “Documented items”miniproto_native::tl::registerminiproto_native::tl::tl_fast_encodeminiproto_native::tl::tl_fast_decodeminiproto_native::tl::tl_encode_intminiproto_native::tl::tl_decode_intminiproto_native::tl::tl_encode_uintminiproto_native::tl::tl_decode_uintminiproto_native::tl::tl_encode_longminiproto_native::tl::tl_decode_longminiproto_native::tl::tl_encode_int128miniproto_native::tl::tl_decode_int128miniproto_native::tl::tl_encode_int256miniproto_native::tl::tl_decode_int256miniproto_native::tl::tl_encode_doubleminiproto_native::tl::tl_decode_doubleminiproto_native::tl::tl_encode_bytesminiproto_native::tl::tl_decode_bytesminiproto_native::tl::tl_encode_stringminiproto_native::tl::tl_decode_stringminiproto_native::tl::tl_encode_int_vectorminiproto_native::tl::tl_decode_int_vectorminiproto_native::tl::tl_encode_long_vectorminiproto_native::tl::tl_decode_long_vector
cargo-docs-md rendering
Section titled “cargo-docs-md rendering”miniproto_native / tl
Module tl
Section titled “Module tl”Registers primitive and generated fast-path TL codec callables. Native primitive and generated fast-path codecs for Telegram’s Type Language (TL).
The primitive Python-visible tl_* functions mirror the pure-Python fallback API. In contrast,
tl_fast_encode and tl_fast_decode are native-only optional accelerators: Python callers
receive None when a selected generated fast path is unavailable and use their fallback path.
They return ValueError or MemoryError for malformed wire input or failed allocation, release
the GIL only for large primitive-vector work, and do not expose unsafe Rust operations.
Incompatible Python-to-Rust values instead fail during PyO3 conversion with its original
TypeError, OverflowError, or source exception before these algorithms run.
generated_tl.rs is trusted, build-time-generated metadata consumed—not hand-maintained—by
this module. Descriptor indices and bit positions are code-generation invariants rather than
values validated on every hot-path call.
Contents
Section titled “Contents”- Structs
- Enums
- Functions
registertl_fast_encode__pyfunction_tl_fast_encodetl_fast_decode__pyfunction_tl_fast_decodeencode_fast_valuedecode_fast_valuedecode_message_containerappend_tl_bytesdecode_tl_bytes_slicetl_encode_int__pyfunction_tl_encode_inttl_decode_int__pyfunction_tl_decode_inttl_encode_uint__pyfunction_tl_encode_uinttl_decode_uint__pyfunction_tl_decode_uinttl_encode_long__pyfunction_tl_encode_longtl_decode_long__pyfunction_tl_decode_longtl_encode_int128__pyfunction_tl_encode_int128tl_decode_int128__pyfunction_tl_decode_int128tl_encode_int256__pyfunction_tl_encode_int256tl_decode_int256__pyfunction_tl_decode_int256tl_encode_double__pyfunction_tl_encode_doubletl_decode_double__pyfunction_tl_decode_doubletl_encode_bytes__pyfunction_tl_encode_bytestl_decode_bytes__pyfunction_tl_decode_bytestl_encode_string__pyfunction_tl_encode_stringtl_decode_string__pyfunction_tl_decode_stringtl_encode_int_vector__pyfunction_tl_encode_int_vectortl_decode_int_vector__pyfunction_tl_decode_int_vectortl_encode_long_vector__pyfunction_tl_encode_long_vectortl_decode_long_vector__pyfunction_tl_decode_long_vectorread_sliceread_fixedencode_tl_bytesdecode_tl_bytespy_int_to_le_bytespy_int_from_le_bytesencode_i32_vectordecode_i32_vectorencode_i64_vectordecode_i64_vectordecode_vector_layoutnormalize_vector_offsetvalidate_vector_allocationchecked_vector_capacity
- Constants
Quick Reference
Section titled “Quick Reference”| Item | Kind | Description |
|---|---|---|
FastConstructorSpec | struct | Generated metadata for one selected TL constructor fast path. |
FastWireType | enum | Wire representation supported by the generated fast-constructor codec. |
FastFieldSpec | enum | One generated field action used to encode or decode a fast TL constructor. |
register | fn | Registers the fallback-compatible tl_* Python functions on miniproto._native. |
tl_fast_encode | fn | Attempts Python tl_fast_encode for a generated constructor. |
__pyfunction_tl_fast_encode | fn | |
tl_fast_decode | fn | Attempts Python tl_fast_decode for a generated constructor at offset. |
__pyfunction_tl_fast_decode | fn | |
encode_fast_value | fn | Appends one generated field value to a fast-path TL output buffer. |
decode_fast_value | fn | Decodes one generated field from data, advancing cursor and creating a Python value. |
decode_message_container | fn | Decodes an MTProto message-container field into a Python tuple of (id, seq_no, body) tuples. |
append_tl_bytes | fn | Encodes and appends a bounded TL bytes value, reserving its output atomically. |
decode_tl_bytes_slice | fn | Borrows one padded TL bytes payload and returns it with its next aligned offset. |
tl_encode_int | fn | Encodes Python tl_encode_int(value) as a four-byte little-endian signed integer. |
__pyfunction_tl_encode_int | fn | |
tl_decode_int | fn | Decodes Python tl_decode_int(data, offset) and returns (value, next_offset) or ValueError. |
__pyfunction_tl_decode_int | fn | |
tl_encode_uint | fn | Encodes Python tl_encode_uint(value) as a four-byte little-endian unsigned integer. |
__pyfunction_tl_encode_uint | fn | |
tl_decode_uint | fn | Decodes Python tl_decode_uint(data, offset) and returns (value, next_offset) or ValueError. |
__pyfunction_tl_decode_uint | fn | |
tl_encode_long | fn | Encodes Python tl_encode_long(value) as an eight-byte little-endian signed integer. |
__pyfunction_tl_encode_long | fn | |
tl_decode_long | fn | Decodes Python tl_decode_long(data, offset) and returns (value, next_offset) or ValueError. |
__pyfunction_tl_decode_long | fn | |
tl_encode_int128 | fn | Encodes Python tl_encode_int128(value) to 16 little-endian bytes via int.to_bytes. |
__pyfunction_tl_encode_int128 | fn | |
tl_decode_int128 | fn | Decodes Python tl_decode_int128(data, offset) to a Python integer and next offset. |
__pyfunction_tl_decode_int128 | fn | |
tl_encode_int256 | fn | Encodes Python tl_encode_int256(value) to 32 little-endian bytes via int.to_bytes. |
__pyfunction_tl_encode_int256 | fn | |
tl_decode_int256 | fn | Decodes Python tl_decode_int256(data, offset) to a Python integer and next offset. |
__pyfunction_tl_decode_int256 | fn | |
tl_encode_double | fn | Encodes Python tl_encode_double(value) as eight IEEE-754 little-endian bytes. |
__pyfunction_tl_encode_double | fn | |
tl_decode_double | fn | Decodes Python tl_decode_double(data, offset) and returns (value, next_offset) or ValueError. |
__pyfunction_tl_decode_double | fn | |
tl_encode_bytes | fn | Encodes Python tl_encode_bytes(value) with TL’s short/long length prefix and zero padding. |
__pyfunction_tl_encode_bytes | fn | |
tl_decode_bytes | fn | Decodes Python tl_decode_bytes(data, offset) and returns bytes plus the next aligned offset. |
__pyfunction_tl_decode_bytes | fn | |
tl_encode_string | fn | Encodes Python tl_encode_string(value) as UTF-8 TL bytes. |
__pyfunction_tl_encode_string | fn | |
tl_decode_string | fn | Decodes Python tl_decode_string(data, offset) as UTF-8 and returns it with the next offset. |
__pyfunction_tl_decode_string | fn | |
tl_encode_int_vector | fn | Encodes Python tl_encode_int_vector(values) as a generic TL vector of 32-bit integers. |
__pyfunction_tl_encode_int_vector | fn | |
tl_decode_int_vector | fn | Decodes Python tl_decode_int_vector(data, offset) into values and a next offset. |
__pyfunction_tl_decode_int_vector | fn | |
tl_encode_long_vector | fn | Encodes Python tl_encode_long_vector(values) as a generic TL vector of 64-bit integers. |
__pyfunction_tl_encode_long_vector | fn | |
tl_decode_long_vector | fn | Decodes Python tl_decode_long_vector(data, offset) into values and a next offset. |
__pyfunction_tl_decode_long_vector | fn | |
read_slice | fn | Borrows length bytes at offset from a TL buffer. |
read_fixed | fn | Reads an exactly N-byte TL field at offset. |
encode_tl_bytes | fn | Serializes bytes with the TL short/long length prefix and zero alignment padding. |
decode_tl_bytes | fn | Parses and copies one padded TL bytes value, returning it and its next aligned offset. |
py_int_to_le_bytes | fn | Calls Python int.to_bytes(width, "little") for fixed-width unsigned TL integer fields. |
py_int_from_le_bytes | fn | Calls Python int.from_bytes(bytes, "little") while holding the supplied GIL token. |
encode_i32_vector | fn | Serializes signed 32-bit values as a generic boxed TL vector. |
decode_i32_vector | fn | Decodes a generic TL vector of signed 32-bit values at offset. |
encode_i64_vector | fn | Serializes signed 64-bit values as a generic boxed TL vector. |
decode_i64_vector | fn | Decodes a generic TL vector of signed 64-bit values at offset. |
decode_vector_layout | fn | Validates a generic vector header and returns its count, payload start, and next offset. |
normalize_vector_offset | fn | Converts the Python-facing signed offset to a safe Rust index. |
validate_vector_allocation | fn | Checks that a decoded vector’s requested allocation fits the platform’s isize limit. |
checked_vector_capacity | fn | Computes encoder capacity including the eight-byte TL vector header. |
TL_VECTOR_CONSTRUCTOR_ID | const | Constructor identifier serialized before every generic TL Vector. |
MAX_TL_BYTES_LENGTH | const | Largest byte-string payload representable by TL’s three-byte long length prefix. |
Structs
Section titled “Structs”FastConstructorSpec
Section titled “FastConstructorSpec”struct FastConstructorSpec { constructor_id: u32, name: &'static str, encode: bool, decode: bool, value_count: usize, fields: &'static [FastFieldSpec],}Defined in rust/miniproto/src/tl.rs:80-93
Generated metadata for one selected TL constructor fast path.
Fields
Section titled “Fields”-
constructor_id:u32Constructor id serialized for boxed values.
-
name:&'static strGenerated schema name used in validation errors.
-
encode:boolWhether this constructor has a native encoder.
-
decode:boolWhether this constructor has a native decoder.
-
value_count:usizeExact number of Python tuple values expected by the fast path.
-
fields:&'static [FastFieldSpec]Ordered generated field descriptors.
Trait Implementations
Section titled “Trait Implementations”impl Same for FastConstructorSpec
Section titled “impl Same for FastConstructorSpec”type Output = T
impl Ungil for FastConstructorSpec
Section titled “impl Ungil for FastConstructorSpec”FastWireType
Section titled “FastWireType”enum FastWireType { Int, Long, UInt64, Bytes, String, VectorLong, Object, EmptyObject, Raw, MessageContainer,}Defined in rust/miniproto/src/tl.rs:30-51
Wire representation supported by the generated fast-constructor codec.
Variants
Section titled “Variants”-
IntSigned 32-bit little-endian integer.
-
LongSigned 64-bit little-endian integer.
-
UInt64Unsigned 64-bit little-endian integer.
-
BytesTL length-prefixed bytes.
-
StringUTF-8 TL length-prefixed bytes.
-
VectorLongA generic TL vector of signed 64-bit integers.
-
ObjectA generated object field supported only while encoding.
-
EmptyObjectA constructor id represented by an otherwise fieldless object.
-
RawThe complete remaining wire suffix.
-
MessageContainerMTProto’s message-container sequence.
Trait Implementations
Section titled “Trait Implementations”impl Clone for FastWireType
Section titled “impl Clone for FastWireType”fn clone(&self) -> FastWireType—FastWireType
impl Copy for FastWireType
Section titled “impl Copy for FastWireType”impl Same for FastWireType
Section titled “impl Same for FastWireType”type Output = T
impl Ungil for FastWireType
Section titled “impl Ungil for FastWireType”FastFieldSpec
Section titled “FastFieldSpec”enum FastFieldSpec { Flags { group: usize, }, True { value: usize, group: usize, bit: u32, }, Value { value: usize, wire_type: FastWireType, },}Defined in rust/miniproto/src/tl.rs:55-77
One generated field action used to encode or decode a fast TL constructor.
Variants
Section titled “Variants”-
FlagsReads or writes one flags word in the specified flags group.
-
TrueMaps a generated boolean value to one bit in a flags word.
-
ValueMaps a Python tuple value to a non-flag wire representation.
Trait Implementations
Section titled “Trait Implementations”impl Clone for FastFieldSpec
Section titled “impl Clone for FastFieldSpec”fn clone(&self) -> FastFieldSpec—FastFieldSpec
impl Copy for FastFieldSpec
Section titled “impl Copy for FastFieldSpec”impl Same for FastFieldSpec
Section titled “impl Same for FastFieldSpec”type Output = T
impl Ungil for FastFieldSpec
Section titled “impl Ungil for FastFieldSpec”Functions
Section titled “Functions”register
Section titled “register”fn register(m: &Bound<'_, pyo3::types::PyModule>) -> PyResult<()>Defined in rust/miniproto/src/tl.rs:102-126
Registers the fallback-compatible tl_* Python functions on miniproto._native.
Returns a PyO3 error if any function cannot be exported.
Arguments
Section titled “Arguments”m: The Python extension module receiving the TL callables.
tl_fast_encode
Section titled “tl_fast_encode”fn tl_fast_encode(constructor_id: u32, values: &Bound<'_, pyo3::types::PyTuple>, boxed: bool) -> PyResult<Option<Vec<u8>>>Defined in rust/miniproto/src/tl.rs:143-191
Attempts Python tl_fast_encode for a generated constructor.
values must have the generated constructor’s exact tuple arity; boxed controls whether the
constructor id is emitted. Returns None if no native encoder exists, encoded bytes on
success, or a Python exception for incompatible values or generated metadata. PyO3 conversion
failures from tuple lookup/extraction propagate as TypeError, OverflowError, or the source
Python exception; algorithm and descriptor validation failures intentionally use ValueError.
Arguments
Section titled “Arguments”constructor_id: Generated TL constructor id selecting a trusted fast-path descriptor.values: Python tuple whose exact arity and value types must match that descriptor.boxed: Whether to serialize the constructor id before its fields.
__pyfunction_tl_fast_encode
Section titled “__pyfunction_tl_fast_encode”unsafe fn __pyfunction_tl_fast_encode<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:141
tl_fast_decode
Section titled “tl_fast_decode”fn tl_fast_decode(py: Python<'_>, constructor_id: u32, data: &[u8], offset: usize, boxed: bool) -> PyResult<Option<(Py<pyo3::types::PyTuple>, usize)>>Defined in rust/miniproto/src/tl.rs:210-266
Attempts Python tl_fast_decode for a generated constructor at offset.
boxed requires and verifies the constructor id. Returns None if no native decoder exists,
otherwise (values_tuple, next_offset); malformed wire input raises a Python exception. This
conversion necessarily holds the GIL to create Python objects. PyO3 conversion errors are
propagated unchanged, whereas malformed TL bytes use ValueError. Descriptor indices and flag
bits come from trusted generated metadata and are not revalidated on every hot-path call.
Arguments
Section titled “Arguments”py: The acquired GIL token used to construct decoded Python values.constructor_id: Generated TL constructor id selecting a trusted fast-path descriptor.data: TL wire bytes to decode.offset: Byte offset at which this constructor begins.boxed: Whetherdatastarts with and must match the constructor id.
__pyfunction_tl_fast_decode
Section titled “__pyfunction_tl_fast_decode”unsafe fn __pyfunction_tl_fast_decode<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:208
encode_fast_value
Section titled “encode_fast_value”fn encode_fast_value(output: &mut Vec<u8>, value: &Bound<'_, PyAny>, wire_type: FastWireType) -> PyResult<()>Defined in rust/miniproto/src/tl.rs:278-312
Appends one generated field value to a fast-path TL output buffer.
Returns a Python exception for incompatible Python values, unrepresentable sizes, or an encode-only generated object mismatch.
Arguments
Section titled “Arguments”output: Destination buffer receiving the encoded field.value: Python value to convert according towire_type.wire_type: Trusted generated representation directive forvalue.
decode_fast_value
Section titled “decode_fast_value”fn decode_fast_value(py: Python<'_>, data: &[u8], cursor: &mut usize, wire_type: FastWireType) -> PyResult<Py<PyAny>>Defined in rust/miniproto/src/tl.rs:325-380
Decodes one generated field from data, advancing cursor and creating a Python value.
Returns a Python exception for malformed data or unsupported generated decode types; requires
the GIL through py because the result is a Python object.
Arguments
Section titled “Arguments”py: The acquired GIL token used to create the decoded Python value.data: Complete TL input buffer.cursor: Mutable offset advanced past the decoded field.wire_type: Trusted generated representation directive for the field.
decode_message_container
Section titled “decode_message_container”fn decode_message_container(py: Python<'_>, data: &[u8], cursor: &mut usize) -> PyResult<Py<PyAny>>Defined in rust/miniproto/src/tl.rs:392-442
Decodes an MTProto message-container field into a Python tuple of (id, seq_no, body) tuples.
Advances cursor and returns Python exceptions for truncated, negative, oversized, or
unallocatable container contents.
Arguments
Section titled “Arguments”py: The acquired GIL token used to create the result tuple and bytes objects.data: Complete TL input buffer containing the container.cursor: Mutable offset advanced past every decoded member.
append_tl_bytes
Section titled “append_tl_bytes”fn append_tl_bytes(output: &mut Vec<u8>, value: &[u8]) -> PyResult<()>Defined in rust/miniproto/src/tl.rs:452-464
Encodes and appends a bounded TL bytes value, reserving its output atomically.
Returns ValueError above TL’s 24-bit limit or MemoryError on allocation failure.
Arguments
Section titled “Arguments”output: Destination buffer receiving the encoded TL bytes field.value: Raw bytes to prefix and pad.
decode_tl_bytes_slice
Section titled “decode_tl_bytes_slice”fn decode_tl_bytes_slice(data: &[u8], offset: usize) -> PyResult<(&[u8], usize)>Defined in rust/miniproto/src/tl.rs:474-496
Borrows one padded TL bytes payload and returns it with its next aligned offset.
Returns ValueError if the length prefix, payload, padding, or offset is malformed.
Arguments
Section titled “Arguments”data: Complete TL input buffer.offset: Byte offset at which the TL bytes length prefix starts.
tl_encode_int
Section titled “tl_encode_int”fn tl_encode_int(value: i32) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:504-506
Encodes Python tl_encode_int(value) as a four-byte little-endian signed integer.
Arguments
Section titled “Arguments”value: Signed 32-bit integer to serialize.
__pyfunction_tl_encode_int
Section titled “__pyfunction_tl_encode_int”unsafe fn __pyfunction_tl_encode_int<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:503
tl_decode_int
Section titled “tl_decode_int”fn tl_decode_int(data: &[u8], offset: usize) -> PyResult<(i32, usize)>Defined in rust/miniproto/src/tl.rs:515-518
Decodes Python tl_decode_int(data, offset) and returns (value, next_offset) or ValueError.
Arguments
Section titled “Arguments”data: TL bytes containing a four-byte signed integer.offset: Byte offset at which the integer starts.
__pyfunction_tl_decode_int
Section titled “__pyfunction_tl_decode_int”unsafe fn __pyfunction_tl_decode_int<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:514
tl_encode_uint
Section titled “tl_encode_uint”fn tl_encode_uint(value: u32) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:526-528
Encodes Python tl_encode_uint(value) as a four-byte little-endian unsigned integer.
Arguments
Section titled “Arguments”value: Unsigned 32-bit integer to serialize.
__pyfunction_tl_encode_uint
Section titled “__pyfunction_tl_encode_uint”unsafe fn __pyfunction_tl_encode_uint<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:525
tl_decode_uint
Section titled “tl_decode_uint”fn tl_decode_uint(data: &[u8], offset: usize) -> PyResult<(u32, usize)>Defined in rust/miniproto/src/tl.rs:537-540
Decodes Python tl_decode_uint(data, offset) and returns (value, next_offset) or ValueError.
Arguments
Section titled “Arguments”data: TL bytes containing a four-byte unsigned integer.offset: Byte offset at which the integer starts.
__pyfunction_tl_decode_uint
Section titled “__pyfunction_tl_decode_uint”unsafe fn __pyfunction_tl_decode_uint<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:536
tl_encode_long
Section titled “tl_encode_long”fn tl_encode_long(value: i64) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:548-550
Encodes Python tl_encode_long(value) as an eight-byte little-endian signed integer.
Arguments
Section titled “Arguments”value: Signed 64-bit integer to serialize.
__pyfunction_tl_encode_long
Section titled “__pyfunction_tl_encode_long”unsafe fn __pyfunction_tl_encode_long<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:547
tl_decode_long
Section titled “tl_decode_long”fn tl_decode_long(data: &[u8], offset: usize) -> PyResult<(i64, usize)>Defined in rust/miniproto/src/tl.rs:559-562
Decodes Python tl_decode_long(data, offset) and returns (value, next_offset) or ValueError.
Arguments
Section titled “Arguments”data: TL bytes containing an eight-byte signed integer.offset: Byte offset at which the integer starts.
__pyfunction_tl_decode_long
Section titled “__pyfunction_tl_decode_long”unsafe fn __pyfunction_tl_decode_long<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:558
tl_encode_int128
Section titled “tl_encode_int128”fn tl_encode_int128(value: &Bound<'_, PyAny>) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:572-574
Encodes Python tl_encode_int128(value) to 16 little-endian bytes via int.to_bytes.
Python raises if value cannot fit the requested unsigned representation.
Arguments
Section titled “Arguments”value: Python integer to convert to exactly 16 little-endian bytes.
__pyfunction_tl_encode_int128
Section titled “__pyfunction_tl_encode_int128”unsafe fn __pyfunction_tl_encode_int128<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:571
tl_decode_int128
Section titled “tl_decode_int128”fn tl_decode_int128(py: Python<'_>, data: &[u8], offset: usize) -> PyResult<(Py<PyAny>, usize)>Defined in rust/miniproto/src/tl.rs:586-589
Decodes Python tl_decode_int128(data, offset) to a Python integer and next offset.
Returns ValueError for truncated input and holds the GIL to construct the Python integer.
Arguments
Section titled “Arguments”py: The acquired GIL token used to construct the Python integer.data: TL bytes containing a 16-byte integer field.offset: Byte offset at which the fixed-width field starts.
__pyfunction_tl_decode_int128
Section titled “__pyfunction_tl_decode_int128”unsafe fn __pyfunction_tl_decode_int128<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:585
tl_encode_int256
Section titled “tl_encode_int256”fn tl_encode_int256(value: &Bound<'_, PyAny>) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:599-601
Encodes Python tl_encode_int256(value) to 32 little-endian bytes via int.to_bytes.
Python raises if value cannot fit the requested unsigned representation.
Arguments
Section titled “Arguments”value: Python integer to convert to exactly 32 little-endian bytes.
__pyfunction_tl_encode_int256
Section titled “__pyfunction_tl_encode_int256”unsafe fn __pyfunction_tl_encode_int256<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:598
tl_decode_int256
Section titled “tl_decode_int256”fn tl_decode_int256(py: Python<'_>, data: &[u8], offset: usize) -> PyResult<(Py<PyAny>, usize)>Defined in rust/miniproto/src/tl.rs:613-616
Decodes Python tl_decode_int256(data, offset) to a Python integer and next offset.
Returns ValueError for truncated input and holds the GIL to construct the Python integer.
Arguments
Section titled “Arguments”py: The acquired GIL token used to construct the Python integer.data: TL bytes containing a 32-byte integer field.offset: Byte offset at which the fixed-width field starts.
__pyfunction_tl_decode_int256
Section titled “__pyfunction_tl_decode_int256”unsafe fn __pyfunction_tl_decode_int256<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:612
tl_encode_double
Section titled “tl_encode_double”fn tl_encode_double(value: f64) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:624-626
Encodes Python tl_encode_double(value) as eight IEEE-754 little-endian bytes.
Arguments
Section titled “Arguments”value: Double-precision value to serialize.
__pyfunction_tl_encode_double
Section titled “__pyfunction_tl_encode_double”unsafe fn __pyfunction_tl_encode_double<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:623
tl_decode_double
Section titled “tl_decode_double”fn tl_decode_double(data: &[u8], offset: usize) -> PyResult<(f64, usize)>Defined in rust/miniproto/src/tl.rs:635-638
Decodes Python tl_decode_double(data, offset) and returns (value, next_offset) or ValueError.
Arguments
Section titled “Arguments”data: TL bytes containing an eight-byte double.offset: Byte offset at which the double starts.
__pyfunction_tl_decode_double
Section titled “__pyfunction_tl_decode_double”unsafe fn __pyfunction_tl_decode_double<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:634
tl_encode_bytes
Section titled “tl_encode_bytes”fn tl_encode_bytes(value: &[u8]) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:646-648
Encodes Python tl_encode_bytes(value) with TL’s short/long length prefix and zero padding.
Arguments
Section titled “Arguments”value: Bytes to prefix and pad according to TL rules.
__pyfunction_tl_encode_bytes
Section titled “__pyfunction_tl_encode_bytes”unsafe fn __pyfunction_tl_encode_bytes<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:645
tl_decode_bytes
Section titled “tl_decode_bytes”fn tl_decode_bytes(data: &[u8], offset: usize) -> PyResult<(Vec<u8>, usize)>Defined in rust/miniproto/src/tl.rs:659-661
Decodes Python tl_decode_bytes(data, offset) and returns bytes plus the next aligned offset.
Returns ValueError for malformed or truncated TL data.
Arguments
Section titled “Arguments”data: TL bytes containing one length-prefixed byte field.offset: Byte offset at which the field starts.
__pyfunction_tl_decode_bytes
Section titled “__pyfunction_tl_decode_bytes”unsafe fn __pyfunction_tl_decode_bytes<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:658
tl_encode_string
Section titled “tl_encode_string”fn tl_encode_string(value: &str) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:669-671
Encodes Python tl_encode_string(value) as UTF-8 TL bytes.
Arguments
Section titled “Arguments”value: UTF-8 Rust string to encode as TL bytes.
__pyfunction_tl_encode_string
Section titled “__pyfunction_tl_encode_string”unsafe fn __pyfunction_tl_encode_string<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:668
tl_decode_string
Section titled “tl_decode_string”fn tl_decode_string(data: &[u8], offset: usize) -> PyResult<(String, usize)>Defined in rust/miniproto/src/tl.rs:682-687
Decodes Python tl_decode_string(data, offset) as UTF-8 and returns it with the next offset.
Returns ValueError for malformed TL data or non-UTF-8 payload bytes.
Arguments
Section titled “Arguments”data: TL bytes containing one length-prefixed string field.offset: Byte offset at which the field starts.
__pyfunction_tl_decode_string
Section titled “__pyfunction_tl_decode_string”unsafe fn __pyfunction_tl_decode_string<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:681
tl_encode_int_vector
Section titled “tl_encode_int_vector”fn tl_encode_int_vector(py: Python<'_>, values: Vec<i32>) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:698-701
Encodes Python tl_encode_int_vector(values) as a generic TL vector of 32-bit integers.
Large vector encoding releases the GIL; invalid size or allocation raises a Python exception.
Arguments
Section titled “Arguments”py: The acquired GIL token used to detach large vector encoding.values: Signed 32-bit values to serialize.
__pyfunction_tl_encode_int_vector
Section titled “__pyfunction_tl_encode_int_vector”unsafe fn __pyfunction_tl_encode_int_vector<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:697
tl_decode_int_vector
Section titled “tl_decode_int_vector”fn tl_decode_int_vector(py: Python<'_>, data: Vec<u8>, offset: i128) -> PyResult<(Vec<i32>, usize)>Defined in rust/miniproto/src/tl.rs:714-722
Decodes Python tl_decode_int_vector(data, offset) into values and a next offset.
The signed Python offset must fit usize; large decoding releases the GIL and malformed input
returns a Python exception.
Arguments
Section titled “Arguments”py: The acquired GIL token used to detach large vector decoding.data: TL bytes containing a generic integer vector.offset: Python-facing signed byte offset that must convert tousize.
__pyfunction_tl_decode_int_vector
Section titled “__pyfunction_tl_decode_int_vector”unsafe fn __pyfunction_tl_decode_int_vector<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:713
tl_encode_long_vector
Section titled “tl_encode_long_vector”fn tl_encode_long_vector(py: Python<'_>, values: Vec<i64>) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:733-736
Encodes Python tl_encode_long_vector(values) as a generic TL vector of 64-bit integers.
Large vector encoding releases the GIL; invalid size or allocation raises a Python exception.
Arguments
Section titled “Arguments”py: The acquired GIL token used to detach large vector encoding.values: Signed 64-bit values to serialize.
__pyfunction_tl_encode_long_vector
Section titled “__pyfunction_tl_encode_long_vector”unsafe fn __pyfunction_tl_encode_long_vector<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:732
tl_decode_long_vector
Section titled “tl_decode_long_vector”fn tl_decode_long_vector(py: Python<'_>, data: Vec<u8>, offset: i128) -> PyResult<(Vec<i64>, usize)>Defined in rust/miniproto/src/tl.rs:749-757
Decodes Python tl_decode_long_vector(data, offset) into values and a next offset.
The signed Python offset must fit usize; large decoding releases the GIL and malformed input
returns a Python exception.
Arguments
Section titled “Arguments”py: The acquired GIL token used to detach large vector decoding.data: TL bytes containing a generic long vector.offset: Python-facing signed byte offset that must convert tousize.
__pyfunction_tl_decode_long_vector
Section titled “__pyfunction_tl_decode_long_vector”unsafe fn __pyfunction_tl_decode_long_vector<'py>(py: Python<'py>, _slf: *mut ffi::PyObject, _args: *const *mut ffi::PyObject, _nargs: ffi::Py_ssize_t, _kwargs: *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>Defined in rust/miniproto/src/tl.rs:748
read_slice
Section titled “read_slice”fn read_slice(data: &[u8], offset: usize, length: usize) -> PyResult<&[u8]>Defined in rust/miniproto/src/tl.rs:768-773
Borrows length bytes at offset from a TL buffer.
Returns ValueError rather than panicking if the requested range is not present.
Arguments
Section titled “Arguments”data: Complete TL input buffer.offset: Byte offset at which the requested range begins.length: Number of bytes to borrow.
read_fixed
Section titled “read_fixed”fn read_fixed<const N: usize>(data: &[u8], offset: usize) -> PyResult<[u8; N]>Defined in rust/miniproto/src/tl.rs:785-787
Reads an exactly N-byte TL field at offset.
Returns ValueError for a truncated buffer; its expect is safe after read_slice verified
the length.
Arguments
Section titled “Arguments”N: Compile-time fixed width required by the caller.data: Complete TL input buffer.offset: Byte offset at which the fixed-width field begins.
encode_tl_bytes
Section titled “encode_tl_bytes”fn encode_tl_bytes(value: &[u8]) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:796-810
Serializes bytes with the TL short/long length prefix and zero alignment padding.
This internal helper assumes the caller has enforced TL’s 24-bit long-length maximum.
Arguments
Section titled “Arguments”value: Bytes to length-prefix and pad to a four-byte boundary.
decode_tl_bytes
Section titled “decode_tl_bytes”fn decode_tl_bytes(data: &[u8], offset: usize) -> PyResult<(Vec<u8>, usize)>Defined in rust/miniproto/src/tl.rs:820-841
Parses and copies one padded TL bytes value, returning it and its next aligned offset.
Returns ValueError for missing length, payload, or padding bytes.
Arguments
Section titled “Arguments”data: Complete TL input buffer.offset: Byte offset at which the bytes field starts.
py_int_to_le_bytes
Section titled “py_int_to_le_bytes”fn py_int_to_le_bytes(value: &Bound<'_, PyAny>, width: usize) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:851-859
Calls Python int.to_bytes(width, "little") for fixed-width unsigned TL integer fields.
Propagates Python conversion exceptions and returns ValueError for an unexpected width.
Arguments
Section titled “Arguments”value: Python integer exposingto_bytes.width: Required serialized width in bytes.
py_int_from_le_bytes
Section titled “py_int_from_le_bytes”fn py_int_from_le_bytes(py: Python<'_>, bytes: &[u8]) -> PyResult<Py<PyAny>>Defined in rust/miniproto/src/tl.rs:869-876
Calls Python int.from_bytes(bytes, "little") while holding the supplied GIL token.
Returns any exception raised while importing or invoking Python builtins.
Arguments
Section titled “Arguments”py: The acquired GIL token used to import and invoke Python builtins.bytes: Little-endian bytes to pass toint.from_bytes.
encode_i32_vector
Section titled “encode_i32_vector”fn encode_i32_vector(values: &[i32]) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:885-897
Serializes signed 32-bit values as a generic boxed TL vector.
Returns ValueError for an unrepresentable count or MemoryError on allocation failure.
Arguments
Section titled “Arguments”values: Signed 32-bit vector elements to serialize.
decode_i32_vector
Section titled “decode_i32_vector”fn decode_i32_vector(data: &[u8], offset: usize) -> PyResult<(Vec<i32>, usize)>Defined in rust/miniproto/src/tl.rs:907-920
Decodes a generic TL vector of signed 32-bit values at offset.
Returns values with the next offset, or Python errors for malformed sizes or allocation failure.
Arguments
Section titled “Arguments”data: Complete TL input buffer.offset: Byte offset at which the generic vector begins.
encode_i64_vector
Section titled “encode_i64_vector”fn encode_i64_vector(values: &[i64]) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:929-941
Serializes signed 64-bit values as a generic boxed TL vector.
Returns ValueError for an unrepresentable count or MemoryError on allocation failure.
Arguments
Section titled “Arguments”values: Signed 64-bit vector elements to serialize.
decode_i64_vector
Section titled “decode_i64_vector”fn decode_i64_vector(data: &[u8], offset: usize) -> PyResult<(Vec<i64>, usize)>Defined in rust/miniproto/src/tl.rs:951-964
Decodes a generic TL vector of signed 64-bit values at offset.
Returns values with the next offset, or Python errors for malformed sizes or allocation failure.
Arguments
Section titled “Arguments”data: Complete TL input buffer.offset: Byte offset at which the generic vector begins.
decode_vector_layout
Section titled “decode_vector_layout”fn decode_vector_layout(data: &[u8], offset: usize, element_width: usize) -> PyResult<(usize, usize, usize)>Defined in rust/miniproto/src/tl.rs:979-1014
Validates a generic vector header and returns its count, payload start, and next offset.
Returns ValueError for a wrong constructor, negative/excessive count, or arithmetic overflow.
The subtraction used to calculate remaining bytes cannot underflow: the preceding checked
header slice exists only when payload_offset <= data.len(). This function has no panic path
for externally supplied data; its expect calls follow exact-width checked slices.
Arguments
Section titled “Arguments”data: Complete TL input buffer.offset: Byte offset at which the vector constructor id starts.element_width: Nonzero byte width of one decoded element; callers use 4 or 8. A zero width would panic in the remaining-bytes division and is therefore an internal precondition.
normalize_vector_offset
Section titled “normalize_vector_offset”fn normalize_vector_offset(offset: i128) -> PyResult<usize>Defined in rust/miniproto/src/tl.rs:1023-1027
Converts the Python-facing signed offset to a safe Rust index.
Returns ValueError for negative or unrepresentable offsets.
Arguments
Section titled “Arguments”offset: Python-facing signed byte offset to convert.
validate_vector_allocation
Section titled “validate_vector_allocation”fn validate_vector_allocation(count: usize, element_width: usize) -> PyResult<()>Defined in rust/miniproto/src/tl.rs:1037-1045
Checks that a decoded vector’s requested allocation fits the platform’s isize limit.
Returns ValueError before allocation on overflow or an excessive capacity.
Arguments
Section titled “Arguments”count: Number of vector elements requested by decoded wire data.element_width: Byte width of one element used for capacity calculation.
checked_vector_capacity
Section titled “checked_vector_capacity”fn checked_vector_capacity(count: usize, element_width: usize) -> PyResult<usize>Defined in rust/miniproto/src/tl.rs:1055-1067
Computes encoder capacity including the eight-byte TL vector header.
Returns ValueError when the count cannot fit signed TL int or the capacity is excessive.
Arguments
Section titled “Arguments”count: Number of vector elements to encode.element_width: Byte width of one serialized element.
Constants
Section titled “Constants”TL_VECTOR_CONSTRUCTOR_ID
Section titled “TL_VECTOR_CONSTRUCTOR_ID”const TL_VECTOR_CONSTRUCTOR_ID: u32 = 481_674_261u32;Defined in rust/miniproto/src/tl.rs:24
Constructor identifier serialized before every generic TL Vector.
MAX_TL_BYTES_LENGTH
Section titled “MAX_TL_BYTES_LENGTH”const MAX_TL_BYTES_LENGTH: usize = 16_777_215usize;Defined in rust/miniproto/src/tl.rs:26
Largest byte-string payload representable by TL’s three-byte long length prefix.