1 use super::{PatternSplitter, StreamSplitter}; 2 use std::io; 3 4 static FRAME_HEADER: [u8; 8] = [0x4f, 0x4f, 0x4f, 0x4f, 0xff, 0xff, 0xff, 0xff]; 5 6 /// Iterator that returns exactly one frame worth of data from a FWHT stream. 7 pub struct FwhtFrameParser<S: io::Read>(PatternSplitter<S>); 8 9 /// Given a reader, return individual compressed FWHT frames. 10 impl<S: io::Read> FwhtFrameParser<S> { new(stream: S) -> Option<Self>11 pub fn new(stream: S) -> Option<Self> { 12 Some(Self(PatternSplitter::new(FRAME_HEADER.to_vec(), stream)?)) 13 } 14 } 15 16 impl<S: io::Read> Iterator for FwhtFrameParser<S> { 17 type Item = Vec<u8>; 18 19 /// Returns the next frame in the stream, header included. next(&mut self) -> Option<Self::Item>20 fn next(&mut self) -> Option<Self::Item> { 21 self.0.next() 22 } 23 } 24 25 impl<S: io::Read> StreamSplitter for FwhtFrameParser<S> {} 26