rtps_parser/rtps/messages/
types.rs1use super::overall_structure::WriteBytes;
2use std::io::Read;
3
4type Octet = u8;
8type Long = i32;
9type UnsignedLong = u32;
10type Short = i16;
11
12#[derive(Clone, Copy, PartialEq, Eq, Debug)]
16#[allow(non_camel_case_types)]
17pub enum ProtocolId {
18 PROTOCOL_RTPS,
19}
20
21impl WriteBytes for ProtocolId {
22 fn write_bytes(&self, buf: &mut [u8]) -> usize {
23 b"RTPS".as_slice().read(buf).unwrap()
24 }
25}
26
27pub type SubmessageFlag = bool;
31
32impl WriteBytes for [SubmessageFlag; 8] {
33 fn write_bytes(&self, buf: &mut [u8]) -> usize {
34 let mut flags = 0b_0000_0000_u8;
35 for (i, &item) in self.iter().enumerate() {
36 if item {
37 flags |= 0b_0000_0001 << i
38 }
39 }
40 buf[0] = flags;
41 1
42 }
43}
44
45#[derive(Clone, Copy, PartialEq, Eq, Debug)]
50#[allow(non_camel_case_types)]
51#[allow(clippy::upper_case_acronyms)]
52pub enum SubmessageKind {
53 DATA,
54 GAP,
55 HEARTBEAT,
56 ACKNACK,
57 PAD,
58 INFO_TS,
59 INFO_REPLY,
60 INFO_DST,
61 INFO_SRC,
62 DATA_FRAG,
63 NACK_FRAG,
64 HEARTBEAT_FRAG,
65}
66
67pub const DATA: u8 = 0x15;
68pub const GAP: u8 = 0x08;
69pub const HEARTBEAT: u8 = 0x07;
70pub const ACKNACK: u8 = 0x06;
71pub const PAD: u8 = 0x01;
72pub const INFO_TS: u8 = 0x09;
73pub const INFO_REPLY: u8 = 0x0f;
74pub const INFO_DST: u8 = 0x0e;
75pub const INFO_SRC: u8 = 0x0c;
76pub const DATA_FRAG: u8 = 0x16;
77pub const NACK_FRAG: u8 = 0x12;
78pub const HEARTBEAT_FRAG: u8 = 0x13;
79
80impl WriteBytes for SubmessageKind {
81 fn write_bytes(&self, buf: &mut [u8]) -> usize {
82 buf[0] = match self {
83 SubmessageKind::DATA => DATA,
84 SubmessageKind::GAP => GAP,
85 SubmessageKind::HEARTBEAT => HEARTBEAT,
86 SubmessageKind::ACKNACK => ACKNACK,
87 SubmessageKind::PAD => PAD,
88 SubmessageKind::INFO_TS => INFO_TS,
89 SubmessageKind::INFO_REPLY => INFO_REPLY,
90 SubmessageKind::INFO_DST => INFO_DST,
91 SubmessageKind::INFO_SRC => INFO_SRC,
92 SubmessageKind::DATA_FRAG => DATA_FRAG,
93 SubmessageKind::NACK_FRAG => NACK_FRAG,
94 SubmessageKind::HEARTBEAT_FRAG => HEARTBEAT_FRAG,
95 };
96 1
97 }
98}
99
100#[derive(Clone, Copy, Debug, PartialEq, Eq)]
107pub struct Time {
108 seconds: UnsignedLong,
109 fraction: UnsignedLong,
110}
111
112impl Time {
113 pub const fn new(seconds: UnsignedLong, fraction: UnsignedLong) -> Self {
114 Self { seconds, fraction }
115 }
116
117 pub fn seconds(&self) -> UnsignedLong {
118 self.seconds
119 }
120
121 pub fn fraction(&self) -> UnsignedLong {
122 self.fraction
123 }
124}
125
126#[allow(dead_code)]
127pub const TIME_ZERO: Time = Time::new(0, 0);
128pub const TIME_INVALID: Time = Time::new(0xffffffff, 0xffffffff);
129#[allow(dead_code)]
130pub const TIME_INFINITE: Time = Time::new(0xffffffff, 0xfffffffe);
131
132impl WriteBytes for Time {
133 fn write_bytes(&self, buf: &mut [u8]) -> usize {
134 self.seconds.write_bytes(&mut buf[0..]) + self.fraction.write_bytes(&mut buf[4..])
135 }
136}
137
138pub type Count = Long;
141
142#[allow(dead_code)]
146pub type Checksum32 = [Octet; 4];
147
148#[allow(dead_code)]
152struct MessageLength;
153
154pub type ParameterId = Short;
158
159pub type FragmentNumber = UnsignedLong;
163
164#[allow(dead_code)]
167pub type GroupDigest = [Octet; 4];
168
169#[allow(dead_code)]
172pub type UExtension4 = [Octet; 4];
173
174#[allow(dead_code)]
177pub type WExtension8 = [Octet; 8];