Skip to content

miniproto_native::tl

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.

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 a bounded TL bytes value, then reserves space before appending it
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_payload fn Decodes the validated payload of a signed 32-bit vector without copying its input
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_i64_vector_payload fn Decodes the validated payload of a signed 64-bit vector without copying its input
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.
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.

  • constructor_id: u32

    Constructor id serialized for boxed values.

  • name: &'static str

    Generated schema name used in validation errors.

  • encode: bool

    Whether this constructor has a native encoder.

  • decode: bool

    Whether this constructor has a native decoder.

  • value_count: usize

    Exact number of Python tuple values expected by the fast path.

  • fields: &'static [FastFieldSpec]

    Ordered generated field descriptors.

  • type Output = T
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.

  • Int

    Signed 32-bit little-endian integer.

  • Long

    Signed 64-bit little-endian integer.

  • UInt64

    Unsigned 64-bit little-endian integer.

  • Bytes

    TL length-prefixed bytes.

  • String

    UTF-8 TL length-prefixed bytes.

  • VectorLong

    A generic TL vector of signed 64-bit integers.

  • Object

    A generated object field supported only while encoding.

  • EmptyObject

    A constructor id represented by an otherwise fieldless object.

  • Raw

    The complete remaining wire suffix.

  • MessageContainer

    MTProto’s message-container sequence.

  • fn clone(&self) -> Self
  • type Output = T
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.

  • Flags

    Reads or writes one flags word in the specified flags group.

  • True

    Maps a generated boolean value to one bit in a flags word.

  • Value

    Maps a Python tuple value to a non-flag wire representation.

  • fn clone(&self) -> Self
  • type Output = T
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.

  • m: The Python extension module receiving the TL callables.
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.

  • 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.
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

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:204-260

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.

  • 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: Whether data starts with and must match the constructor id.
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

