Binry encoding and decoding of XDR (RFC4506) data.
| XDR IDL | Rust |
|---|---|
int |
i32 |
unsigned int |
u32 |
enum |
Unit enum |
bool |
bool |
hyper |
i64 |
unsigned hyper |
u64 |
float |
f32 |
double |
f64 |
quadruple |
Not currently supported |
opaque [n] |
[u8; N] |
opaque<> |
Vec<u8> or &[u8] |
string<> |
String |
Fixed length array [n] |
[T; N] |
Variable length array <> |
Vec<T> or &[T] |
struct |
struct |
union |
enum |
void |
Unit struct or unit variant |
* (optional-data) |
Option |
The example from chapter 7 of RFC4506 can be represented in Rust like so:
#[derive(Debug, Facet)]
#[repr(u32)]
enum FileType {
Text,
Data { creator: String },
Exec { interpretor: String },
}
#[derive(Debug, Facet, PartialEq)]
struct File {
filename: String,
filetype: FileType,
owner: String,
data: Vec<u8>,
}