[][src]Struct protocol::wire::Reader

pub struct Reader { /* fields omitted */ }

A receive buffer that waits until enough data is ready and then returns the parsed parcels.

This mechanism can be used to send parcels without length prefixes.

Adding data to the receive buffer

Reader implements std::io::Write. Any bytes written to the reader are added to the receive queue for future processing.

Example

This example shows a reader only returning a u32 once enough data has been buffered.

use protocol;
use std::io::Write;

let mut reader = protocol::wire::Reader::new();
let settings = protocol::Settings::default();

// No bytes received yet.
assert_eq!(None, reader.poll::<u32>(&settings).unwrap());

// Two bytes received.
reader.write(&[0xff, 0x00]).unwrap();
assert_eq!(None, reader.poll::<u32>(&settings).unwrap());

// Three bytes received.
reader.write(&[0x00]).unwrap();
assert_eq!(None, reader.poll::<u32>(&settings).unwrap());

// All four bytes received.
reader.write(&[0x00]).unwrap();
assert_eq!(Some(0xff000000), reader.poll::<u32>(&settings).unwrap());

Methods

impl Reader[src]

pub fn new() -> Self[src]

Creates a new parcel reader.

pub fn poll<P>(&mut self, settings: &Settings) -> Result<Option<P>, Error> where
    P: Parcel
[src]

Polls the reader for a value.

Returns Ok(None) if further data must be received in order to interpret the value.

Returns Ok(Some(value)) if the value is ready to be read from the stream.

Returns Err(e) on error.

Trait Implementations

impl Default for Reader[src]

impl Debug for Reader[src]

impl Write for Reader[src]

default fn write_vectored(&mut self, bufs: &[IoVec]) -> Result<usize, Error>[src]

🔬 This is a nightly-only experimental API. (iovec)

Like write, except that it writes from a slice of buffers. Read more

default fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
[src]

Attempts to write an entire buffer into this writer. Read more

default fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

default fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

Auto Trait Implementations

impl Send for Reader

impl Sync for Reader

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<W> WriteBytesExt for W where
    W: Write + ?Sized
[src]

default fn write_u8(&mut self, n: u8) -> Result<(), Error>[src]

Writes an unsigned 8 bit integer to the underlying writer. Read more

default fn write_i8(&mut self, n: i8) -> Result<(), Error>[src]

Writes a signed 8 bit integer to the underlying writer. Read more

default fn write_u16<T>(&mut self, n: u16) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned 16 bit integer to the underlying writer. Read more

default fn write_i16<T>(&mut self, n: i16) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed 16 bit integer to the underlying writer. Read more

default fn write_u24<T>(&mut self, n: u32) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned 24 bit integer to the underlying writer. Read more

default fn write_i24<T>(&mut self, n: i32) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed 24 bit integer to the underlying writer. Read more

default fn write_u32<T>(&mut self, n: u32) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned 32 bit integer to the underlying writer. Read more

default fn write_i32<T>(&mut self, n: i32) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed 32 bit integer to the underlying writer. Read more

default fn write_u48<T>(&mut self, n: u64) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned 48 bit integer to the underlying writer. Read more

default fn write_i48<T>(&mut self, n: i64) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed 48 bit integer to the underlying writer. Read more

default fn write_u64<T>(&mut self, n: u64) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned 64 bit integer to the underlying writer. Read more

default fn write_i64<T>(&mut self, n: i64) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed 64 bit integer to the underlying writer. Read more

default fn write_u128<T>(&mut self, n: u128) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned 128 bit integer to the underlying writer.

default fn write_i128<T>(&mut self, n: i128) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed 128 bit integer to the underlying writer.

default fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned n-bytes integer to the underlying writer. Read more

default fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed n-bytes integer to the underlying writer. Read more

default fn write_uint128<T>(
    &mut self,
    n: u128,
    nbytes: usize
) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes an unsigned n-bytes integer to the underlying writer. Read more

default fn write_int128<T>(
    &mut self,
    n: i128,
    nbytes: usize
) -> Result<(), Error> where
    T: ByteOrder
[src]

Writes a signed n-bytes integer to the underlying writer. Read more

default fn write_f32<T>(&mut self, n: f32) -> Result<(), Error> where
    T: ByteOrder
[src]

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

default fn write_f64<T>(&mut self, n: f64) -> Result<(), Error> where
    T: ByteOrder
[src]

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