Buffalo

Buffalo is a binary serialization format that gives you ultimate control.

Example

```rust

[derive(buffalo::Read, buffalo::Write)]

[buffalo(size = "dynamic")]

struct AddressBook { #[buffalo(id = 0, required)] pub contacts: Vec, }

[derive(buffalo::Read, buffalo::Write)]

[buffalo(size = "dynamic")]

struct Contact { #[buffalo(id = 0, required)] pub age: u16, #[buffalo(id = 1, required)] pub name: String, #[buffalo(id = 2, required)] pub phone_numbers: Option>, }

[derive(buffalo::Read, buffalo::Write)]

[buffalo(size = "static", value_size = 8)]

enum PhoneNumber { #[allow(unused)] #[buffalo(id = 0)] Home(String), #[allow(unused)] #[buffalo(id = 1)] Mobile(String), }

fn addressbookexample() { let mut writer = buffalo::Writer::new(); let name = writer.write("John Doe"); let home = writer.write("1231231234"); let mobile = writer.write("4564564567"); let phonenumbers = writer.write(&vec![ PhoneNumberWriter::Home(home), PhoneNumberWriter::Mobile(mobile), ]); let contact = writer.write(&ContactWriter { age: 28, name, phonenumbers: Some(phonenumbers), }); let contacts = writer.write(&vec![contact]); let addressbook = writer.write(&AddressBookWriter { contacts }); writer.write(&addressbook); let bytes = writer.intobytes(); let addressbook = buffalo::read::(&bytes); let contact = addressbook.contacts().get(0).unwrap(); asserteq!(contact.name(), "John Doe"); asserteq!(contact.age(), 28); let phonenumbers = contact.phonenumbers(); let home = phonenumbers.unwrap().get(0).unwrap(); asserteq!(home.ashome().unwrap(), "1231231234"); let mobile = phonenumbers.unwrap().get(1).unwrap(); asserteq!(mobile.asmobile().unwrap(), "4564564567"); } ```