Struct byteordered::ByteOrdered
source · pub struct ByteOrdered<T, E> { /* private fields */ }
Expand description
Wrapper type for a reader or writer with an assumed byte order.
More details can be found at the crate level documentation.
Implementations
sourceimpl<T> ByteOrdered<T, StaticEndianness<LittleEndian>>
impl<T> ByteOrdered<T, StaticEndianness<LittleEndian>>
sourcepub fn endianness(&self) -> Endianness
pub fn endianness(&self) -> Endianness
Retrieves the runtime byte order assumed by this wrapper.
sourceimpl<T> ByteOrdered<T, StaticEndianness<BigEndian>>
impl<T> ByteOrdered<T, StaticEndianness<BigEndian>>
sourcepub fn endianness(&self) -> Endianness
pub fn endianness(&self) -> Endianness
Retrieves the runtime byte order assumed by this wrapper.
sourceimpl<T> ByteOrdered<T, StaticEndianness<NativeEndian>>
impl<T> ByteOrdered<T, StaticEndianness<NativeEndian>>
sourceimpl<T> ByteOrdered<T, StaticEndianness<NetworkEndian>>
impl<T> ByteOrdered<T, StaticEndianness<NetworkEndian>>
sourceimpl<T> ByteOrdered<T, Endianness>
impl<T> ByteOrdered<T, Endianness>
sourcepub fn runtime(inner: T, endianness: Endianness) -> Self
pub fn runtime(inner: T, endianness: Endianness) -> Self
Creates a new reader or writer that assumes data in the given byte order known at run-time.
Although it is equivalent to ByteOrdered::new
, this function
leaves a code signal that subsequent calls depend on conditions
resolved at run-time. If you know the data’s endianness in advance, the
other constructors are preferred (e.g. new
, le
or be
), so
as to avoid the overhead of dynamic dispatching.
sourcepub fn endianness(&self) -> Endianness
pub fn endianness(&self) -> Endianness
Retrieves the runtime byte order assumed by this wrapper.
sourceimpl<T, E> ByteOrdered<T, E>where
E: Endian,
impl<T, E> ByteOrdered<T, E>where
E: Endian,
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Recovers the inner reader or writer from this wrapper. Information about the assumed byte order is discarded.
sourcepub fn into_endianness<E2: Endian>(self, endianness: E2) -> ByteOrdered<T, E2> ⓘ
pub fn into_endianness<E2: Endian>(self, endianness: E2) -> ByteOrdered<T, E2> ⓘ
Changes the assumed byte order of the reader or writer.
sourcepub fn into_le(self) -> ByteOrdered<T, StaticEndianness<LittleEndian>> ⓘ
pub fn into_le(self) -> ByteOrdered<T, StaticEndianness<LittleEndian>> ⓘ
Changes the assumed byte order of the reader or writer to little endian.
sourcepub fn into_be(self) -> ByteOrdered<T, StaticEndianness<BigEndian>> ⓘ
pub fn into_be(self) -> ByteOrdered<T, StaticEndianness<BigEndian>> ⓘ
Changes the assumed byte order of the reader or writer to little endian.
sourcepub fn into_opposite(self) -> ByteOrdered<T, E::Opposite> ⓘwhere
E: Endian,
pub fn into_opposite(self) -> ByteOrdered<T, E::Opposite> ⓘwhere
E: Endian,
Converts the assumed endianness to the opposite of the current order.
sourceimpl<R, E> ByteOrdered<R, E>where
R: ReadBytesExt,
E: Endian,
impl<R, E> ByteOrdered<R, E>where
R: ReadBytesExt,
E: Endian,
sourcepub fn read_i8(&mut self) -> IoResult<i8>
pub fn read_i8(&mut self) -> IoResult<i8>
Reads a signed 8 bit integer from the underlying reader.
This method does exactly the same thing as read_i8
in
byteorder::ReadBytesExt
. It is included so that users do not have to
import the former trait.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 8 bit integers from a Read
:
use std::io::Cursor;
use byteordered::ByteOrdered;
let mut rdr = ByteOrdered::native(Cursor::new(vec![2, 5]));
assert_eq!(2, rdr.read_i8().unwrap());
assert_eq!(5, rdr.read_i8().unwrap());
sourcepub fn read_u8(&mut self) -> IoResult<u8>
pub fn read_u8(&mut self) -> IoResult<u8>
Reads an unsigned 8 bit integer from the underlying reader.
This method does exactly the same thing as read_u8
in
byteorder::ReadBytesExt
. It is included so that users do not have to
import the former trait.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 8 bit integers from a Read
:
use std::io::Cursor;
use byteordered::ByteOrdered;
let mut rdr = ByteOrdered::native(Cursor::new(vec![2, 5]));
assert_eq!(2, rdr.read_u8().unwrap());
assert_eq!(5, rdr.read_u8().unwrap());
sourcepub fn read_i16(&mut self) -> IoResult<i16>
pub fn read_i16(&mut self) -> IoResult<i16>
Reads a signed 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read signed 16 bit big-endian integers from a Read
:
use std::io::Cursor;
use byteordered::ByteOrdered;
let mut rdr = ByteOrdered::be(Cursor::new(vec![0x00, 0xc1, 0xff, 0x7c]));
assert_eq!(193, rdr.read_i16().unwrap());
assert_eq!(-132, rdr.read_i16().unwrap());
sourcepub fn read_u16(&mut self) -> IoResult<u16>
pub fn read_u16(&mut self) -> IoResult<u16>
Reads an unsigned 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
sourcepub fn read_i32(&mut self) -> IoResult<i32>
pub fn read_i32(&mut self) -> IoResult<i32>
Reads a signed 32 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
sourcepub fn read_u32(&mut self) -> IoResult<u32>
pub fn read_u32(&mut self) -> IoResult<u32>
Reads an unsigned 32 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
sourcepub fn read_i64(&mut self) -> IoResult<i64>
pub fn read_i64(&mut self) -> IoResult<i64>
Reads a signed 64 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
sourcepub fn read_u64(&mut self) -> IoResult<u64>
pub fn read_u64(&mut self) -> IoResult<u64>
Reads an unsigned 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
sourceimpl<W, E> ByteOrdered<W, E>where
W: WriteBytesExt,
E: Endian,
impl<W, E> ByteOrdered<W, E>where
W: WriteBytesExt,
E: Endian,
sourcepub fn write_i8(&mut self, x: i8) -> IoResult<()>
pub fn write_i8(&mut self, x: i8) -> IoResult<()>
Writes a signed 8 bit integer to the underlying writer.
Note that since this writes a single byte, no byte order conversions are used. It is included for completeness.
Errors
This method returns the same errors as Write::write_all
.
sourcepub fn write_u8(&mut self, x: u8) -> IoResult<()>
pub fn write_u8(&mut self, x: u8) -> IoResult<()>
Writes an unsigned 8 bit integer to the underlying writer.
Note that since this writes a single byte, no byte order conversions are used. It is included for completeness.
Errors
This method returns the same errors as Write::write_all
.
sourcepub fn write_i16(&mut self, x: i16) -> IoResult<()>
pub fn write_i16(&mut self, x: i16) -> IoResult<()>
Writes a signed 16 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Examples
Write signed 16 bit big-endian integers to a Write
:
use byteordered::ByteOrdered;
let mut wtr = ByteOrdered::be(Vec::new());
wtr.write_i16(193).unwrap();
wtr.write_i16(-132).unwrap();
assert_eq!(wtr.into_inner(), b"\x00\xc1\xff\x7c");
sourcepub fn write_u16(&mut self, x: u16) -> IoResult<()>
pub fn write_u16(&mut self, x: u16) -> IoResult<()>
Writes an unsigned 16 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
sourcepub fn write_i32(&mut self, x: i32) -> IoResult<()>
pub fn write_i32(&mut self, x: i32) -> IoResult<()>
Writes a signed 32 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
sourcepub fn write_u32(&mut self, x: u32) -> IoResult<()>
pub fn write_u32(&mut self, x: u32) -> IoResult<()>
Writes an unsigned 32 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
sourcepub fn write_i64(&mut self, x: i64) -> IoResult<()>
pub fn write_i64(&mut self, x: i64) -> IoResult<()>
Writes a signed 64 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
sourcepub fn write_u64(&mut self, x: u64) -> IoResult<()>
pub fn write_u64(&mut self, x: u64) -> IoResult<()>
Writes an unsigned 64 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Trait Implementations
sourceimpl<T, E> BufRead for ByteOrdered<T, E>where
T: BufRead,
impl<T, E> BufRead for ByteOrdered<T, E>where
T: BufRead,
sourcefn fill_buf(&mut self) -> IoResult<&[u8]>
fn fill_buf(&mut self) -> IoResult<&[u8]>
sourcefn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moresourcefn read_line(&mut self, buf: &mut String) -> IoResult<usize>
fn read_line(&mut self, buf: &mut String) -> IoResult<usize>
0xA
byte) is reached, and append
them to the provided buffer. You do not need to clear the buffer before
appending. Read moresourcefn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Read
has any data left to be read. Read moresourceimpl<T: Debug, E: Debug> Debug for ByteOrdered<T, E>
impl<T: Debug, E: Debug> Debug for ByteOrdered<T, E>
sourceimpl<R, E> Read for ByteOrdered<R, E>where
R: Read,
impl<R, E> Read for ByteOrdered<R, E>where
R: Read,
sourcefn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
sourcefn read_to_end(&mut self, buf: &mut Vec<u8>) -> IoResult<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> IoResult<usize>
buf
. Read moresourcefn read_to_string(&mut self, buf: &mut String) -> IoResult<usize>
fn read_to_string(&mut self, buf: &mut String) -> IoResult<usize>
buf
. Read moresourcefn read_exact(&mut self, buf: &mut [u8]) -> IoResult<()>
fn read_exact(&mut self, buf: &mut [u8]) -> IoResult<()>
buf
. Read more1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)sourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresourceimpl<T, E> Seek for ByteOrdered<T, E>where
T: Seek,
impl<T, E> Seek for ByteOrdered<T, E>where
T: Seek,
sourcefn seek(&mut self, pos: SeekFrom) -> IoResult<u64>
fn seek(&mut self, pos: SeekFrom) -> IoResult<u64>
1.55.0 · sourcefn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
sourceimpl<W, E> Write for ByteOrdered<W, E>where
W: Write,
impl<W, E> Write for ByteOrdered<W, E>where
W: Write,
sourcefn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
sourcefn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
sourcefn write_all(&mut self, buf: &[u8]) -> IoResult<()>
fn write_all(&mut self, buf: &[u8]) -> IoResult<()>
sourcefn write_fmt(&mut self, fmt: Arguments<'_>) -> IoResult<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> IoResult<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Auto Trait Implementations
impl<T, E> RefUnwindSafe for ByteOrdered<T, E>where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> Send for ByteOrdered<T, E>where
E: Send,
T: Send,
impl<T, E> Sync for ByteOrdered<T, E>where
E: Sync,
T: Sync,
impl<T, E> Unpin for ByteOrdered<T, E>where
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for ByteOrdered<T, E>where
E: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<R> ReadBytesExt for Rwhere
R: Read + ?Sized,
impl<R> ReadBytesExt for Rwhere
R: Read + ?Sized,
sourcefn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
sourcefn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
sourcefn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
sourcefn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
sourcefn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
sourcefn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
sourcefn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
sourcefn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
sourcefn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
sourcefn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
sourcefn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
sourcefn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
sourcefn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
sourcefn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
sourcefn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
sourcefn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
sourcefn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
sourcefn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
sourcefn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
sourcefn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
sourcefn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
sourcefn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
sourcefn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
read_f32_into
instead