Expand description
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§
- Compat
Deserialization Error - An
Error
-compatible wrapper forDeserializationError
. - Compat
Serialization Error - An
Error
-compatible wrapper forSerializationError
. - Deserializer
- Deserializer for the XDR format.
- Serializer
- Serializer for the XDR format.
Enums§
- Deserialization
Error - Error during deserialization.
- Serialization
Error - 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.