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§

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

Structs§

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

Enums§

BigEndian
Defines big-endian serialization.
CdrBe
OMG CDR big-endian encapsulation.
CdrLe
OMG CDR little-endian encapsulation.
Error
The Error type.
LittleEndian
Defines little-endian serialization.
PlCdrBe
ParameterList encapsulated using OMG CDR big-endian encapsulation.
PlCdrLe
ParameterList encapsulated using OMG CDR little-endian encapsulation.

Traits§

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

Functions§

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

Type Aliases§

Result
Convenient wrapper around std::Result.