#![allow(clippy::print_stdout, clippy::print_stderr)]
use std::thread;
use std::time::Duration;
use zerodds_dcps::{
DataWriterQos, DomainParticipantFactory, DomainParticipantQos, PublisherQos, RawBytes, TopicQos,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let factory = DomainParticipantFactory::instance();
let participant = factory.create_participant(0, DomainParticipantQos::default())?;
let topic = participant.create_topic::<RawBytes>("Chatter", TopicQos::default())?;
let publisher = participant.create_publisher(PublisherQos::default());
let writer = publisher.create_datawriter::<RawBytes>(&topic, DataWriterQos::default())?;
println!("hello_dds_publisher: sending on Domain 0 Topic 'Chatter' — Ctrl-C to stop");
thread::sleep(Duration::from_secs(3));
let mut counter: u32 = 0;
loop {
let payload = format!("hello #{counter}");
writer.write(&RawBytes::new(payload.clone().into_bytes()))?;
println!(" -> {payload}");
counter = counter.wrapping_add(1);
thread::sleep(Duration::from_secs(1));
}
}