use core::convert::TryInto;
#[allow(clippy::len_without_is_empty)]
pub trait SerBacker {
fn new() -> Self;
fn len(&self) -> usize;
fn get_first_4byte_slice(&mut self) -> &mut [u8; 4];
fn extend_from_slice(&mut self, other: &[u8]);
fn push(&mut self, byte: u8);
fn reset(&mut self);
fn reserve(&mut self, additional: usize);
}
impl SerBacker for Vec<u8> {
fn new() -> Self {
vec![0, 0, 0, 0]
}
fn len(&self) -> usize {
self.len()
}
fn get_first_4byte_slice(&mut self) -> &mut [u8; 4] {
(&mut self[..4]).try_into().unwrap()
}
fn extend_from_slice(&mut self, other: &[u8]) {
self.extend_from_slice(other)
}
fn push(&mut self, byte: u8) {
self.push(byte)
}
fn reset(&mut self) {
self.resize(4, 0);
}
fn reserve(&mut self, additional: usize) {
self.reserve(additional);
}
}