use crate::*;
macro_rules! ty_fn_endian {
($ty: ident, $endian: ident, $doc_endian: ident) => {
#[doc =
concat!(r"Reads a single [`", stringify!($ty), r"`] in [", stringify!($doc_endian), "-endian][Endianness::", stringify!($endian), "] byte order.
## Errors
If an error is returned, the chisel [breaks][crate#breaking].
")]
#[inline]
pub fn $ty(&mut self) -> InfallibleFormatResult<$ty, S> {
self.0.$ty(Endianness::$endian)
}
};
}
#[repr(transparent)]
pub struct ChiselLittleEndian<'a, S : ChiselSource>(pub(crate) &'a mut Chisel<S>);
impl<'a, S : ChiselSource> ChiselLittleEndian<'a, S> {
#[inline]
pub fn inner(&mut self) -> &mut Chisel<S> { self.0 }
#[inline]
pub fn into_inner(self) -> &'a mut Chisel<S> { self.0 }
#[inline]
pub fn error<E>(&self, err: E, backstep: usize) -> ChiselError<E, S::Error> { self.0.error(err, backstep) }
#[inline]
pub fn offset(&self) -> usize { self.0.offset() }
#[inline]
pub fn read_buf(&mut self, buf: &mut [u8]) -> InfallibleFormatResult<(), S> { self.0.read_buf(buf) }
#[inline]
pub fn u8(&mut self) -> InfallibleFormatResult<u8, S> { self.0.u8() }
ty_fn_endian!(u16, Little, little);
ty_fn_endian!(u32, Little, little);
ty_fn_endian!(u64, Little, little);
#[inline]
pub fn i8(&mut self) -> InfallibleFormatResult<i8, S> { self.0.i8() }
ty_fn_endian!(i16, Little, little);
ty_fn_endian!(i32, Little, little);
ty_fn_endian!(i64, Little, little);
ty_fn_endian!(f32, Little, little);
ty_fn_endian!(f64, Little, little);
#[inline]
pub fn skip(&mut self, how_many: usize) -> InfallibleFormatResult<(), S> { self.0.skip(how_many) }
#[cfg(feature = "alloc")]
#[inline]
pub fn read_until(&mut self, byte: u8, dest: &mut Vec<u8>) -> InfallibleFormatResult<(), S> { self.0.read_until(byte, dest) }
#[cfg(feature = "alloc")]
#[inline]
pub fn read_until_or_end(&mut self, byte: u8, dest: &mut Vec<u8>) -> InfallibleFormatResult<ReadUntilStopReason, S> { self.0.read_until_or_end(byte, dest) }
}
#[repr(transparent)]
pub struct ChiselBigEndian<'a, S : ChiselSource>(pub(crate) &'a mut Chisel<S>);
impl<'a, S : ChiselSource> ChiselBigEndian<'a, S> {
#[inline]
pub fn inner(&mut self) -> &mut Chisel<S> { self.0 }
#[inline]
pub fn into_inner(self) -> &'a mut Chisel<S> { self.0 }
#[inline]
pub fn error<E>(&self, err: E, backstep: usize) -> ChiselError<E, S::Error> { self.0.error(err, backstep) }
#[inline]
pub fn offset(&self) -> usize { self.0.offset() }
#[inline]
pub fn read_buf(&mut self, buf: &mut [u8]) -> InfallibleFormatResult<(), S> { self.0.read_buf(buf) }
#[inline]
pub fn u8(&mut self) -> InfallibleFormatResult<u8, S> { self.0.u8() }
ty_fn_endian!(u16, Big, big);
ty_fn_endian!(u32, Big, big);
ty_fn_endian!(u64, Big, big);
#[inline]
pub fn i8(&mut self) -> InfallibleFormatResult<i8, S> { self.0.i8() }
ty_fn_endian!(i16, Big, big);
ty_fn_endian!(i32, Big, big);
ty_fn_endian!(i64, Big, big);
ty_fn_endian!(f32, Big, big);
ty_fn_endian!(f64, Big, big);
#[inline]
pub fn skip(&mut self, how_many: usize) -> InfallibleFormatResult<(), S> { self.0.skip(how_many) }
#[cfg(feature = "alloc")]
#[inline]
pub fn read_until(&mut self, byte: u8, dest: &mut Vec<u8>) -> InfallibleFormatResult<(), S> { self.0.read_until(byte, dest) }
#[cfg(feature = "alloc")]
#[inline]
pub fn read_until_or_end(&mut self, byte: u8, dest: &mut Vec<u8>) -> InfallibleFormatResult<ReadUntilStopReason, S> { self.0.read_until_or_end(byte, dest) }
}