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
#[cfg(test)]
use bytes::Bytes;
use crate::{
dds::traits::key::KeyHash,
messages::submessages::submessage_elements::serialized_payload::SerializedPayload,
};
//use crate::messages::submessages::submessages::RepresentationIdentifier;
use crate::structure::cache_change::ChangeKind;
// DDSData represets a serialized data sample with metadata
#[derive(Debug, PartialEq, Clone)]
// Contents of a DATA submessage or several DATAFRAG submessages. This is either
// a new sample, or key, or a key hash. The latter two are used to indicate
// dispose or unregister.
pub enum DDSData {
Data {
serialized_payload: SerializedPayload,
},
// DataFrags {
// // Each DATAFRAG specifies RepresentationIdentifier, but we assume they are the same.
// // Otherwise, decoding would be exceedingly confusing.
// representation_identifier: RepresentationIdentifier,
// // The payload is stored as a Vec of Bytes buffers.
// // Deserializer should concateneate these and deserialize.
// bytes_frags: Vec<Bytes>,
// },
DisposeByKey {
change_kind: ChangeKind,
key: SerializedPayload,
},
DisposeByKeyHash {
change_kind: ChangeKind,
key_hash: KeyHash,
},
}
impl DDSData {
pub fn new(serialized_payload: SerializedPayload) -> Self {
Self::Data { serialized_payload }
}
pub fn new_disposed_by_key(change_kind: ChangeKind, key: SerializedPayload) -> Self {
Self::DisposeByKey { change_kind, key }
}
pub fn new_disposed_by_key_hash(change_kind: ChangeKind, key_hash: KeyHash) -> Self {
Self::DisposeByKeyHash {
change_kind,
key_hash,
}
}
#[allow(dead_code)] // Why is this not used?
pub fn change_kind(&self) -> ChangeKind {
match self {
DDSData::Data {..} /*| DDSData::DataFrags {..}*/ => ChangeKind::Alive,
DDSData::DisposeByKey { change_kind, ..} | DDSData::DisposeByKeyHash { change_kind, .. } => *change_kind,
}
}
// pub fn serialized_payload(&self) -> Option<&SerializedPayload> {
// match &self {
// DDSData::Data { serialized_payload } => Some( serialized_payload ),
// DDSData::DisposeByKey { key , ..} => Some( key ),
// DDSData::DisposeByKeyHash {..} => None,
// }
// }
#[cfg(test)]
pub fn data(&self) -> Option<Bytes> {
match &self {
DDSData::Data { serialized_payload } => Some(serialized_payload.value.clone()),
// DDSData::DataFrags { _representation_identifier, bytes_frags } =>
// Some( ) ,
DDSData::DisposeByKey { key, .. } => Some(key.value.clone()),
DDSData::DisposeByKeyHash { .. } => None,
}
}
}