Implementation of ZeroFormatter in Rust.
§Usage
Put this in your Cargo.toml
:
[dependencies]
zero-formatter = "0.1"
§Examples
#[macro_use] extern crate zero_formatter;
extern crate byteorder;
use zero_formatter::*;
use std::io::{Seek, SeekFrom, Read, Write, Cursor, Result};
use byteorder::{ReadBytesExt, WriteBytesExt};
declare_buffer! { Buffer }
object_formatter! {
#[target(Buffer<Cursor<Vec<u8>>>)]
ObjectSample {
0; a: i32,
1; b: i64
}
}
let mut writer = Buffer::new(Cursor::new(Vec::new()));
try!(writer.serialize(0, ObjectSample { a: 1, b: 2 }));
§Supported Type
Currently, this library support only Stage1.
See also WireFormat Specification.
Rust | C# | Note |
i16 | Int16 | |
i32 | Int32 | |
i64 | Int64 | |
u16 | UInt16 | |
u32 | UInt32 | |
u64 | UInt64 | |
f32 | Single | |
f64 | Double | |
bool | Boolean | |
u8 | Byte | |
i8 | SByte | |
time::Duration | TimeSpan | |
chrono::DateTime<chrono::UTC> | DateTime | |
| DateTimeOffset | |
Cow<'a, str> | String | |
Option<i16> | Int16? | |
Option<i32> | Int32? | |
Option<i64> | Int64? | |
Option<u16> | UInt16? | |
Option<u32> | UInt32? | |
Option<u64> | UInt64? | |
Option<f32> | Single? | |
Option<f64> | Double? | |
Option<bool> | Boolean? | |
Option<u8> | Byte? | |
Option<i8> | SByte? | |
Option<time::Duration> | TimeSpan? | |
Option<chrono::DateTime<chrono::UTC>> | DateTime? | |
| DateTimeOffset? | |
Rust | C# | Note |
Cow<'a, [T]> | Sequence<T> | |
Rust | C# | Note |
| FixedSizeList | |
| VariableSizeList | |
Rust | C# | Note |
struct | Object | use object_formatter macro |
Option<struct> | Object | if byteSize = -1, indicates None |
struct | Struct | |
Option<struct> | Struct? | |
Rust | C# | Note |
enum | Union | use union_formatter macro |
Option | | if byte_size = 1, indicates None |