7 releases
Uses new Rust 2024
| 0.1.6 | Aug 30, 2025 |
|---|---|
| 0.1.5 | Aug 25, 2025 |
| 0.1.4 | Jul 28, 2025 |
| 0.1.3 | Jun 20, 2025 |
| 0.1.1 | May 24, 2025 |
#5 in #ecal
517 downloads per month
81KB
1.5K
SLoC
rustecal-types-protobuf
rustecal-types-protobuf provides a helper wrapper for Protobuf messages (using prost) to use with the typed eCAL Pub/Sub API.
Features
- ProtobufMessage: wrap and transport Protobuf messages
- Implements
PublisherMessageandSubscriberMessagefor seamless integration - Zero-copy where possible via
Arc::from(ProtobufMessage) - Static descriptor embedding via
include_bytes!(optional) - No extra dependencies beyond
prost,rustecal-coreandrustecal-pubsub
Installation
Add to your workspace Cargo.toml:
[dependencies]
rustecal-types-protobuf = "0.1"
Usage
Publisher Example
use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_protobuf::{ProtobufMessage, IsProtobufType};
mod people { include!(concat!(env!("OUT_DIR"), "/pb.people.rs")); }
mod animal { include!(concat!(env!("OUT_DIR"), "/pb.animal.rs")); }
mod environment { include!(concat!(env!("OUT_DIR"), "/pb.environment.rs")); }
use people::Person;
impl IsProtobufType for Person {}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("protobuf publisher"), EcalComponents::DEFAULT, None)?;
let publisher = TypedPublisher::<ProtobufMessage<Person>>::new("person")?;
while Ecal::ok() {
let person = Person { id: 1, name: "Alice".into(), ..Default::default() };
let message = ProtobufMessage { data : person.into() };
publisher.send(&message, Timestamp::Auto);
std::thread::sleep(std::time::Duration::from_millis(500));
}
Ecal::finalize();
Ok(())
}
Subscriber Example
use rustecal::{Ecal, EcalComponents, TypedSubscriber};
use rustecal_types_protobuf::{ProtobufMessage, IsProtobufType};
mod people { include!(concat!(env!("OUT_DIR"), "/pb.people.rs")); }
mod animal { include!(concat!(env!("OUT_DIR"), "/pb.animal.rs")); }
mod environment { include!(concat!(env!("OUT_DIR"), "/pb.environment.rs")); }
use people::Person;
impl IsProtobufType for Person {}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("protobuf subscriber"), EcalComponents::DEFAULT, None)?;
let mut subscriber = TypedSubscriber::<ProtobufMessage<Person>>::new("person")?;
subscriber.set_callback(|message| {
println!("Received person: {}", message.payload.data.name)
});
while Ecal::ok() {
std::thread::sleep(std::time::Duration::from_millis(500));
}
Ecal::finalize();
Ok(())
}
Traits Reference
-
PublisherMessagedatatype() -> DataTypeInfoto_bytes(&self) -> Arc<[u8]>
-
SubscriberMessagedatatype() -> DataTypeInfofrom_bytes(bytes: Arc<[u8]>, _info: &DataTypeInfo) -> Option<Self>
See Also
rustecal-types-bytesfor raw binary data messagesrustecal-types-stringfor UTF-8 string messagesrustecal-types-serdefor JSON/CBOR/MessagePack via Serde- Examples in the
rustecal-samples/pubsubdirectory
Dependencies
~2.5MB
~53K SLoC