wlan_common/ie/wsc/
reader.rsuse super::{AttributeHeader, Id};
use crate::buffer_reader::BufferReader;
use std::mem::size_of;
use zerocopy::SplitByteSlice;
pub struct Reader<B>(BufferReader<B>);
impl<B: SplitByteSlice> Reader<B> {
pub fn new(bytes: B) -> Self {
Reader(BufferReader::new(bytes))
}
}
impl<B: SplitByteSlice> Iterator for Reader<B> {
type Item = (Id, B);
fn next(&mut self) -> Option<Self::Item> {
let header = self.0.peek::<AttributeHeader>()?;
let body_len = header.body_len.to_native() as usize;
if self.0.bytes_remaining() < size_of::<AttributeHeader>() + body_len {
None
} else {
let header = self.0.read::<AttributeHeader>().unwrap();
let body = self.0.read_bytes(body_len).unwrap();
Some((header.id, body))
}
}
}