Trait bytes::Buf
[−]
[src]
pub trait Buf { fn remaining(&self) -> usize; fn bytes(&self) -> &[u8]; fn advance(&mut self, cnt: usize); fn has_remaining(&self) -> bool { ... } fn copy_to<S: Sink + ?Sized>(&mut self, dst: &mut S) where Self: Sized { ... } fn copy_to_slice(&mut self, dst: &mut [u8]) { ... } fn peek_u8(&self) -> Option<u8> { ... } fn get_u8(&mut self) -> u8 { ... } fn get_i8(&mut self) -> i8 { ... } fn get_u16<T: ByteOrder>(&mut self) -> u16 { ... } fn get_i16<T: ByteOrder>(&mut self) -> i16 { ... } fn get_u32<T: ByteOrder>(&mut self) -> u32 { ... } fn get_i32<T: ByteOrder>(&mut self) -> i32 { ... } fn get_u64<T: ByteOrder>(&mut self) -> u64 { ... } fn get_i64<T: ByteOrder>(&mut self) -> i64 { ... } fn get_uint<T: ByteOrder>(&mut self, nbytes: usize) -> u64 { ... } fn get_int<T: ByteOrder>(&mut self, nbytes: usize) -> i64 { ... } fn get_f32<T: ByteOrder>(&mut self) -> f32 { ... } fn get_f64<T: ByteOrder>(&mut self) -> f64 { ... } fn by_ref(&mut self) -> &mut Self where Self: Sized { ... } fn take(self, limit: usize) -> Take<Self> where Self: Sized { ... } fn reader(self) -> Reader<Self> where Self: Sized { ... } }
A trait for values that provide sequential read access to bytes.
Required Methods
fn remaining(&self) -> usize
Returns the number of bytes that can be accessed from the Buf
fn bytes(&self) -> &[u8]
Returns a slice starting at the current Buf position and of length
between 0 and Buf::remaining()
.
fn advance(&mut self, cnt: usize)
Advance the internal cursor of the Buf
Provided Methods
fn has_remaining(&self) -> bool
Returns true if there are any more bytes to consume
fn copy_to<S: Sink + ?Sized>(&mut self, dst: &mut S) where Self: Sized
Copies bytes from self
into dst
Panics
The function panics if self
does not contain enough bytes to fill
dst
.
fn copy_to_slice(&mut self, dst: &mut [u8])
Copies bytes from the Buf
into the given slice and advance the cursor by
the number of bytes copied.
use std::io::Cursor; use bytes::Buf; let mut buf = Cursor::new(b"hello world"); let mut dst = [0; 5]; buf.copy_to_slice(&mut dst); assert_eq!(b"hello", &dst); assert_eq!(6, buf.remaining());
Panics
This function panics if self.remaining() < dst.len()
fn peek_u8(&self) -> Option<u8>
Gets an unsigned 8 bit integer from the Buf
without advancing the
buffer cursor
fn get_u8(&mut self) -> u8
Gets an unsigned 8 bit integer from the Buf
.
fn get_i8(&mut self) -> i8
Gets a signed 8 bit integer from the Buf
.
fn get_u16<T: ByteOrder>(&mut self) -> u16
Gets an unsigned 16 bit integer from the Buf
fn get_i16<T: ByteOrder>(&mut self) -> i16
Gets a signed 16 bit integer from the Buf
fn get_u32<T: ByteOrder>(&mut self) -> u32
Gets an unsigned 32 bit integer from the Buf
fn get_i32<T: ByteOrder>(&mut self) -> i32
Gets a signed 32 bit integer from the Buf
fn get_u64<T: ByteOrder>(&mut self) -> u64
Gets an unsigned 64 bit integer from the Buf
fn get_i64<T: ByteOrder>(&mut self) -> i64
Gets a signed 64 bit integer from the Buf
fn get_uint<T: ByteOrder>(&mut self, nbytes: usize) -> u64
Gets an unsigned n-bytes integer from the Buf
fn get_int<T: ByteOrder>(&mut self, nbytes: usize) -> i64
Gets a signed n-bytes integer from the Buf
fn get_f32<T: ByteOrder>(&mut self) -> f32
Gets a IEEE754 single-precision (4 bytes) floating point number from
the Buf
fn get_f64<T: ByteOrder>(&mut self) -> f64
Gets a IEEE754 double-precision (8 bytes) floating point number from
the Buf
fn by_ref(&mut self) -> &mut Self where Self: Sized
Creates a "by reference" adaptor for this instance of Buf
fn take(self, limit: usize) -> Take<Self> where Self: Sized
Create an adapter which will limit at most limit
bytes from it.
fn reader(self) -> Reader<Self> where Self: Sized
Return a Reader
for the value. Allows using a Buf
as an io::Read