Expand description
§Zenobuf Core - A simpler ROS-like framework in Rust
Zenobuf is a lightweight, ergonomic framework for building distributed systems in Rust. It provides a publish-subscribe messaging system, a service-based RPC system, and a parameter system, similar to ROS (Robot Operating System) but with a more Rust-idiomatic API.
§Features
- Publish-Subscribe Messaging: Send and receive messages on topics
- Service-Based RPC: Request-response communication between nodes
- Parameter System: Store and retrieve configuration values
- Type-Safe API: Leverage Rust’s type system for compile-time guarantees
- Protocol Buffers Integration: Use Protocol Buffers for message serialization
- Zenoh Transport: Efficient pub/sub and query/reply using Zenoh
§Quick Start
§1. Add Dependencies
[dependencies]
zenobuf-core = "0.2"
zenobuf-macros = "0.2"
prost = "0.13"
tokio = { version = "1", features = ["full"] }
[build-dependencies]
prost-build = "0.13"
§2. Define Messages with Protocol Buffers
Create protos/messages.proto
:
syntax = "proto3";
package my_app;
message Point {
float x = 1;
float y = 2;
float z = 3;
}
§3. Setup Build Script
Create build.rs
:
ⓘ
fn main() -> std::io::Result<()> {
prost_build::Config::new()
.type_attribute(".", "#[derive(zenobuf_macros::ZenobufMessage)]")
.compile_protos(&["protos/messages.proto"], &["protos"])?;
Ok(())
}
§4. Create a Node and Publisher
ⓘ
use zenobuf_core::Node;
// Include generated protobuf code
pub mod proto {
include!(concat!(env!("OUT_DIR"), "/my_app.rs"));
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a node
let node = Node::new("my_node").await?;
// Create a publisher
let publisher = node
.publisher::<proto::Point>("points")
.build()
.await?;
// Create and publish a message
let point = proto::Point {
x: 1.0,
y: 2.0,
z: 3.0,
};
publisher.publish(&point)?;
Ok(())
}
§5. Create a Subscriber
ⓘ
use zenobuf_core::Node;
// Use the same proto module from above
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let node = Node::new("subscriber_node").await?;
// Create a subscriber with a callback
let _subscriber = node
.subscriber::<proto::Point>("points")
.build(|point| {
println!("Received point: ({}, {}, {})", point.x, point.y, point.z);
})
.await?;
// Keep the node running
node.spin().await?;
Ok(())
}
§Architecture
Zenobuf is built around several key concepts:
- Node: The main entry point that manages publishers, subscribers, services, and clients
- Publisher: Sends messages to topics
- Subscriber: Receives messages from topics
- Service: Handles request-response communication
- Client: Makes requests to services
- Message: Trait for types that can be sent over the network
- QosProfile: Quality of Service settings for reliable communication
§Examples
For complete examples, see the zenobuf-examples
crate which includes:
- Publisher/Subscriber examples
- Service/Client examples
- Parameter usage
- Complete applications
§Getting Started Template
The fastest way to get started is to copy the starter template:
git clone https://github.com/varunkamath/zenobuf
cp -r zenobuf/starter-template my-zenobuf-app
cd my-zenobuf-app
cargo run
Re-exports§
pub use client::Client;
pub use error::Error;
pub use error::Result;
pub use message::Message;
pub use node::ClientHandle;
pub use node::DropGuard;
pub use node::Node;
pub use node::PublisherHandle;
pub use node::ServiceHandle;
pub use node::SubscriberHandle;
pub use parameter::Parameter;
pub use publisher::Publisher;
pub use qos::QosPreset;
pub use qos::QosProfile;
pub use service::Service;
pub use subscriber::Subscriber;
pub use transport::Transport;
pub use transport::ZenohTransport;
Modules§
- client
- Client implementation for Zenobuf
- error
- Error types for the Zenobuf framework
- message
- Message trait and utilities for working with Protocol Buffer messages
- node
- Node abstraction for Zenobuf
- parameter
- Parameter system for Zenobuf
- publisher
- Publisher implementation for Zenobuf
- qos
- Quality of Service (QoS) profiles for Zenobuf
- service
- Service implementation for Zenobuf
- subscriber
- Subscriber implementation for Zenobuf
- time
- Time utilities for Zenobuf
- transport
- Transport layer abstraction for Zenobuf