#data-encoding #dds #protocols #data-transfer #deserialize #networking #rtps

cdr-encoding

Serde implementation of OMG Common Data Representation (CDR) encoding

3 releases

0.10.2 Sep 24, 2024
0.10.1 Apr 24, 2024
0.10.0 Apr 23, 2024

#1636 in Encoding

Download history 752/week @ 2024-08-19 1355/week @ 2024-08-26 331/week @ 2024-09-02 1043/week @ 2024-09-09 701/week @ 2024-09-16 981/week @ 2024-09-23 467/week @ 2024-09-30 1451/week @ 2024-10-07 286/week @ 2024-10-14 417/week @ 2024-10-21 459/week @ 2024-10-28 863/week @ 2024-11-04 1863/week @ 2024-11-11 1225/week @ 2024-11-18 1408/week @ 2024-11-25 1272/week @ 2024-12-02

5,794 downloads per month
Used in 5 crates (via rustdds)

Apache-2.0

61KB
1.5K SLoC

OMG Common Data Representation (CDR) serialization with Serde

Used by RustDDS and ros2-client.

See Wikipedia or specification in Section "9.3 CDR Transfer Syntax".

This is also a part of the full XTYPES specification. XTYPES specifies several encodings, of which this implemention is only for "plain" CDR.


lib.rs:

OMG Common Data Representation (CDR) serialization with Serde See Wikipedia or specification in Section "9.3 CDR Transfer Syntax".

Full XTYPES specification, which covers a lot more. This implemention is only for "plain" CDR.

Example

 use cdr_encoding::*;
 use serde::{Serialize, Deserialize};
 use byteorder::LittleEndian;

 // This example is originally from https://www.omg.org/spec/DDSI-RTPS/2.3/PDF
 // 10.7 Example for User-defined Topic Data
 #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
 struct ShapeType {
   color: String,
   x: i32,
   y: i32,
   size: i32,
 }

 let message = ShapeType {
   color: "BLUE".to_string(),
   x: 34,
   y: 100,
   size: 24,
 };

 let expected_serialized_result: Vec<u8> = vec![
   0x05, 0x00, 0x00, 0x00, 0x42, 0x4c, 0x55, 0x45, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00,
   0x00, 0x64, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
 ];

 let serialized = to_vec::<ShapeType, LittleEndian>(&message).unwrap();
 assert_eq!(serialized, expected_serialized_result);

 let (deserialized_message, _consumed_byte_count)
   = from_bytes::<ShapeType, LittleEndian>(&serialized).unwrap();
 assert_eq!(deserialized_message, message);

Dependencies

~0.5–1.2MB
~25K SLoC