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
use std::fmt;

use speedy::{Readable, Writable};

/// Type for DDS Topic (With Key or No key)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Readable, Writable)]
#[repr(u32)]
pub enum TopicKind {
  NoKey = 1,
  WithKey = 2,
}

impl fmt::Display for TopicKind {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    write!(
      f,
      "{}",
      match self {
        TopicKind::NoKey => "NoKey",
        TopicKind::WithKey => "WithKey",
      }
    )
  }
}

#[cfg(test)]
mod tests {
  use super::*;

  serialization_test!(type = TopicKind,
  {
      topic_kind_no_key,
      TopicKind::NoKey,
      le = [0x01, 0x00, 0x00, 0x00],
      be = [0x00, 0x00, 0x00, 0x01]
  },
  {
      topic_kind_with_key,
      TopicKind::WithKey,
      le = [0x02, 0x00, 0x00, 0x00],
      be = [0x00, 0x00, 0x00, 0x02]
  });
}