rustdds/serialization/
representation_identifier.rs1use std::io;
2
3use speedy::{Readable, Writable};
4use byteorder::ReadBytesExt;
5
6#[derive(Debug, PartialEq, Eq, Clone, Copy, Readable, Writable)]
8pub struct RepresentationIdentifier {
9 pub(crate) bytes: [u8; 2], }
11
12impl RepresentationIdentifier {
13 pub const CDR_BE: Self = Self {
15 bytes: [0x00, 0x00],
16 };
17 pub const CDR_LE: Self = Self {
18 bytes: [0x00, 0x01],
19 };
20
21 pub const PL_CDR_BE: Self = Self {
22 bytes: [0x00, 0x02],
23 };
24 pub const PL_CDR_LE: Self = Self {
25 bytes: [0x00, 0x03],
26 };
27
28 pub const CDR2_BE: Self = Self {
32 bytes: [0x00, 0x10],
33 };
34 pub const CDR2_LE: Self = Self {
35 bytes: [0x00, 0x11],
36 };
37
38 pub const PL_CDR2_BE: Self = Self {
39 bytes: [0x00, 0x12],
40 };
41 pub const PL_CDR2_LE: Self = Self {
42 bytes: [0x00, 0x13],
43 };
44
45 pub const D_CDR_BE: Self = Self {
46 bytes: [0x00, 0x14],
47 };
48 pub const D_CDR_LE: Self = Self {
49 bytes: [0x00, 0x15],
50 };
51
52 pub const XML: Self = Self {
54 bytes: [0x00, 0x04],
55 };
56
57 pub const XCDR2_BE: Self = Self {
63 bytes: [0x00, 0x06],
64 };
65
66 pub const XCDR2_LE: Self = Self {
67 bytes: [0x00, 0x07],
68 };
69
70 pub const D_CDR2_BE: Self = Self {
71 bytes: [0x00, 0x08],
72 };
73
74 pub const D_CDR2_LE: Self = Self {
75 bytes: [0x00, 0x09],
76 };
77
78 pub const PL_XCDR2_BE: Self = Self {
80 bytes: [0x00, 0x0a],
81 };
82 pub const PL_XCDR2_LE: Self = Self {
84 bytes: [0x00, 0x0b],
85 };
86
87 pub fn from_bytes(bytes: &[u8]) -> io::Result<Self> {
89 let mut reader = io::Cursor::new(bytes);
90 Ok(Self {
91 bytes: [reader.read_u8()?, reader.read_u8()?],
92 })
93 }
94
95 pub fn to_bytes(self) -> [u8; 2] {
96 self.bytes
97 }
98}