pub mod leb128;
pub mod primitives;
pub mod std;
#[macro_export]
macro_rules! unwrap_return {
($data:expr) => {
match $data {
Some(value) => value,
None => return None,
}
};
}
pub trait Serializable {
fn serialize(&self) -> Vec<u8>;
fn parse(data: &mut Vec<u8>) -> Option<Self>
where
Self: Sized;
}
fn get_vec<T: Serializable>(item_count: usize, data: &mut Vec<u8>) -> Option<Vec<T>> {
let mut result = vec![];
for _ in 0..item_count {
result.push(unwrap_return!(T::parse(data)));
}
Some(result)
}
fn bin_slice<T: Serializable>(items: &[T]) -> Vec<u8> {
let mut stuffs = vec![];
for item in items {
stuffs.push(item.serialize());
}
stuffs.concat()
}
mod test_leb128;
mod test_primitives;
mod test_std;