use std::io::{self,Read,Write,Seek,SeekFrom,Take};
use crate::Error;
pub trait Decode: Sized {
fn decode<Source>(input: &mut Source) -> Result<Self, Error> where
Source: Read + Seek;
}
pub trait Encode {
fn encode<Sink>(&self, output: &mut Sink) -> Result<(), Error> where
Sink: Write + Seek;
}
pub trait Entry: Sized {
fn len(&self) -> u64;
fn pos(&self) -> u64;
fn reader<'a, Source: Read + Seek>(&mut self, source: &'a mut Source) -> Result<Take<&'a mut Source>, io::Error> {
source.seek(SeekFrom::Start(self.pos()))?;
Ok(source.take(self.len()))
}
}