[][src]Crate serde_xdr

XDR serialization and deserialization for Serde.

This crate implements serialization to and deserialization from the External Data Representation Standard (XDR) using the Serde serialization and deserialization framework.

Usage is mainly through the helper functions:

Examples

extern crate serde_xdr;
extern crate serde_bytes;
#[macro_use]
extern crate serde_derive;

use std::io::Cursor;

use serde_bytes::ByteBuf;
use serde_xdr::{from_reader, to_writer};

#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
enum FileType {
    Text,
    Data(String),
    Exec(String),
}

#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
struct File {
    filename: String,
    filetype: FileType,
    owner: String,
    data: ByteBuf,
}

fn main() {
    let file_contents: Vec<u8> = "(quit)".as_bytes().into();

    let initial_file = File {
        filename: "sillyprog".to_string(),
        filetype: FileType::Exec("lisp".to_string()),
        owner: "john".to_string(),
        data: file_contents.into(),
    };

    // Serialize
    let mut bytes = Vec::new();

    to_writer(&mut bytes, &initial_file).unwrap();

    // Deserialize
    let mut cursor = Cursor::new(bytes);

    let recovered_file = from_reader(&mut cursor).unwrap();

    assert_eq!(initial_file, recovered_file);
}

Modules

opaque_data

Serialization and deserialization functions for opaque data.

Structs

CompatDeserializationError

An Error-compatible wrapper for DeserializationError.

CompatSerializationError

An Error-compatible wrapper for SerializationError.

Deserializer

Deserializer for the XDR format.

Serializer

Serializer for the XDR format.

Enums

DeserializationError

Error during deserialization.

SerializationError

Error during serialization.

Functions

from_bytes

Deserializes data from a slice of bytes.

from_reader

Deserializes data from a generic reader.

to_bytes

Serialize data into a vector of bytes.

to_writer

Serialize data through a generic writer.