[−][src]Trait byteio::ReadBytesExt
Extends ReadBytes
with functions for reading numbers.
Examples
Read u16
s from a buffer using native endianness:
use byteio::ReadBytesExt; use byteorder::NativeEndian; fn main() { let mut buf = &[0_u8, 1, 1, 0][..]; let a = buf.read_u16::<NativeEndian>(); let b = buf.read_u16::<NativeEndian>(); assert!(buf.is_empty()); }
Try to read u16
s from a buffer using a specific endianness:
use byteio::ReadBytesExt; use byteorder::{BigEndian, LittleEndian}; fn main() -> byteio::Result<()> { let mut buf = &[0_u8, 1, 1, 0][..]; let a = buf.try_read_u16::<BigEndian>()?; let b = buf.try_read_u16::<LittleEndian>()?; assert_eq!(a, 1); assert_eq!(b, 1); assert!(buf.is_empty()); Ok(()) }
Provided methods
fn read_u8(&mut self) -> u8
fn try_read_u8(&mut self) -> Result<u8>
Attempts to read a u8
from the underlying buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn read_i8(&mut self) -> i8
fn try_read_i8(&mut self) -> Result<i8>
Attempts to read an i8
from the underlying buffer.
If there are not enough bytes in self
this function will return
Error::EndOfStream
.
fn read_u16<E: ByteOrder>(&mut self) -> u16
fn try_read_u16<E: ByteOrder>(&mut self) -> Result<u16>
Attempts to read a u16
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i16<E: ByteOrder>(&mut self) -> i16
fn try_read_i16<E: ByteOrder>(&mut self) -> Result<i16>
Attempts to read an i16
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_u32<E: ByteOrder>(&mut self) -> u32
fn try_read_u32<E: ByteOrder>(&mut self) -> Result<u32>
Attempts to read a u32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i32<E: ByteOrder>(&mut self) -> i32
fn try_read_i32<E: ByteOrder>(&mut self) -> Result<i32>
Attempts to read an i32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_u64<E: ByteOrder>(&mut self) -> u64
fn try_read_u64<E: ByteOrder>(&mut self) -> Result<u64>
Attempts to read a u64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i64<E: ByteOrder>(&mut self) -> i64
fn try_read_i64<E: ByteOrder>(&mut self) -> Result<i64>
Attempts to read an i64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_u128<E: ByteOrder>(&mut self) -> u128
fn try_read_u128<E: ByteOrder>(&mut self) -> Result<u128>
Attempts to read a u128
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_i128<E: ByteOrder>(&mut self) -> i128
fn try_read_i128<E: ByteOrder>(&mut self) -> Result<i128>
Attempts to read an i128
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_f32<E: ByteOrder>(&mut self) -> f32
Reads an IEEE754 f32
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_f32<E: ByteOrder>(&mut self) -> Result<f32>
Attempts to read an IEEE754 f32
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.
fn read_f64<E: ByteOrder>(&mut self) -> f64
Reads an IEEE754 f64
from the underlying buffer.
Panics
Panics if there are not enough bytes in self
.
fn try_read_f64<E: ByteOrder>(&mut self) -> Result<f64>
Attempts to read an IEEE754 f64
from the underlying buffer.
If there are not enough bytes in self
this function will return Error::EndOfStream
.