1use speedy::{Context, Readable, Reader, Writable, Writer};
2
3#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Ord, Eq)]
4pub struct EntityId_t {
5 entityKey: [u8; 3],
6 entityKind: u8,
7}
8
9impl EntityId_t {
10 pub const ENTITYID_UNKNOWN: EntityId_t = EntityId_t {
11 entityKey: [0x00; 3],
12 entityKind: 0x00,
13 };
14 pub const ENTITYID_PARTICIPANT: EntityId_t = EntityId_t {
15 entityKey: [0x00, 0x00, 0x01],
16 entityKind: 0xC1,
17 };
18 pub const ENTITYID_SEDP_BUILTIN_TOPIC_WRITER: EntityId_t = EntityId_t {
19 entityKey: [0x00, 0x00, 0x02],
20 entityKind: 0xC2,
21 };
22 pub const ENTITYID_SEDP_BUILTIN_TOPIC_READER: EntityId_t = EntityId_t {
23 entityKey: [0x00, 0x00, 0x02],
24 entityKind: 0xC7,
25 };
26 pub const ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER: EntityId_t = EntityId_t {
27 entityKey: [0x00, 0x00, 0x03],
28 entityKind: 0xC2,
29 };
30 pub const ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER: EntityId_t = EntityId_t {
31 entityKey: [0x00, 0x00, 0x03],
32 entityKind: 0xC7,
33 };
34 pub const ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER: EntityId_t = EntityId_t {
35 entityKey: [0x00, 0x00, 0x04],
36 entityKind: 0xC2,
37 };
38 pub const ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER: EntityId_t = EntityId_t {
39 entityKey: [0x00, 0x00, 0x04],
40 entityKind: 0xC7,
41 };
42 pub const ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER: EntityId_t = EntityId_t {
43 entityKey: [0x00, 0x01, 0x00],
44 entityKind: 0xC2,
45 };
46 pub const ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER: EntityId_t = EntityId_t {
47 entityKey: [0x00, 0x01, 0x00],
48 entityKind: 0xC7,
49 };
50 pub const ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER: EntityId_t = EntityId_t {
51 entityKey: [0x00, 0x02, 0x00],
52 entityKind: 0xC2,
53 };
54 pub const ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_READER: EntityId_t = EntityId_t {
55 entityKey: [0x00, 0x02, 0x00],
56 entityKind: 0xC7,
57 };
58}
59
60impl Default for EntityId_t {
61 fn default() -> EntityId_t {
62 EntityId_t::ENTITYID_UNKNOWN
63 }
64}
65
66impl<'a, C: Context> Readable<'a, C> for EntityId_t {
67 #[inline]
68 fn read_from<R: Reader<'a, C>>(reader: &mut R) -> Result<Self, C::Error> {
69 let entityKey = [reader.read_u8()?, reader.read_u8()?, reader.read_u8()?];
70 let entityKind = reader.read_u8()?;
71 Ok(EntityId_t {
72 entityKey,
73 entityKind,
74 })
75 }
76}
77
78impl<C: Context> Writable<C> for EntityId_t {
79 #[inline]
80 fn write_to<T: ?Sized + Writer<C>>(&self, writer: &mut T) -> Result<(), C::Error> {
81 for elem in &self.entityKey {
82 writer.write_u8(*elem)?
83 }
84 writer.write_u8(self.entityKind)
85 }
86}
87
88#[cfg(test)]
89mod tests {
90 use super::*;
91
92 serialization_test!( type = EntityId_t,
93 {
94 entity_unknown,
95 EntityId_t::ENTITYID_UNKNOWN,
96 le = [0x00, 0x00, 0x00, 0x00],
97 be = [0x00, 0x00, 0x00, 0x00]
98 },
99 {
100 entity_default,
101 EntityId_t::default(),
102 le = [0x00, 0x00, 0x00, 0x00],
103 be = [0x00, 0x00, 0x00, 0x00]
104 },
105 {
106 entity_participant,
107 EntityId_t::ENTITYID_PARTICIPANT,
108 le = [0x00, 0x00, 0x01, 0xC1],
109 be = [0x00, 0x00, 0x01, 0xC1]
110 },
111 {
112 entity_sedp_builtin_topic_writer,
113 EntityId_t::ENTITYID_SEDP_BUILTIN_TOPIC_WRITER,
114 le = [0x00, 0x00, 0x02, 0xC2],
115 be = [0x00, 0x00, 0x02, 0xC2]
116 },
117 {
118 entity_sedp_builtin_topic_reader,
119 EntityId_t::ENTITYID_SEDP_BUILTIN_TOPIC_READER,
120 le = [0x00, 0x00, 0x02, 0xC7],
121 be = [0x00, 0x00, 0x02, 0xC7]
122 },
123 {
124 entity_sedp_builtin_publications_writer,
125 EntityId_t::ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER,
126 le = [0x00, 0x00, 0x03, 0xC2],
127 be = [0x00, 0x00, 0x03, 0xC2]
128 },
129 {
130 entity_sedp_builtin_publications_reader,
131 EntityId_t::ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER,
132 le = [0x00, 0x00, 0x03, 0xC7],
133 be = [0x00, 0x00, 0x03, 0xC7]
134 },
135 {
136 entity_sedp_builtin_subscriptions_writer,
137 EntityId_t::ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER,
138 le = [0x00, 0x00, 0x04, 0xC2],
139 be = [0x00, 0x00, 0x04, 0xC2]
140 },
141 {
142 entity_sedp_builtin_subscriptions_reader,
143 EntityId_t::ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER,
144 le = [0x00, 0x00, 0x04, 0xC7],
145 be = [0x00, 0x00, 0x04, 0xC7]
146 },
147 {
148 entity_spdp_builtin_participant_writer,
149 EntityId_t::ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER,
150 le = [0x00, 0x01, 0x00, 0xC2],
151 be = [0x00, 0x01, 0x00, 0xC2]
152 },
153 {
154 entity_spdp_builtin_participant_reader,
155 EntityId_t::ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER,
156 le = [0x00, 0x01, 0x00, 0xC7],
157 be = [0x00, 0x01, 0x00, 0xC7]
158 },
159 {
160 entity_p2p_builtin_participant_message_writer,
161 EntityId_t::ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER,
162 le = [0x00, 0x02, 0x00, 0xC2],
163 be = [0x00, 0x02, 0x00, 0xC2]
164 },
165 {
166 entity_p2p_builtin_participant_message_reader,
167 EntityId_t::ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_READER,
168 le = [0x00, 0x02, 0x00, 0xC7],
169 be = [0x00, 0x02, 0x00, 0xC7]
170 }
171 );
172}