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.rsChannelHandle— libs/zer0-proto-mp/src/channel.rsChannelId— libs/zer0-proto-mp/src/frame.rsChannelStats— libs/zer0-proto-mp/src/channel.rsFrame— libs/zer0-proto-mp/src/frame.rsHandshakeConfig— libs/zer0-proto-mp/src/protocol.rsMessageId— libs/zer0-proto-mp/src/protocol.rsMessageSchema— libs/zer0-proto-mp/src/protocol.rsMuxConfig— libs/zer0-proto-mp/src/config.rsMuxMetrics— libs/zer0-proto-mp/src/metrics.rsProtocol— libs/zer0-proto-mp/src/protocol.rsProtocolBuilder— 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(())
}