use std::io::{
Result,
SeekFrom,
};
use qubit_io::{
Input,
Output,
Seekable,
};
use super::{
BinaryReader,
BinaryWriter,
BufferedBinaryReader,
BufferedBinaryWriter,
BufferedLeb128Reader,
BufferedLeb128Writer,
BufferedZigZagReader,
BufferedZigZagWriter,
Leb128Reader,
Leb128Writer,
ZigZagReader,
ZigZagWriter,
};
macro_rules! impl_input_methods {
($type:ident<$($param:ident),+> where $($bound:tt)*) => {
impl<$($param),+> $type<$($param),+>
where
$($bound)*
{
#[inline(always)]
pub fn is_buffered(&self) -> bool {
Input::is_buffered(self)
}
#[inline(always)]
pub unsafe fn read_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize> {
unsafe { Input::read_unchecked(self, output, index, count) }
}
#[inline(always)]
pub fn read(&mut self, output: &mut [u8]) -> Result<usize> {
Input::read(self, output)
}
#[inline(always)]
pub unsafe fn read_fully_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize> {
unsafe { Input::read_fully_unchecked(self, output, index, count) }
}
#[inline(always)]
pub fn read_fully(&mut self, output: &mut [u8]) -> Result<usize> {
Input::read_fully(self, output)
}
#[inline(always)]
pub fn read_exactly(&mut self, output: &mut [u8]) -> Result<()> {
Input::read_exactly(self, output)
}
}
};
}
macro_rules! impl_output_methods {
($type:ident<$($param:ident),+> where $($bound:tt)*) => {
impl<$($param),+> $type<$($param),+>
where
$($bound)*
{
#[inline(always)]
pub fn is_buffered(&self) -> bool {
Output::is_buffered(self)
}
#[inline(always)]
pub unsafe fn write_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<usize> {
unsafe { Output::write_unchecked(self, input, index, count) }
}
#[inline(always)]
pub fn write(&mut self, input: &[u8]) -> Result<usize> {
Output::write(self, input)
}
#[inline(always)]
pub unsafe fn write_fully_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<()> {
unsafe { Output::write_fully_unchecked(self, input, index, count) }
}
#[inline(always)]
pub fn write_fully(&mut self, input: &[u8]) -> Result<()> {
Output::write_fully(self, input)
}
#[inline(always)]
pub fn flush(&mut self) -> Result<()> {
Output::flush(self)
}
}
};
}
macro_rules! impl_seekable_methods {
($type:ident<$($param:ident),+> where $($bound:tt)*) => {
impl<$($param),+> $type<$($param),+>
where
$($bound)*
{
#[inline(always)]
pub fn seek_to(&mut self, position: SeekFrom) -> Result<u64> {
Seekable::seek_to(self, position)
}
}
};
}
impl_input_methods!(BinaryReader<R, O> where R: Input<Item = u8>);
impl_input_methods!(BufferedBinaryReader<R, O> where R: Input<Item = u8>);
impl_input_methods!(Leb128Reader<R, P> where R: Input<Item = u8>);
impl_input_methods!(BufferedLeb128Reader<R, P> where R: Input<Item = u8>);
impl_input_methods!(ZigZagReader<R, P> where R: Input<Item = u8>);
impl_input_methods!(BufferedZigZagReader<R, P> where R: Input<Item = u8>);
impl_output_methods!(BinaryWriter<W, O> where W: Output<Item = u8>);
impl_output_methods!(BufferedBinaryWriter<W, O> where W: Output<Item = u8>);
impl_output_methods!(Leb128Writer<W> where W: Output<Item = u8>);
impl_output_methods!(BufferedLeb128Writer<W> where W: Output<Item = u8>);
impl_output_methods!(ZigZagWriter<W> where W: Output<Item = u8>);
impl_output_methods!(BufferedZigZagWriter<W> where W: Output<Item = u8>);
impl_seekable_methods!(BinaryReader<R, O> where R: Seekable<Unit = u8>);
impl_seekable_methods!(BufferedBinaryReader<R, O> where R: Input<Item = u8> + Seekable<Unit = u8>);
impl_seekable_methods!(Leb128Reader<R, P> where R: Seekable<Unit = u8>);
impl_seekable_methods!(BufferedLeb128Reader<R, P> where R: Input<Item = u8> + Seekable<Unit = u8>);
impl_seekable_methods!(ZigZagReader<R, P> where R: Seekable<Unit = u8>);
impl_seekable_methods!(BufferedZigZagReader<R, P> where R: Input<Item = u8> + Seekable<Unit = u8>);
impl_seekable_methods!(BinaryWriter<W, O> where W: Seekable<Unit = u8>);
impl_seekable_methods!(BufferedBinaryWriter<W, O> where W: Output<Item = u8> + Seekable<Unit = u8>);
impl_seekable_methods!(Leb128Writer<W> where W: Seekable<Unit = u8>);
impl_seekable_methods!(BufferedLeb128Writer<W> where W: Output<Item = u8> + Seekable<Unit = u8>);
impl_seekable_methods!(ZigZagWriter<W> where W: Seekable<Unit = u8>);
impl_seekable_methods!(BufferedZigZagWriter<W> where W: Output<Item = u8> + Seekable<Unit = u8>);