[−][src]Crate bytebuff
This crate is purely for marshalling and unmarshalling a data to send over a network, main deal is ByteBuff witch is used for serilizing and deserilizing. There is also Marshal trait that can be derivated on structs. in case you vant to experience internal hell you can chenkout proc-macro implementation of Marshall (could not find other way, but it works).
example
extern crate bytebuff; use bytebuff::marshall_derive::Marshall; use bytebuff::Marshall; use bytebuff::ByteBuff; #[derive(Marshall)] struct Point { x: f32, y: f32, } #[derive(Marshall)] struct Dummy { #[marshall(nested)] position: Point, name: String, #[marshall(ignore)] useless_stuff: i128, } fn main() { let mut buff = ByteBuff::new(); let dummy = Dummy { useless_stuff: 10, position: Point { x: 10.0, y: 70.0 }, name: String::from("Mlokogrgel"), }; //dummy can write it self to ByteBuff dummy.marshall(&mut buff); //now imagine we sent buffer with dummy over the network let mut buff = ByteBuff::from_bytes(buff.data()); //and dummy can also read its self from buffer let de_dummy = Dummy::unmarshall(&mut buff).unwrap(); //ignored data don't ewen get written to buffer in first place and is replaced //by default, in any case you can always implement Default trait to your types assert_eq!(de_dummy.useless_stuff, Default::default()); //you can nest how match you want as long as you annotate so assert_eq!(10.0, de_dummy.position.x); assert_eq!(70.0, de_dummy.position.y); // other then all numbers, strings, booleans and bite vectors are supported assert_eq!(String::from("Mlokogrgel"), de_dummy.name); }
Re-exports
pub use marshall_derive; |
Structs
ByteBuff | ByteBuff is a convenient helper for game networking. Using this is similar to using ThreadRng from rand package. Example speaks for it self. |
ReadError | ReadError informs about the read overflow, this happens when you for example try to read usize from buffer where is only one bool. In this case you would get ReadError { size: 1, overflow: 8 } |
Traits
HelloMacro | |
Interface | |
Marshall |