Skip to content

miniproto_native::transport::TransportCodec

  • Rust visibility: restricted
  • Source: rust/miniproto/src/transport.rs
  • Python exposure: miniproto._native.TransportCodec (confirmed from adjacent PyO3 attributes)
struct TransportCodec {
decoder: std::sync::Mutex<FramePump>,
encoder: FrameEncoder,
}

Defined in rust/miniproto/src/transport.rs:149-154

Python-visible incremental TCP framing codec, exported as miniproto._native.TransportCodec.

  • decoder: std::sync::Mutex<FramePump>

    Stateful native parser and encoder backing this Python object.

  • encoder: FrameEncoder

    Immutable outgoing transport framing parameters.

  • fn new(mode: &str, max_payload_size: usize, server_side: bool) -> PyResult<Self>

    Creates TransportCodec(mode, max_payload_size, server_side=False).

    An unsupported mode or zero payload bound raises ValueError. A negative bound or one larger than usize raises OverflowError during PyO3 conversion.

    • mode: One of the supported Python TCP mode names.

    • max_payload_size: Positive upper bound for decoded application payload bytes.

    • server_side: Whether inbound quick-ACK request bits remain payload metadata instead of

      being interpreted as quick-ACK response frames.

  • fn encode_packet(&self, payload: &[u8], quick_ack: bool) -> PyResult<Vec<u8>>

    Encodes Python encode_packet(payload, quick_ack=False) into a single TCP frame.

    Returns ValueError for oversized payloads, invalid abridged alignment, length overflow,

    or operating-system randomness failure in padded mode.

    • payload: Complete MTProto payload to frame.

    • quick_ack: Whether to set the outbound quick-ACK request bit where the mode supports it.

  • fn feed_data(&self, data: &[u8]) -> PyResult<Vec<(u8, Vec<u8>, i64, bool)>>

    Feeds Python feed_data(data) and returns tagged native event tuples.

    Tuple kinds are 0 payload, 1 quick ACK and 2 negative transport error. It preserves

    incomplete trailing bytes for the next call and raises Python errors for invalid framing.

    • data: Newly received TCP bytes to append to this codec’s buffered stream.
  • fn feed_transport_data(&self, py: Python<'_>, data: &[u8]) -> PyResult<Vec<Py<PyAny>>>

    Feeds compatibility feed_transport_data(data) and returns bytes or integer Python events.

    The GIL token is used only for object conversion after native parsing; malformed framing

    returns a Python exception.

    • py: The acquired GIL token used to build Python bytes and integer events.

    • data: Newly received TCP bytes to append to this codec’s buffered stream.

  • type Target = TransportCodec

  • type Output = Bound<'py, TransportCodec>

  • type Error = PyErr

  • fn into_pyobject(self, py: ::pyo3::Python<'py>) -> ::pyo3::PyResult<::pyo3::Bound<'py, Self>>

  • const NAME: &str

  • type Frozen = True

  • const MODULE: ::core::option::Option<&str>

  • type Layout = <<TransportCodec as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout

  • type BaseType = PyAny

  • type ThreadChecker = NoopThreadChecker

  • type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild

  • type Dict = PyClassDummySlot

  • type WeakRef = PyClassDummySlot

  • type BaseNativeType = PyAny

  • fn items_iter() -> ::pyo3::impl_::pyclass::PyClassItemsIter

  • const RAW_DOC: &'static ::core::ffi::CStr

  • const DOC: &'static ::core::ffi::CStr

  • fn lazy_type_object() -> &'static ::pyo3::impl_::pyclass::LazyTypeObject<Self>

  • fn __traverse__(&self, visit: ::pyo3::gc::PyVisit<'_>) -> ::core::result::Result<(), ::pyo3::gc::PyTraverseError>

impl PyClassNewTextSignature for TransportCodec
Section titled “impl PyClassNewTextSignature for TransportCodec”
  • const TEXT_SIGNATURE: &'static str
  • fn arguments(self, py: Python<'_>) -> Py<PyAny>
impl PyMethods for ::pyo3::impl_::pyclass::PyClassImplCollector<TransportCodec>
Section titled “impl PyMethods for ::pyo3::impl_::pyclass::PyClassImplCollector<TransportCodec>”
  • fn py_methods(self) -> &'static ::pyo3::impl_::pyclass::PyClassItems
  • fn type_check(object: &Bound<'_, PyAny>) -> bool

  • fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>

  • fn type_object_raw(py: ::pyo3::Python<'_>) -> *mut ::pyo3::ffi::PyTypeObject
  • type Output = T