use crate::errors::PcapError;
use byteorder::{ByteOrder, ReadBytesExt};
use std::borrow::Cow;
use derive_into_owned::IntoOwned;
#[derive(Clone, Debug, IntoOwned)]
pub struct SimplePacketBlock<'a> {
pub original_len: u32,
pub data: Cow<'a, [u8]>
}
impl<'a> SimplePacketBlock<'a> {
pub fn from_slice<B: ByteOrder>(mut slice: &'a [u8]) -> Result<(&'a [u8], Self), PcapError> {
if slice.len() < 4 {
return Err(PcapError::InvalidField("SimplePacketBlock: block length < 4"));
}
let original_len = slice.read_u32::<B>()?;
let packet = SimplePacketBlock {
original_len,
data: Cow::Borrowed(slice)
};
Ok((&[], packet))
}
}