miniproto_native::tl
Provenance
Section titled “Provenance”- 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_decode_bytesminiproto_native::tl::tl_decode_doubleminiproto_native::tl::tl_decode_intminiproto_native::tl::tl_decode_int128miniproto_native::tl::tl_decode_int256miniproto_native::tl::tl_decode_int_vectorminiproto_native::tl::tl_decode_longminiproto_native::tl::tl_decode_long_vectorminiproto_native::tl::tl_decode_stringminiproto_native::tl::tl_decode_uintminiproto_native::tl::tl_encode_bytesminiproto_native::tl::tl_encode_doubleminiproto_native::tl::tl_encode_intminiproto_native::tl::tl_encode_int128miniproto_native::tl::tl_encode_int256miniproto_native::tl::tl_encode_int_vectorminiproto_native::tl::tl_encode_longminiproto_native::tl::tl_encode_long_vectorminiproto_native::tl::tl_encode_stringminiproto_native::tl::tl_encode_uintminiproto_native::tl::tl_fast_decodeminiproto_native::tl::tl_fast_encode
miniproto_native / tl
Registers primitive and generated fast-path TL codec callables. Native primitive and generated fast-path codecs for Telegram’s Type Language (TL).
Primitive tl_* exports share the Python fallback’s calling conventions. Optional tl_fast_encode and tl_fast_decode exports return None when the constructor has no matching fast path. Malformed wire data raises ValueError, checked allocation failures raise MemoryError, and PyO3 conversion errors propagate unchanged. Large primitive-vector operations detach from Python.
generated_tl.rs supplies trusted metadata. Some descriptor indices and bit positions rely on generator invariants instead of per-call validation.
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:74-87
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:24-45
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) -> Self
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:49-71
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) -> Self
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:96-120
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:137-185
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:135
tl_fast_decode
Section titled “tl_fast_decode”fn tl_fast_decode(py: Python<'_>, constructor_id: u32, data: &[u8], offset: i128, boxed: bool) -> PyResult<Option<(Py<pyo3::types::PyTuple>, usize)>>Defined in rust/miniproto/src/tl.rs:204-261
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:202
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:273-307
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:320-375
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:387-437
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:447-468
Encodes a bounded TL bytes value, then reserves space before appending it
Returns ValueError above TL’s 24-bit limit or MemoryError if the destination reservation fails. The temporary encoding uses an ordinary Rust allocation.
Arguments
Section titled “Arguments”output: Destination buffer receiving the encoded TL bytes field.value: Raw bytes to prefix and pad.
wire_bytes
Section titled “wire_bytes”fn wire_bytes<'py>(value: &Bound<'py, PyAny>) -> PyResult<Bound<'py, pyo3::types::PyBytes>>Defined in rust/miniproto/src/tl.rs:475-482
Borrows immutable Python bytes or snapshots another buffer in logical byte order.
Arguments
Section titled “Arguments”value: Byte buffer supplied by a scalar or generated TL encoder.
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:492-517
Borrows one padded TL bytes payload and returns it with its next aligned offset.
Returns ValueError for an unavailable prefix, truncated payload or padding, or offset overflow. Padding byte values are not checked.
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:525-527
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:524
tl_decode_int
Section titled “tl_decode_int”fn tl_decode_int(data: &[u8], offset: i128) -> PyResult<(i32, usize)>Defined in rust/miniproto/src/tl.rs:536-540
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:535
tl_encode_uint
Section titled “tl_encode_uint”fn tl_encode_uint(value: u32) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:548-550
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:547
tl_decode_uint
Section titled “tl_decode_uint”fn tl_decode_uint(data: &[u8], offset: i128) -> PyResult<(u32, usize)>Defined in rust/miniproto/src/tl.rs:559-563
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:558
tl_encode_long
Section titled “tl_encode_long”fn tl_encode_long(value: i64) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:571-573
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:570
tl_decode_long
Section titled “tl_decode_long”fn tl_decode_long(data: &[u8], offset: i128) -> PyResult<(i64, usize)>Defined in rust/miniproto/src/tl.rs:582-586
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:581
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:596-598
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:595
tl_decode_int128
Section titled “tl_decode_int128”fn tl_decode_int128(py: Python<'_>, data: &[u8], offset: i128) -> PyResult<(Py<PyAny>, usize)>Defined in rust/miniproto/src/tl.rs:610-614
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:609
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:624-626
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:623
tl_decode_int256
Section titled “tl_decode_int256”fn tl_decode_int256(py: Python<'_>, data: &[u8], offset: i128) -> PyResult<(Py<PyAny>, usize)>Defined in rust/miniproto/src/tl.rs:638-642
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:637
tl_encode_double
Section titled “tl_encode_double”fn tl_encode_double(value: f64) -> Vec<u8>Defined in rust/miniproto/src/tl.rs:650-652
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:649
tl_decode_double
Section titled “tl_decode_double”fn tl_decode_double(data: &[u8], offset: i128) -> PyResult<(f64, usize)>Defined in rust/miniproto/src/tl.rs:661-665
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:660
tl_encode_bytes
Section titled “tl_encode_bytes”fn tl_encode_bytes(value: &Bound<'_, PyAny>) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:673-675
Encodes Python tl_encode_bytes(value) with TL’s short/long length prefix and zero padding.
Arguments
Section titled “Arguments”value: Must contain at most2**24 - 1bytes.
__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:672
tl_decode_bytes
Section titled “tl_decode_bytes”fn tl_decode_bytes(data: &[u8], offset: i128) -> PyResult<(Vec<u8>, usize)>Defined in rust/miniproto/src/tl.rs:686-689
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:685
tl_encode_string
Section titled “tl_encode_string”fn tl_encode_string(value: &str) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:697-699
Encodes Python tl_encode_string(value) as UTF-8 TL bytes.
Arguments
Section titled “Arguments”value: Its UTF-8 encoding must contain at most2**24 - 1bytes.
__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:696
tl_decode_string
Section titled “tl_decode_string”fn tl_decode_string(data: &[u8], offset: i128) -> PyResult<(String, usize)>Defined in rust/miniproto/src/tl.rs:710-716
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:709
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:727-730
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:726
tl_decode_int_vector
Section titled “tl_decode_int_vector”fn tl_decode_int_vector(py: Python<'_>, data: std::borrow::Cow<'_, [u8]>, offset: i128) -> PyResult<(Py<pyo3::types::PyTuple>, usize)>Defined in rust/miniproto/src/tl.rs:743-755
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:742
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:766-769
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:765
tl_decode_long_vector
Section titled “tl_decode_long_vector”fn tl_decode_long_vector(py: Python<'_>, data: std::borrow::Cow<'_, [u8]>, offset: i128) -> PyResult<(Py<pyo3::types::PyTuple>, usize)>Defined in rust/miniproto/src/tl.rs:782-794
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:781
read_slice
Section titled “read_slice”fn read_slice(data: &[u8], offset: usize, length: usize) -> PyResult<&[u8]>Defined in rust/miniproto/src/tl.rs:805-810
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:822-824
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]) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:833-837
Serializes bytes with the TL short/long length prefix and zero alignment padding.
Returns a Python value error if the payload exceeds the 24-bit length limit.
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:847-850
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:860-868
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:878-884
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:893-905
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_payload
Section titled “decode_i32_vector_payload”fn decode_i32_vector_payload(payload: &[u8]) -> PyResult<Vec<i32>>Defined in rust/miniproto/src/tl.rs:929-940
Decodes the validated payload of a signed 32-bit vector without copying its input
Arguments
Section titled “Arguments”payload: Validated vector element bytes with a length divisible by four
encode_i64_vector
Section titled “encode_i64_vector”fn encode_i64_vector(values: &[i64]) -> PyResult<Vec<u8>>Defined in rust/miniproto/src/tl.rs:949-961
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:971-977
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_i64_vector_payload
Section titled “decode_i64_vector_payload”fn decode_i64_vector_payload(payload: &[u8]) -> PyResult<Vec<i64>>Defined in rust/miniproto/src/tl.rs:984-995
Decodes the validated payload of a signed 64-bit vector without copying its input
Arguments
Section titled “Arguments”payload: Validated vector element bytes with a length divisible by eight
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:1010-1045
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_offset
Section titled “normalize_offset”fn normalize_offset(offset: i128) -> PyResult<usize>Defined in rust/miniproto/src/tl.rs:1054-1058
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:1068-1076
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:1086-1098
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:18
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:20
Largest byte-string payload representable by TL’s three-byte long length prefix.