Rust XDR library

Build Status Crates.io Coverage Status

This crate provides a set of runtime routines to encode and decode basic XDR types, which can be used with xdrgen's automatically generated code, or with hand-written codecs.

This crate also implements XDR-RPC record marking in the form of the XdrRecordReader and XdrRecordWriter IO filters.

Usage

The easiest way to use this library is with xdrgen, which takes takes a specification in a .x file and generates all the necessary definitions for you.

However, you can manually implement the Pack and Unpack traits for your own types:

``` struct MyType { a: u32, b: Vec, }

impl Pack for MyType where W: Write { fn pack(&self, out: &mut W) -> xdr_codec::Result { let mut sz = 0;

    sz += try!(self.a.pack(out));
    sz += try!(Opaque::borrowed(self.b).pack(out));

    Ok(sz)
}

}

impl Unpack for MyType where R: Read { fn unpack(input: &mut In) -> Result<(Self, usize)> { let mut rsz = 0; let ret = MyType { a: { let (v, sz) = try!(Unpack::unpack(input)); rsz += sz; v }, b: { let (v, sz) = try!(Opaque::unpack(input)); rsz += sz; v.into_owned() }, };

    Ok((ret, rsz))
}

} ```

or alternatively, put the following in src/mytype.x:

struct MyType { unsigned int a; opaque b<>; }

then add a build.rs to your Cargo.toml:

``` extern crate xdrgen;

fn main() { xdrgen::compile("src/mytype.x").expect("xdrgen mytype.x failed"); } ```

then include the generated code in one of your modules: ``` extern crate xdr_codec;

// ...

include!(concat!(env!("OUTDIR"), "/mytypexdr.rs")); ```

Documentation

Complete documentation is here.

Changes in 0.2

Versions starting with 0.2 introduced a number of breaking changes:

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.