cdr_encoding/
lib.rs

1//! OMG Common Data Representation (CDR) serialization with Serde
2//! See [Wikipedia](https://en.wikipedia.org/wiki/Common_Data_Representation) or
3//! [specification in Section "9.3 CDR Transfer Syntax"](https://www.omg.org/spec/CORBA/3.4/Interoperability/PDF).
4//!
5//! [Full XTYPES specification](https://www.omg.org/spec/DDS-XTypes/1.2/PDF), which covers a lot more.
6//! This implemention is only for "plain" CDR.
7//!
8//! # Example
9//!
10//! ```
11//!  use cdr_encoding::*;
12//!  use serde::{Serialize, Deserialize};
13//!  use byteorder::LittleEndian;
14//!
15//!  // This example is originally from https://www.omg.org/spec/DDSI-RTPS/2.3/PDF
16//!  // 10.7 Example for User-defined Topic Data
17//!  #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
18//!  struct ShapeType {
19//!    color: String,
20//!    x: i32,
21//!    y: i32,
22//!    size: i32,
23//!  }
24//!
25//!  let message = ShapeType {
26//!    color: "BLUE".to_string(),
27//!    x: 34,
28//!    y: 100,
29//!    size: 24,
30//!  };
31//!
32//!  let expected_serialized_result: Vec<u8> = vec![
33//!    0x05, 0x00, 0x00, 0x00, 0x42, 0x4c, 0x55, 0x45, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00,
34//!    0x00, 0x64, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
35//!  ];
36//!
37//!  let serialized = to_vec::<ShapeType, LittleEndian>(&message).unwrap();
38//!  assert_eq!(serialized, expected_serialized_result);
39//!
40//!  let (deserialized_message, _consumed_byte_count)
41//!    = from_bytes::<ShapeType, LittleEndian>(&serialized).unwrap();
42//!  assert_eq!(deserialized_message, message);
43//! ```
44
45mod cdr_deserializer;
46mod cdr_serializer;
47mod error;
48
49pub use cdr_deserializer::{from_bytes, CdrDeserializer};
50pub use cdr_serializer::{to_vec, to_vec_with_size_hint, to_writer, CdrSerializer};
51pub use error::{Error, Result};