Crate cdr

source ·
Expand description

A serialization/deserialization implementation for Common Data Representation.

Examples

use cdr::{CdrBe, Infinite};
use serde_derive::{Deserialize, Serialize};

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

#[derive(Deserialize, Serialize, PartialEq)]
struct Polygon(Vec<Point>);

fn main() {
    let triangle = Polygon(vec![Point { x: -1.0, y: -1.0 },
                                Point { x: 1.0, y: -1.0 },
                                Point { x: 0.0, y: 0.73 }]);

    let encoded = cdr::serialize::<_, _, CdrBe>(&triangle, Infinite).unwrap();
    let decoded = cdr::deserialize::<Polygon>(&encoded[..]).unwrap();

    assert!(triangle == decoded);
}

Modules

Deserializing CDR into Rust data types.
Serializing Rust data types into CDR.
Measuring the size of (de)serialized data.

Structs

A SizeLimit that restricts serialized or deserialized messages so that they do not exceed a certain byte length.
A deserializer that reads bytes from a buffer.
The Error type.
A SizeLimit without a limit.
A serializer that writes values into a buffer.

Enums

Defines big-endian serialization.
OMG CDR big-endian encapsulation.
OMG CDR little-endian encapsulation.
The kind of an error.
Defines little-endian serialization.
ParameterList encapsulated using OMG CDR big-endian encapsulation.
ParameterList encapsulated using OMG CDR little-endian encapsulation.

Traits

Data encapsulation scheme identifiers.
Limits on the number of bytes that can be read or written.

Functions

Returns the size that an object would be if serialized with a encapsulation.
Given a maximum size limit, check how large an object would be if it were to be serialized with a encapsulation.
Deserializes a slice of bytes into an object.
Deserializes an object directly from a Read.
Serializes a serializable object into a Vec of bytes with the encapsulation.
Serializes an object directly into a Write with the encapsulation.

Type Definitions

Convenient wrapper around std::Result.