WeaveDocs
Zer0 Proto Mp

Protocol Builder

Protocol builder in `zer0-proto-mp` — declarative composition of channels, schemas, and per-channel handlers.

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 zer0_proto_mp::protocol::{Protocol, ProtocolBuilder, ProtocolFeature};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // ProtocolBuilder accumulates name, version, and feature flags. Each
    // channel registers a Protocol that the peer must support.
    let protocol: Protocol = ProtocolBuilder::new("weave.control")
        .version(2)
        .feature(ProtocolFeature::FlowControl)
        .feature(ProtocolFeature::Multiplexing)
        .feature(ProtocolFeature::Compression)
        .build()?;

    // Protocols are negotiated during channel open; the peer side replies
    // with a compatible Protocol or rejects the channel.
    println!(
        "name={} version={} feature_count={}",
        protocol.name(),
        protocol.version(),
        protocol.features().len(),
    );
    Ok(())
}