WeaveDocs
Zer0 Proto Mp

Channels

Multiplexed channels in `zer0-proto-mp` — open, close, and route per-channel traffic over a single shared transport.

Purpose

Protocol multiplexing with channels, frames, varints, schemas, handshakes, metrics, and stream integration.

This page follows the real source shape for Zer0 Proto Mp and explains the workflow a developer is likely to use first.

Developer workflow

Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.

Primary types to know

  • Channel — libs/zer0-proto-mp/src/channel.rs
  • ChannelHandle — libs/zer0-proto-mp/src/channel.rs
  • ChannelId — libs/zer0-proto-mp/src/frame.rs
  • ChannelStats — libs/zer0-proto-mp/src/channel.rs
  • Frame — libs/zer0-proto-mp/src/frame.rs
  • HandshakeConfig — libs/zer0-proto-mp/src/protocol.rs
  • MessageId — libs/zer0-proto-mp/src/protocol.rs
  • MessageSchema — libs/zer0-proto-mp/src/protocol.rs
  • MuxConfig — libs/zer0-proto-mp/src/config.rs
  • MuxMetrics — libs/zer0-proto-mp/src/metrics.rs
  • Protocol — libs/zer0-proto-mp/src/protocol.rs
  • ProtocolBuilder — libs/zer0-proto-mp/src/protocol.rs

Example shape

use bytes::Bytes;
use zer0_proto_mp::{ChannelId, Frame, MessageType, MuxConfig, WeaveMux};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // The mux multiplexes many logical channels over one underlying stream.
    // ChannelHandle owns the per-channel credit window and stats.
    let (stream_a, _stream_b) = tokio::io::duplex(64 * 1024);
    let mut mux = WeaveMux::new(stream_a, MuxConfig::default());

    let handle = mux.open_channel("control").await?;
    let frame = Frame::data(handle.id(), Bytes::from_static(b"ping"));
    mux.send(frame).await?;

    let stats = handle.stats();
    println!(
        "channel_id={} sent_frames={} sent_bytes={} message_type_data={:?}",
        handle.id().0,
        stats.frames_sent,
        stats.bytes_sent,
        MessageType::Data,
    );
    Ok(())
}