Struct rustdds::dds::with_key::DataWriter [−][src]
pub struct DataWriter<D: Keyed + Serialize, SA: SerializerAdapter<D> = CDRSerializerAdapter<D>> { /* fields omitted */ }
Expand description
DDS DataWriter for keyed topics
Examples
use serde::{Serialize, Deserialize};
use rustdds::dds::DomainParticipant;
use rustdds::dds::qos::QosPolicyBuilder;
use rustdds::dds::data_types::TopicKind;
use rustdds::dds::With_Key_DataWriter as DataWriter;
use rustdds::dds::traits::Keyed;
use rustdds::serialization::CDRSerializerAdapter;
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None);
Implementations
impl<D, SA> DataWriter<D, SA> where
D: Keyed + Serialize,
<D as Keyed>::K: Key,
SA: SerializerAdapter<D>,
impl<D, SA> DataWriter<D, SA> where
D: Keyed + Serialize,
<D as Keyed>::K: Key,
SA: SerializerAdapter<D>,
Manually refreshes liveliness if QoS allows it
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
data_writer.refresh_manual_liveliness();
Writes single data instance to a topic.
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
let some_data = SomeType { a: 1 };
data_writer.write(some_data, None).unwrap();
This operation blocks the calling thread until either all data written by the
reliable DataWriter entities is acknowledged by all
matched reliable DataReader entities, or else the duration specified by the
max_wait
parameter elapses, whichever happens first.
See DDS Spec 1.4 Section 2.2.2.4.1.12 wait_for_acknowledgments.
If this DataWriter is not set to Realiable, or there are no matched DataReaders with Realibale QoS, the call succeeds imediately.
Return values
Ok(true)
- all acknowledgedOk(false)
- timed out waiting for acknowledgmentsErr(_)
- something went wrong
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
let some_data = SomeType { a: 1 };
data_writer.write(some_data, None).unwrap();
data_writer.wait_for_acknowledgments(std::time::Duration::from_millis(100));
Topic assigned to this DataWriter
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic.clone(), None).unwrap();
assert_eq!(data_writer.get_topic(), &topic);
Publisher assigned to this DataWriter
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
assert_eq!(data_writer.get_publisher(), &publisher);
Manually asserts liveliness (use this instead of refresh) according to QoS
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
data_writer.assert_liveliness().unwrap();
Unimplemented. Do not use.
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
for sub in data_writer.get_matched_subscriptions().iter() {
// do something
}
Disposes data instance with specified key
Arguments
key
- Key of the instancesource_timestamp
- DDS source timestamp (None uses now as time as specified in DDS spec)
Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType { a: i32, val: usize }
impl Keyed for SomeType {
type K = i32;
fn get_key(&self) -> Self::K {
self.a
}
}
// WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(topic, None).unwrap();
let some_data_1_1 = SomeType { a: 1, val: 3};
let some_data_1_2 = SomeType { a: 1, val: 4};
// different key
let some_data_2_1 = SomeType { a: 2, val: 5};
let some_data_2_2 = SomeType { a: 2, val: 6};
data_writer.write(some_data_1_1, None).unwrap();
data_writer.write(some_data_1_2, None).unwrap();
data_writer.write(some_data_2_1, None).unwrap();
data_writer.write(some_data_2_2, None).unwrap();
// disposes both some_data_1_1 and some_data_1_2. They are no longer offered by this writer to this topic.
data_writer.dispose(1, None).unwrap();