fn encode_fast_value(output: &mut Vec<u8>, value: &Bound<'_, PyAny>, wire_type: FastWireType) -> PyResult<()>

Defined in rust/miniproto/src/tl.rs:272-306

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.

  • output: Destination buffer receiving the encoded field.
  • value: Python value to convert according to wire_type.
  • wire_type: Trusted generated representation directive for 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:319-374

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.

  • 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.
fn decode_message_container(py: Python<'_>, data: &[u8], cursor: &mut usize) -> PyResult<Py<PyAny>>

Defined in rust/miniproto/src/tl.rs:386-436

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.

  • 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.
fn append_tl_bytes(output: &mut Vec<u8>, value: &[u8]) -> PyResult<()>

Defined in rust/miniproto/src/tl.rs:446-458

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.

  • output: Destination buffer receiving the encoded TL bytes field.
  • value: Raw bytes to prefix and pad.
fn decode_tl_bytes_slice(data: &[u8], offset: usize) -> PyResult<(&[u8], usize)>

Defined in rust/miniproto/src/tl.rs:468-490

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.

  • data: Complete TL input buffer.
  • offset: Byte offset at which the TL bytes length prefix starts.
fn tl_encode_int(value: i32) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:498-500

Encodes Python tl_encode_int(value) as a four-byte little-endian signed integer.

  • value: Signed 32-bit integer to serialize.
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:497

fn tl_decode_int(data: &[u8], offset: usize) -> PyResult<(i32, usize)>

Defined in rust/miniproto/src/tl.rs:509-512

Decodes Python tl_decode_int(data, offset) and returns (value, next_offset) or ValueError.

  • data: TL bytes containing a four-byte signed integer.
  • offset: Byte offset at which the integer starts.
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:508

fn tl_encode_uint(value: u32) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:520-522

Encodes Python tl_encode_uint(value) as a four-byte little-endian unsigned integer.

  • value: Unsigned 32-bit integer to serialize.
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:519

fn tl_decode_uint(data: &[u8], offset: usize) -> PyResult<(u32, usize)>

Defined in rust/miniproto/src/tl.rs:531-534

Decodes Python tl_decode_uint(data, offset) and returns (value, next_offset) or ValueError.

  • data: TL bytes containing a four-byte unsigned integer.
  • offset: Byte offset at which the integer starts.
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:530

fn tl_encode_long(value: i64) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:542-544

Encodes Python tl_encode_long(value) as an eight-byte little-endian signed integer.

  • value: Signed 64-bit integer to serialize.
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:541

fn tl_decode_long(data: &[u8], offset: usize) -> PyResult<(i64, usize)>

Defined in rust/miniproto/src/tl.rs:553-556

Decodes Python tl_decode_long(data, offset) and returns (value, next_offset) or ValueError.

  • data: TL bytes containing an eight-byte signed integer.
  • offset: Byte offset at which the integer starts.
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:552

fn tl_encode_int128(value: &Bound<'_, PyAny>) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:566-568

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.

  • value: Python integer to convert to exactly 16 little-endian bytes.
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:565

fn tl_decode_int128(py: Python<'_>, data: &[u8], offset: usize) -> PyResult<(Py<PyAny>, usize)>

Defined in rust/miniproto/src/tl.rs:580-583

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.

  • 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.
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:579

fn tl_encode_int256(value: &Bound<'_, PyAny>) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:593-595

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.

  • value: Python integer to convert to exactly 32 little-endian bytes.
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:592

fn tl_decode_int256(py: Python<'_>, data: &[u8], offset: usize) -> PyResult<(Py<PyAny>, usize)>

Defined in rust/miniproto/src/tl.rs:607-610

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.

  • 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.
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:606

fn tl_encode_double(value: f64) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:618-620

Encodes Python tl_encode_double(value) as eight IEEE-754 little-endian bytes.

  • value: Double-precision value to serialize.
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:617

fn tl_decode_double(data: &[u8], offset: usize) -> PyResult<(f64, usize)>

Defined in rust/miniproto/src/tl.rs:629-632

Decodes Python tl_decode_double(data, offset) and returns (value, next_offset) or ValueError.

  • data: TL bytes containing an eight-byte double.
  • offset: Byte offset at which the double starts.
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:628

fn tl_encode_bytes(value: &[u8]) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:640-642

Encodes Python tl_encode_bytes(value) with TL’s short/long length prefix and zero padding.

  • value: Must contain at most 2**24 - 1 bytes. This function does not check the limit.
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:639

fn tl_decode_bytes(data: &[u8], offset: usize) -> PyResult<(Vec<u8>, usize)>

Defined in rust/miniproto/src/tl.rs:653-655

Decodes Python tl_decode_bytes(data, offset) and returns bytes plus the next aligned offset.

Returns ValueError for malformed or truncated TL data.

  • data: TL bytes containing one length-prefixed byte field.
  • offset: Byte offset at which the field starts.
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:652

fn tl_encode_string(value: &str) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:663-665

Encodes Python tl_encode_string(value) as UTF-8 TL bytes.

  • value: Its UTF-8 encoding must contain at most 2**24 - 1 bytes. This function does not check the limit.
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:662

fn tl_decode_string(data: &[u8], offset: usize) -> PyResult<(String, usize)>

Defined in rust/miniproto/src/tl.rs:676-681

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.

  • data: TL bytes containing one length-prefixed string field.
  • offset: Byte offset at which the field starts.
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:675

fn tl_encode_int_vector(py: Python<'_>, values: Vec<i32>) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:692-695

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.

  • py: The acquired GIL token used to detach large vector encoding.
  • values: Signed 32-bit values to serialize.
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:691

fn tl_decode_int_vector(py: Python<'_>, data: std::borrow::Cow<'_, [u8]>, offset: i128) -> PyResult<(Vec<i32>, usize)>

Defined in rust/miniproto/src/tl.rs:708-720

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.

  • 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 to usize.
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:707

fn tl_encode_long_vector(py: Python<'_>, values: Vec<i64>) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:731-734

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.

  • py: The acquired GIL token used to detach large vector encoding.
  • values: Signed 64-bit values to serialize.
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:730

fn tl_decode_long_vector(py: Python<'_>, data: std::borrow::Cow<'_, [u8]>, offset: i128) -> PyResult<(Vec<i64>, usize)>

Defined in rust/miniproto/src/tl.rs:747-759

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.

  • 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 to usize.
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:746

fn read_slice(data: &[u8], offset: usize, length: usize) -> PyResult<&[u8]>

Defined in rust/miniproto/src/tl.rs:770-775

Borrows length bytes at offset from a TL buffer.

Returns ValueError rather than panicking if the requested range is not present.

  • data: Complete TL input buffer.
  • offset: Byte offset at which the requested range begins.
  • length: Number of bytes to borrow.
fn read_fixed<const N: usize>(data: &[u8], offset: usize) -> PyResult<[u8; N]>

Defined in rust/miniproto/src/tl.rs:787-789

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.

  • N: Compile-time fixed width required by the caller.
  • data: Complete TL input buffer.
  • offset: Byte offset at which the fixed-width field begins.
fn encode_tl_bytes(value: &[u8]) -> Vec<u8>

Defined in rust/miniproto/src/tl.rs:798-812

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.

  • value: Bytes to length-prefix and pad to a four-byte boundary.
fn decode_tl_bytes(data: &[u8], offset: usize) -> PyResult<(Vec<u8>, usize)>

Defined in rust/miniproto/src/tl.rs:822-843

Parses and copies one padded TL bytes value, returning it and its next aligned offset.

Returns ValueError for missing length, payload or padding bytes.

  • data: Complete TL input buffer.
  • offset: Byte offset at which the bytes field starts.
fn py_int_to_le_bytes(value: &Bound<'_, PyAny>, width: usize) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:853-861

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.

  • value: Python integer exposing to_bytes.
  • width: Required serialized width in bytes.
fn py_int_from_le_bytes(py: Python<'_>, bytes: &[u8]) -> PyResult<Py<PyAny>>

Defined in rust/miniproto/src/tl.rs:871-878

Calls Python int.from_bytes(bytes, "little") while holding the supplied GIL token.

Returns any exception raised while importing or invoking Python builtins.

  • py: The acquired GIL token used to import and invoke Python builtins.
  • bytes: Little-endian bytes to pass to int.from_bytes.
fn encode_i32_vector(values: &[i32]) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:887-899

Serializes signed 32-bit values as a generic boxed TL vector.

Returns ValueError for an unrepresentable count or MemoryError on allocation failure.

  • values: Signed 32-bit vector elements to serialize.
fn decode_i32_vector_payload(payload: &[u8]) -> PyResult<Vec<i32>>

Defined in rust/miniproto/src/tl.rs:923-934

Decodes the validated payload of a signed 32-bit vector without copying its input

  • payload: Validated vector element bytes with a length divisible by four
fn encode_i64_vector(values: &[i64]) -> PyResult<Vec<u8>>

Defined in rust/miniproto/src/tl.rs:943-955

Serializes signed 64-bit values as a generic boxed TL vector.

Returns ValueError for an unrepresentable count or MemoryError on allocation failure.

  • values: Signed 64-bit vector elements to serialize.
fn decode_i64_vector(data: &[u8], offset: usize) -> PyResult<(Vec<i64>, usize)>

Defined in rust/miniproto/src/tl.rs:965-971

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.

  • data: Complete TL input buffer.
  • offset: Byte offset at which the generic vector begins.
fn decode_i64_vector_payload(payload: &[u8]) -> PyResult<Vec<i64>>

Defined in rust/miniproto/src/tl.rs:978-989

Decodes the validated payload of a signed 64-bit vector without copying its input

  • payload: Validated vector element bytes with a length divisible by eight
fn decode_vector_layout(data: &[u8], offset: usize, element_width: usize) -> PyResult<(usize, usize, usize)>

Defined in rust/miniproto/src/tl.rs:1004-1039

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.

  • 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.
fn normalize_vector_offset(offset: i128) -> PyResult<usize>

Defined in rust/miniproto/src/tl.rs:1048-1052

Converts the Python-facing signed offset to a safe Rust index.

Returns ValueError for negative or unrepresentable offsets.

  • offset: Python-facing signed byte offset to convert.
fn validate_vector_allocation(count: usize, element_width: usize) -> PyResult<()>

Defined in rust/miniproto/src/tl.rs:1062-1070

Checks that a decoded vector’s requested allocation fits the platform’s isize limit.

Returns ValueError before allocation on overflow or an excessive capacity.

  • count: Number of vector elements requested by decoded wire data.
  • element_width: Byte width of one element used for capacity calculation.
fn checked_vector_capacity(count: usize, element_width: usize) -> PyResult<usize>

Defined in rust/miniproto/src/tl.rs:1080-1092

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.

  • count: Number of vector elements to encode.
  • element_width: Byte width of one serialized element.
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.

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.