Read everything as byte slices

Zero-copy baby.
This commit is contained in:
Bradlee Speice 2019-04-22 17:57:00 -04:00
parent d8f783e85d
commit 9723f0b12d

View File

@ -58,7 +58,7 @@ pub trait KStream {
fn align_to_byte(&mut self) -> io::Result<()>; fn align_to_byte(&mut self) -> io::Result<()>;
fn read_bits_int(&mut self, n: u32) -> io::Result<u64>; fn read_bits_int(&mut self, n: u32) -> io::Result<u64>;
fn read_bytes(&mut self, dst: &mut [u8], len: usize) -> io::Result<&[u8]>; fn read_bytes(&mut self, len: usize) -> io::Result<&[u8]>;
fn read_bytes_full(&mut self) -> io::Result<&[u8]>; fn read_bytes_full(&mut self) -> io::Result<&[u8]>;
fn read_bytes_term( fn read_bytes_term(
&mut self, &mut self,
@ -70,8 +70,8 @@ pub trait KStream {
/// Verify a magic sequence occurs in the file. Because the size is known at compile-time /// Verify a magic sequence occurs in the file. Because the size is known at compile-time
/// (and is generally very small), we ask that our caller pass in a buffer for us. /// (and is generally very small), we ask that our caller pass in a buffer for us.
fn ensure_fixed_contents(&mut self, expected: &[u8], buf: &mut [u8]) -> KResult<&[u8]> { fn ensure_fixed_contents(&mut self, expected: &[u8]) -> KResult<&[u8]> {
let actual = self.read_bytes(buf, expected.len())?; let actual = self.read_bytes(expected.len())?;
if actual == expected { if actual == expected {
Ok(actual) Ok(actual)
} else { } else {
@ -229,7 +229,7 @@ impl<'a> KStream for BytesReader<'a> {
unimplemented!() unimplemented!()
} }
fn read_bytes(&mut self, buf: &mut [u8], len: usize) -> io::Result<&[u8]> { fn read_bytes(&mut self, len: usize) -> io::Result<&[u8]> {
unimplemented!() unimplemented!()
} }