Zer0 Proto Mp
Frames and Wire
Frame layout and wire format in `zer0-proto-mp` — varint-prefixed frames with type tags and length-delimited payloads.
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, BytesMut};
use zer0_proto_mp::{decode_varint, encode_varint, ChannelId, Frame, MessageType};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Frame::encode serializes a typed frame to its on-wire bytes. The first
// byte carries the MessageType; channel id and payload follow as varints.
let frame = Frame::new(
ChannelId(7),
MessageType::Data,
Bytes::from_static(b"frames are typed"),
);
let wire = frame.encode();
// The decoder is incremental: feed bytes into a BytesMut and call
// decode() until it returns Ok(Some(frame)).
let mut buffer = BytesMut::from(&wire[..]);
let parsed = Frame::decode(&mut buffer)?.expect("complete frame");
// varint helpers are exported for callers building their own framing.
let mut len_buf = BytesMut::new();
encode_varint(parsed.payload.len() as u64, &mut len_buf);
let (decoded_len, _consumed) = decode_varint(&len_buf)?;
println!(
"wire_bytes={} encoded_size={} parsed_channel={} payload_len_varint={}",
wire.len(),
frame.encoded_size(),
parsed.channel.0,
decoded_len,
);
Ok(())
}