Skip to content

rerun-io/re_cdr

re_cdr

CDR (Common Data Representation) codec for ROS 2 / DDS messages.

re_cdr decodes and encodes CDR.

It is aimed at ROS 2 reflection: decoding messages whose layout is only known at runtime, as when reading MCAP. Inspired by cdr-encoding and hiroz-cdr.

API

CdrSerializer and CdrDeserializer integrate with serde for static Rust types.

CdrReader and CdrWriter read and write aligned primitives for runtime schemas. CdrReader::read_numeric_vec handles numeric arrays (float32[], uint32[], ...), using a byte-copy path when the message byte order matches the host and per-element reads otherwise.

Readers and writers are generic over byteorder::ByteOrder. Choose LittleEndian or BigEndian from the message encapsulation header.

Usage

Static types

use re_cdr::{from_bytes, to_vec, LittleEndian};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Vector3 { x: f64, y: f64, z: f64 }

let v = Vector3 { x: 1.0, y: 2.0, z: 3.0 };

let bytes = to_vec::<Vector3, LittleEndian>(&v).unwrap();
let (decoded, consumed) = from_bytes::<Vector3, LittleEndian>(&bytes).unwrap();

assert_eq!(decoded, v);
assert_eq!(consumed, bytes.len());

License

Apache-2.0 or MIT

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors