rustzmq2 0.1.0

A native async Rust implementation of ZeroMQ
Documentation
//! Implements a codec for ZMQ, providing a way to convert from a byte-oriented
//! io device to a protocal comprised of [`Message`] frames. See [`FramedIo`]

mod command;
pub(crate) mod framed;
mod greeting;
pub(crate) mod handshake;
pub(crate) mod mechanism;
pub(crate) mod zmq_codec;

pub(crate) use crate::error::CodecError;
#[cfg(any(feature = "tcp", all(feature = "ipc", target_family = "unix")))]
pub(crate) use crate::error::CodecResult;
#[cfg(feature = "curve")]
pub(crate) use command::CurveFrame;
pub use command::HeartbeatFrame;
#[cfg(any(feature = "tcp", all(feature = "ipc", target_family = "unix")))]
pub(crate) use command::PlainFrame;
pub(crate) use command::ZmqCommand;
#[cfg(any(feature = "tcp", all(feature = "ipc", target_family = "unix")))]
pub(crate) use command::ZmqCommandName;
#[cfg(all(feature = "smol", not(feature = "tokio"), feature = "tcp"))]
pub(crate) use framed::smol::SmolFramedIo;
#[cfg(all(
    feature = "tokio",
    any(feature = "tcp", all(feature = "ipc", target_family = "unix"))
))]
pub(crate) use framed::TcpFramedIo as DefaultFramedIo;
pub use framed::{FramedIo, IntoEngineWriter};

/// Runtime-neutral concrete `FramedIo` alias: `DefaultFramedIo` under tokio,
/// `SmolFramedIo` under smol. The two runtimes are mutually exclusive.
/// Only used by wire transports (TCP/IPC); inproc bypasses framing entirely.
#[cfg(all(
    feature = "tokio",
    any(feature = "tcp", all(feature = "ipc", target_family = "unix"))
))]
pub(crate) type RuntimeFramedIo = DefaultFramedIo;
#[cfg(all(
    feature = "smol",
    not(feature = "tokio"),
    any(feature = "tcp", all(feature = "ipc", target_family = "unix"))
))]
pub(crate) type RuntimeFramedIo = SmolFramedIo;
pub(crate) use greeting::{ZmqGreeting, ZmtpVersion};
#[cfg(any(feature = "tcp", all(feature = "ipc", target_family = "unix")))]
pub(crate) use zmq_codec::ZmqCodec;

use crate::message::ZmqMessage;

use std::sync::Arc;

#[allow(clippy::enum_variant_names)]
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum Message {
    Greeting(ZmqGreeting),
    Command(ZmqCommand),
    Message(ZmqMessage),
    /// Shared broadcast payload. Used by PUB/XPUB to fan one message out to N
    /// subscribers via a single `Arc::clone` instead of cloning the `VecDeque`
    /// plus every Bytes refcount per subscriber.
    ///
    /// Protocol-level semantics are identical to `Message`; the only
    /// difference is ownership.
    Shared(Arc<ZmqMessage>),
    /// ZMTP PING/PONG heartbeat frame. The `#[non_exhaustive]` attribute
    /// on `Message` prevents downstream `match` arms from breaking on this
    /// addition.
    Heartbeat(HeartbeatFrame),
    /// Raw security handshake command frame (HELLO/WELCOME/INITIATE/READY/ERROR).
    /// Emitted by the codec for all mechanism-specific command names so
    /// that `mechanism.rs` can parse them with mechanism context rather
    /// than the codec needing to know which mechanism is active.
    SecurityRaw(bytes::Bytes),
}