zero_formatter/
lib.rs

1//! Implementation of [ZeroFormatter](https://github.com/neuecc/ZeroFormatter) in Rust.
2//!
3//! ## Usage
4//!
5//! Put this in your `Cargo.toml`:
6//!
7//! ```toml
8//! [dependencies]
9//! zero-formatter = "0.1"
10//! ```
11//!
12//! ## Examples
13//!
14//! ```
15//! #[macro_use] extern crate zero_formatter;
16//! extern crate byteorder;
17//! use zero_formatter::*;
18//! use std::io::{Seek, SeekFrom, Read, Write, Cursor, Result};
19//! use byteorder::{ReadBytesExt, WriteBytesExt};
20//!
21//! declare_buffer! { Buffer }
22//!
23//! object_formatter! {
24//!     #[target(Buffer<Cursor<Vec<u8>>>)]
25//!     ObjectSample {
26//!         0; a: i32,
27//!         1; b: i64
28//!     }
29//! }
30//!
31//! # fn example() -> Result<()> {
32//! let mut writer = Buffer::new(Cursor::new(Vec::new()));
33//! try!(writer.serialize(0, ObjectSample { a: 1, b: 2 }));
34//! # Ok(())
35//! # }
36//! #
37//! # fn main() {
38//! # example();
39//! # }
40//! ```
41//!
42//! ## Supported Type
43//!
44//! Currently, this library support only [Stage1](https://github.com/neuecc/ZeroFormatter/tree/1.6.0#cross-platform).
45//! See also [WireFormat Specification](https://github.com/neuecc/ZeroFormatter/tree/1.6.0#wireformat-specification).
46//!
47//! ### Primitive Format
48//!
49//! | Rust | C# | Note |
50//! | ---- | ---- | --- |
51//! | `i16` | `Int16` | |
52//! | `i32` | `Int32`| |
53//! | `i64` | `Int64` | |
54//! | `u16` | `UInt16` | |
55//! | `u32` | `UInt32` | |
56//! | `u64` | `UInt64` | |
57//! | `f32` | `Single` | |
58//! | `f64` | `Double` | |
59//! | `bool` | `Boolean` | |
60//! | `u8` | `Byte` | |
61//! | `i8` | `SByte` | |
62//! | `time::Duration` | `TimeSpan` | |
63//! | `chrono::DateTime<chrono::UTC>` | `DateTime` | |
64//! | | `DateTimeOffset` | |
65//! | `Cow<'a, str>` | `String` | |
66//! | `Option<i16>` | `Int16?` | |
67//! | `Option<i32>` | `Int32?`| |
68//! | `Option<i64>` | `Int64?` | |
69//! | `Option<u16>` | `UInt16?` | |
70//! | `Option<u32>` | `UInt32?` | |
71//! | `Option<u64>` | `UInt64?` | |
72//! | `Option<f32>` | `Single?` | |
73//! | `Option<f64>` | `Double?` | |
74//! | `Option<bool>` | `Boolean?` | |
75//! | `Option<u8>` | `Byte?` | |
76//! | `Option<i8>` | `SByte?` | |
77//! | `Option<time::Duration>` | `TimeSpan?` | |
78//! | `Option<chrono::DateTime<chrono::UTC>>` | `DateTime?` | |
79//! | | `DateTimeOffset?` | |
80//!
81//! ### Sequence Format
82//!
83//! | Rust | C# | Note |
84//! | ---- | ---- | --- |
85//! | `Cow<'a, [T]>` | `Sequence<T>` | |
86//!
87//! ### List Format
88//!
89//! | Rust | C# | Note |
90//! | ---- | ---- | --- |
91//! | | FixedSizeList | |
92//! | | VariableSizeList | |
93//!
94//! ### Object Format
95//!
96//! | Rust | C# | Note |
97//! | ---- | ---- | --- |
98//! | struct | Object | use `object_formatter` macro |
99//! | `Option<struct>` | Object | if byteSize = -1, indicates `None` |
100//! | struct | Struct | |
101//! | `Option<struct>` | Struct? | |
102//!
103//! ### Union Format
104//!
105//! | Rust | C# | Note |
106//! | ---- | ---- | --- |
107//! | enum | Union | use `union_formatter` macro |
108//! | Option<enum> | | if byte_size = 1, indicates `None` |
109
110
111extern crate byteorder;
112extern crate chrono;
113
114mod error;
115mod formatter;
116#[macro_use]
117mod buffer;
118mod primitive;
119pub mod util;
120#[macro_use]
121mod has_value;
122#[macro_use]
123mod option;
124#[macro_use]
125mod object;
126mod time;
127mod sequence;
128mod union;
129
130pub use error::ZeroFormatterResult;
131pub use error::ZeroFormatterError;
132pub use formatter::Formatter;