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

Obtains a new reader or writer that assumes data in little endian.

Retrieves the runtime byte order assumed by this wrapper.

Obtains a new reader or writer that assumes data in big endian.

Retrieves the runtime byte order assumed by this wrapper.

Obtains a new reader or writer that assumes data in the system’s native endianness. While this method might sounds a bit pointless, it enables easier byte order changes through method chaining).

Obtains a new reader or writer that assumes network order.

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.

Retrieves the runtime byte order assumed by this wrapper.

Creates a new reader or writer that assumes data in the given byte order. This flexible constructor admits any kind of byte order (static and dynamic). Note that the other constructors are easier to use (e.g. le, be, [native'], or [runtime`]).

Recovers the inner reader or writer from this wrapper. Information about the assumed byte order is discarded.

Changes the assumed byte order of the reader or writer.

Changes the assumed byte order of the reader or writer to little endian.

Changes the assumed byte order of the reader or writer to little endian.

Converts the assumed endianness to the opposite of the current order.

Checks whether the assumed endianness is the system’s native byte order.

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());

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());

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());

Reads an unsigned 16 bit integer from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

Reads a signed 32 bit integer from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

Reads an unsigned 32 bit integer from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

Reads a signed 64 bit integer from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

Reads an unsigned 16 bit integer from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader.

Errors

This method returns the same errors as Read::read_exact.

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.

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.

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");

Writes an unsigned 16 bit integer to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Writes a signed 32 bit integer to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Writes an unsigned 32 bit integer to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Writes a signed 64 bit integer to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Writes an unsigned 64 bit integer to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer.

Errors

This method returns the same errors as Write::write_all.

Trait Implementations

Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to read. Read more
Read all bytes into buf until the delimiter byte or EOF is reached. Read more
Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. You do not need to clear the buffer before appending. Read more
🔬This is a nightly-only experimental API. (buf_read_has_data_left)
Check if the underlying Read has any data left to be read. Read more
Returns an iterator over the contents of this reader split on the byte byte. Read more
Returns an iterator over the lines of this reader. Read more
Formats the value using the given formatter. Read more
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Read all bytes until EOF in this source, placing them into buf. Read more
Read all bytes until EOF in this source, appending them to buf. Read more
Read the exact number of bytes required to fill buf. Read more
Like read, except that it reads into a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
Creates a “by reference” adaptor for this instance of Read. Read more
Transforms this Read instance to an Iterator over its bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Seek to an offset, in bytes, in a stream. Read more
Rewind to the beginning of a stream. Read more
🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
Returns the current seek position from the start of the stream. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Attempts to write an entire buffer into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Reads an unsigned 8 bit integer from the underlying reader. Read more
Reads a signed 8 bit integer from the underlying reader. Read more
Reads an unsigned 16 bit integer from the underlying reader. Read more
Reads a signed 16 bit integer from the underlying reader. Read more
Reads an unsigned 24 bit integer from the underlying reader. Read more
Reads a signed 24 bit integer from the underlying reader. Read more
Reads an unsigned 32 bit integer from the underlying reader. Read more
Reads a signed 32 bit integer from the underlying reader. Read more
Reads an unsigned 48 bit integer from the underlying reader. Read more
Reads a signed 48 bit integer from the underlying reader. Read more
Reads an unsigned 64 bit integer from the underlying reader. Read more
Reads a signed 64 bit integer from the underlying reader. Read more
Reads an unsigned 128 bit integer from the underlying reader. Read more
Reads a signed 128 bit integer from the underlying reader. Read more
Reads an unsigned n-bytes integer from the underlying reader. Read more
Reads a signed n-bytes integer from the underlying reader. Read more
Reads an unsigned n-bytes integer from the underlying reader.
Reads a signed n-bytes integer from the underlying reader.
Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader. Read more
Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader. Read more
Reads a sequence of unsigned 16 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 32 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 64 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 128 bit integers from the underlying reader. Read more
Reads a sequence of signed 8 bit integers from the underlying reader. Read more
Reads a sequence of signed 16 bit integers from the underlying reader. Read more
Reads a sequence of signed 32 bit integers from the underlying reader. Read more
Reads a sequence of signed 64 bit integers from the underlying reader. Read more
Reads a sequence of signed 128 bit integers from the underlying reader. Read more
Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader. Read more
👎Deprecated since 1.2.0: please use read_f32_into instead
DEPRECATED. Read more
Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more
👎Deprecated since 1.2.0: please use read_f64_into instead
DEPRECATED. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Writes an unsigned 8 bit integer to the underlying writer. Read more
Writes a signed 8 bit integer to the underlying writer. Read more
Writes an unsigned 16 bit integer to the underlying writer. Read more
Writes a signed 16 bit integer to the underlying writer. Read more
Writes an unsigned 24 bit integer to the underlying writer. Read more
Writes a signed 24 bit integer to the underlying writer. Read more
Writes an unsigned 32 bit integer to the underlying writer. Read more
Writes a signed 32 bit integer to the underlying writer. Read more
Writes an unsigned 48 bit integer to the underlying writer. Read more
Writes a signed 48 bit integer to the underlying writer. Read more
Writes an unsigned 64 bit integer to the underlying writer. Read more
Writes a signed 64 bit integer to the underlying writer. Read more
Writes an unsigned 128 bit integer to the underlying writer.
Writes a signed 128 bit integer to the underlying writer.
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more