Flat message buffers.
The crate provides basic flat types and a macro to create new flat types. Flat means that it occupies a single contiguous memory area.
Flat types have stable binary representation can be safely transferred between machines (of the same endianness) as is without packing/unpacking.
Message is represented as native Rust struct
or enum
.
()
).u8
, i8
, u16
, i16
, u32
, i32
, u64
, i64
, u128
, i128
).f32
, f64
).[T; N] where T: FlatSized
).FlatVec<T, L = u32>
).```rust
struct SizedStruct { a: u8, b: u16, c: u32, d: [u64; 4], } ```
For enum you may explicitly set the type of variant index (default value is u8
).
```rust
enum SizedEnum { A, B(u16, u8), C { a: u8, b: u16 }, D(u32), } ```
Unsized struct is DST. The reference to that structure contains its size.
```rust
struct UnsizedStruct {
a: u8,
b: u16,
c: flatty::FlatVec
```
Rust doesn't support DST enums yet so for now enum declaration is translated to unsized structure.
But it has as_ref
/as_mut
methods that returns a native enum that contains references to original enum fields.
```rust
enum UnsizedEnum {
A,
B(u8, u16),
C { a: u8, b: flatty::FlatVec
Licensed under either of
at your option.
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.