adapter: Implement the Read trait

This commit is contained in:
Thibault Saunier 2017-11-04 08:57:52 -03:00 committed by Sebastian Dröge
parent bf360ebce8
commit 9158c2c8e1

View file

@ -8,6 +8,7 @@
use std::collections::VecDeque;
use std::cmp;
use std::io;
use gst;
use gst::prelude::*;
@ -255,6 +256,27 @@ impl Adapter {
}
}
impl io::Read for Adapter {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
let mut len = self.get_available();
if buf.len() < len {
len = buf.len();
}
if self.size == 0 {
return Err(io::Error::new(
io::ErrorKind::WouldBlock,
format!("Missing data: requesting {} but only got {}.",
len, self.size)));
}
Self::copy_data(&self.deque, self.skip, buf, len);
self.flush(len);
Ok(len)
}
}
#[cfg(test)]
mod tests {
use super::*;