[−]Trait gst_plugin::bytes::ReadBytesExt
Extends Read
with methods for reading numbers. (For std::io
.)
Most of the methods defined here have an unconstrained type parameter that
must be explicitly instantiated. Typically, it is instantiated with either
the BigEndian
or LittleEndian
types defined in this crate.
Examples
Read unsigned 16 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![2, 5, 3, 0]); assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap()); assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());
Provided Methods
fn read_u8(&mut self) -> Result<u8, Error>
Reads an unsigned 8 bit integer from the underlying reader.
Note that since this reads a single byte, no byte order conversions are used. It is included for completeness.
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 byteorder::ReadBytesExt; let mut rdr = Cursor::new(vec![2, 5]); assert_eq!(2, rdr.read_u8().unwrap()); assert_eq!(5, rdr.read_u8().unwrap());
fn read_i8(&mut self) -> Result<i8, Error>
Reads a signed 8 bit integer from the underlying reader.
Note that since this reads a single byte, no byte order conversions are used. It is included for completeness.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read signed 8 bit integers from a Read
:
use std::io::Cursor; use byteorder::ReadBytesExt; let mut rdr = Cursor::new(vec![0x02, 0xfb]); assert_eq!(2, rdr.read_i8().unwrap()); assert_eq!(-5, rdr.read_i8().unwrap());
fn read_u16<T>(&mut self) -> Result<u16, Error> where
T: ByteOrder,
T: ByteOrder,
Reads an unsigned 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 16 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![2, 5, 3, 0]); assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap()); assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());
fn read_i16<T>(&mut self) -> Result<i16, Error> where
T: ByteOrder,
T: ByteOrder,
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 byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x00, 0xc1, 0xff, 0x7c]); assert_eq!(193, rdr.read_i16::<BigEndian>().unwrap()); assert_eq!(-132, rdr.read_i16::<BigEndian>().unwrap());
fn read_u24<T>(&mut self) -> Result<u32, Error> where
T: ByteOrder,
T: ByteOrder,
Reads an unsigned 24 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 24 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x00, 0x01, 0x0b]); assert_eq!(267, rdr.read_u24::<BigEndian>().unwrap());
fn read_i24<T>(&mut self) -> Result<i32, Error> where
T: ByteOrder,
T: ByteOrder,
Reads a signed 24 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read signed 24 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0xff, 0x7a, 0x33]); assert_eq!(-34253, rdr.read_i24::<BigEndian>().unwrap());
fn read_u32<T>(&mut self) -> Result<u32, Error> where
T: ByteOrder,
T: ByteOrder,
Reads an unsigned 32 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 32 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x00, 0x00, 0x01, 0x0b]); assert_eq!(267, rdr.read_u32::<BigEndian>().unwrap());
fn read_i32<T>(&mut self) -> Result<i32, Error> where
T: ByteOrder,
T: ByteOrder,
Reads a signed 32 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read signed 32 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0xff, 0xff, 0x7a, 0x33]); assert_eq!(-34253, rdr.read_i32::<BigEndian>().unwrap());
fn read_u48<T>(&mut self) -> Result<u64, Error> where
T: ByteOrder,
T: ByteOrder,
Reads an unsigned 48 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 48 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0xb6, 0x71, 0x6b, 0xdc, 0x2b, 0x31]); assert_eq!(200598257150769, rdr.read_u48::<BigEndian>().unwrap());
fn read_i48<T>(&mut self) -> Result<i64, Error> where
T: ByteOrder,
T: ByteOrder,
Reads a signed 48 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read signed 48 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x9d, 0x71, 0xab, 0xe7, 0x97, 0x8f]); assert_eq!(-108363435763825, rdr.read_i48::<BigEndian>().unwrap());
fn read_u64<T>(&mut self) -> Result<u64, Error> where
T: ByteOrder,
T: ByteOrder,
Reads an unsigned 64 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read an unsigned 64 bit big-endian integer from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x00, 0x03, 0x43, 0x95, 0x4d, 0x60, 0x86, 0x83]); assert_eq!(918733457491587, rdr.read_u64::<BigEndian>().unwrap());
fn read_i64<T>(&mut self) -> Result<i64, Error> where
T: ByteOrder,
T: ByteOrder,
Reads a signed 64 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a signed 64 bit big-endian integer from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x80, 0, 0, 0, 0, 0, 0, 0]); assert_eq!(i64::min_value(), rdr.read_i64::<BigEndian>().unwrap());
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error> where
T: ByteOrder,
T: ByteOrder,
Reads an unsigned n-bytes integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read an unsigned n-byte big-endian integer from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0x80, 0x74, 0xfa]); assert_eq!(8418554, rdr.read_uint::<BigEndian>(3).unwrap());
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error> where
T: ByteOrder,
T: ByteOrder,
Reads a signed n-bytes integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read an unsigned n-byte big-endian integer from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0xc1, 0xff, 0x7c]); assert_eq!(-4063364, rdr.read_int::<BigEndian>(3).unwrap());
fn read_f32<T>(&mut self) -> Result<f32, Error> where
T: ByteOrder,
T: ByteOrder,
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
.
Examples
Read a big-endian single-precision floating point number from a Read
:
use std::f32; use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0x40, 0x49, 0x0f, 0xdb, ]); assert_eq!(f32::consts::PI, rdr.read_f32::<BigEndian>().unwrap());
fn read_f64<T>(&mut self) -> Result<f64, Error> where
T: ByteOrder,
T: ByteOrder,
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
.
Examples
Read a big-endian double-precision floating point number from a Read
:
use std::f64; use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18, ]); assert_eq!(f64::consts::PI, rdr.read_f64::<BigEndian>().unwrap());
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of unsigned 16 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of unsigned 16 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![2, 5, 3, 0]); let mut dst = [0; 2]; rdr.read_u16_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([517, 768], dst);
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of unsigned 32 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of unsigned 32 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0, 0, 2, 5, 0, 0, 3, 0]); let mut dst = [0; 2]; rdr.read_u32_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([517, 768], dst);
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of unsigned 64 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of unsigned 64 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0, 3, 0, ]); let mut dst = [0; 2]; rdr.read_u64_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([517, 768], dst);
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of signed 16 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of signed 16 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![2, 5, 3, 0]); let mut dst = [0; 2]; rdr.read_i16_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([517, 768], dst);
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of signed 32 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of signed 32 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![0, 0, 2, 5, 0, 0, 3, 0]); let mut dst = [0; 2]; rdr.read_i32_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([517, 768], dst);
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of signed 64 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of signed 64 bit big-endian integers from a Read
:
use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0, 3, 0, ]); let mut dst = [0; 2]; rdr.read_i64_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([517, 768], dst);
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of big-endian single-precision floating point number
from a Read
:
use std::f32; use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0x40, 0x49, 0x0f, 0xdb, 0x3f, 0x80, 0x00, 0x00, ]); let mut dst = [0.0; 2]; rdr.read_f32_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([f32::consts::PI, 1.0], dst);
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
: please use read_f32_into
instead
DEPRECATED.
This method is deprecated. Use read_f32_into
instead.
Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of big-endian single-precision floating point number
from a Read
:
use std::f32; use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0x40, 0x49, 0x0f, 0xdb, 0x3f, 0x80, 0x00, 0x00, ]); let mut dst = [0.0; 2]; rdr.read_f32_into_unchecked::<BigEndian>(&mut dst).unwrap(); assert_eq!([f32::consts::PI, 1.0], dst);
fn read_f64_into<T>(&mut self, dst: &mut [f64]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of big-endian single-precision floating point number
from a Read
:
use std::f64; use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18, 0x3f, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]); let mut dst = [0.0; 2]; rdr.read_f64_into::<BigEndian>(&mut dst).unwrap(); assert_eq!([f64::consts::PI, 1.0], dst);
fn read_f64_into_unchecked<T>(&mut self, dst: &mut [f64]) -> Result<(), Error> where
T: ByteOrder,
T: ByteOrder,
: please use read_f64_into
instead
DEPRECATED.
This method is deprecated. Use read_f64_into
instead.
Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned, the contents of dst
are unspecified.
Safety
This method is unsafe because there are no guarantees made about the floating point values. In particular, this method does not check for signaling NaNs, which may result in undefined behavior.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read a sequence of big-endian single-precision floating point number
from a Read
:
use std::f64; use std::io::Cursor; use byteorder::{BigEndian, ReadBytesExt}; let mut rdr = Cursor::new(vec![ 0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18, 0x3f, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]); let mut dst = [0.0; 2]; rdr.read_f64_into_unchecked::<BigEndian>(&mut dst).unwrap(); assert_eq!([f64::consts::PI, 1.0], dst);
Implementors
impl<R> ReadBytesExt for R where
R: Read + ?Sized,
impl<R> ReadBytesExt for R where
R: Read + ?Sized,
All types that implement Read
get methods defined in ReadBytesExt
for free.
fn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
fn read_u16<T>(&mut self) -> Result<u16, Error> where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error> where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error> where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error> where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error> where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error> where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error> where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error> where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error> where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error> where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error> where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error> where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error> where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error> where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error> where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error> where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error> where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error> where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error> where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error> where
T: ByteOrder,
fn 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,
fn 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,
fn read_f32<T>(&mut self) -> Result<f32, Error> where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error> where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error> where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error> where
T: ByteOrder,
fn 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,
fn 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,
fn 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,
fn 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,
fn 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,
fn 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,
fn 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,
fn 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,
: please use read_f32_into
instead
fn read_f64_into<T>(&mut self, dst: &mut [f64]) -> Result<(), Error> where
T: ByteOrder,
fn read_f64_into<T>(&mut self, dst: &mut [f64]) -> Result<(), Error> where
T: ByteOrder,
fn read_f64_into_unchecked<T>(&mut self, dst: &mut [f64]) -> Result<(), Error> where
T: ByteOrder,
fn read_f64_into_unchecked<T>(&mut self, dst: &mut [f64]) -> Result<(), Error> where
T: ByteOrder,
: please use read_f64_into
instead