use std::convert::TryInto;
pub fn encode(opcode: u32, data_length: u32) -> Vec<u8> {
[opcode.to_le_bytes(), data_length.to_le_bytes()].concat()
}
pub fn decode(data: &[u8]) -> Option<(u32, u32)> {
if data.len() < 8 {
return None;
}
let opcode = data[..4].try_into().map(u32::from_le_bytes).ok()?;
let length = data[4..8].try_into().map(u32::from_le_bytes).ok()?;
Some((opcode, length))
}