rustdds/messages/submessages/
heartbeat_frag.rs

1use speedy::{Readable, Writable};
2
3use crate::structure::{
4  guid::EntityId,
5  sequence_number::{FragmentNumber, SequenceNumber},
6};
7use super::submessage::HasEntityIds;
8
9/// When fragmenting data and until all fragments are available, the
10/// HeartbeatFrag Submessage is sent from an RTPS Writer to an RTPS Reader to
11/// communicate which fragments the Writer has available. This enables reliable
12/// communication at the fragment level.
13///
14/// Once all fragments are available, a regular Heartbeat message is used.
15#[derive(Debug, PartialEq, Eq, Clone, Readable, Writable)]
16pub struct HeartbeatFrag {
17  /// Identifies the Reader Entity that is being informed of the availability
18  /// of fragments. Can be set to UNKNOWN to indicate all readers for
19  /// the writer that sent the message.
20  pub reader_id: EntityId,
21
22  /// Identifies the Writer Entity that sent the Submessage.
23  pub writer_id: EntityId,
24
25  /// Identifies the sequence number of the data change for which fragments
26  /// are available.
27  pub writer_sn: SequenceNumber,
28
29  /// All fragments up to and including this last (highest) fragment are
30  /// available on the Writer for the change identified by writerSN.
31  pub last_fragment_num: FragmentNumber,
32
33  /// A counter that is incremented each time a new HeartbeatFrag message is
34  /// sent. Provides the means for a Reader to detect duplicate HeartbeatFrag
35  /// messages that can result from the presence of redundant communication
36  /// paths.
37  pub count: i32,
38}
39
40impl HasEntityIds for HeartbeatFrag {
41  fn receiver_entity_id(&self) -> EntityId {
42    self.reader_id
43  }
44  fn sender_entity_id(&self) -> EntityId {
45    self.writer_id
46  }
47}
48
49#[cfg(test)]
50mod tests {
51  use super::*;
52
53  serialization_test!( type = HeartbeatFrag,
54  {
55      heartbeat_frag,
56      HeartbeatFrag {
57          reader_id: EntityId::SEDP_BUILTIN_PUBLICATIONS_READER,
58          writer_id: EntityId::SEDP_BUILTIN_PUBLICATIONS_WRITER,
59          writer_sn: SequenceNumber::from(42),
60          last_fragment_num: FragmentNumber::from(99_u32),
61          count: 6,
62      },
63      le = [0x00, 0x00, 0x03, 0xC7,
64            0x00, 0x00, 0x03, 0xC2,
65            0x00, 0x00, 0x00, 0x00,
66            0x2A, 0x00, 0x00, 0x00,
67            0x63, 0x00, 0x00, 0x00,
68            0x06, 0x00, 0x00, 0x00],
69      be = [0x00, 0x00, 0x03, 0xC7,
70            0x00, 0x00, 0x03, 0xC2,
71            0x00, 0x00, 0x00, 0x00,
72            0x00, 0x00, 0x00, 0x2A,
73            0x00, 0x00, 0x00, 0x63,
74            0x00, 0x00, 0x00, 0x06]
75  });
76}