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.

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

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

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

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

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

  • output: Destination buffer receiving the encoded TL bytes field.
  • value: Raw bytes to prefix and pad.
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.

  • value: Byte buffer supplied by a scalar or generated TL encoder.
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.

  • 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:525-527

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:524

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.

  • 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:535

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.

  • 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:547

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.

  • 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:558

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.

  • 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:570

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.

  • 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:581

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.

  • 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:595

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.

  • 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:609

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.

  • 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:623

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.

  • 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:637

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.

  • 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:649

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.

  • 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:660

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.

  • value: Must contain at most 2**24 - 1 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

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.

  • 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:685

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.

  • value: Its UTF-8 encoding must contain at most 2**24 - 1 bytes.
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

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.

  • 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:709

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.

  • 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:726

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.

  • 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:742

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.

  • 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:765

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.

  • 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:781

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.

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

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

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

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

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

  • 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:893-905

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:929-940

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:949-961

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

  • 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:984-995

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

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

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

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

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