1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::{
serialization::SubMessage, serialization::SubmessageBody, structure::guid::EntityId,
messages::submessages::submessages::SubmessageHeader,
};
use crate::structure::sequence_number::SequenceNumberSet;
use enumflags2::BitFlags;
use log::error;
use speedy::{Readable, Writable};
use super::{
submessage::EntitySubmessage, submessage_flag::ACKNACK_Flags, submessage_kind::SubmessageKind,
};
/// This Submessage is used to communicate the state of a Reader to a
/// Writer.
///
/// The Submessage allows the Reader to inform the Writer about
/// the sequence numbers it has received and which ones it is still
/// missing. This Submessage can be used to do both positive
/// and negative acknowledgments
#[derive(Debug, PartialEq, Readable, Writable)]
pub struct AckNack {
/// Identifies the Reader entity that acknowledges receipt of certain
/// sequence numbers and/or requests to receive certain sequence numbers.
pub reader_id: EntityId,
/// Identifies the Writer entity that is the target of the AckNack message.
/// This is the Writer Entity that is being asked to re-send some sequence
/// numbers or is being informed of the reception of certain sequence
/// numbers.
pub writer_id: EntityId,
/// Communicates the state of the reader to the writer.
/// All sequence numbers up to the one prior to readerSNState.base
/// are confirmed as received by the reader. The sequence numbers that
/// appear in the set indicate missing sequence numbers on the reader
/// side. The ones that do not appear in the set are undetermined (could
/// be received or not).
pub reader_sn_state: SequenceNumberSet,
/// A counter that is incremented each time a new AckNack message is sent.
/// Provides the means for a Writer to detect duplicate AckNack messages
/// that can result from the presence of redundant communication paths.
pub count: i32,
}
impl AckNack {
pub fn create_submessage(self, flags: BitFlags<ACKNACK_Flags>) -> Option<SubMessage> {
let submessage_len = match self.write_to_vec() {
Ok(bytes) => bytes.len() as u16,
Err(e) => {
error!("Reader couldn't write acknack to bytes. Error: {}", e);
return None;
}
};
let acknack_header = SubmessageHeader {
kind: SubmessageKind::ACKNACK,
flags: flags.bits(),
content_length: submessage_len,
};
Some(SubMessage {
header: acknack_header,
body: SubmessageBody::Entity(EntitySubmessage::AckNack(self, flags)),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::structure::sequence_number::SequenceNumber;
serialization_test!( type = AckNack,
{
acknack,
AckNack {
reader_id: EntityId::ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER,
writer_id: EntityId::ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER,
reader_sn_state: SequenceNumberSet::new(SequenceNumber::from(0)),
count: 1,
},
le = [0x00, 0x00, 0x03, 0xC7,
0x00, 0x00, 0x03, 0xC2,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00],
be = [0x00, 0x00, 0x03, 0xC7,
0x00, 0x00, 0x03, 0xC2,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01]
});
}