Struct bytecodec::bytes::BytesDecoder[][src]

pub struct BytesDecoder<B = Vec<u8>> { /* fields omitted */ }

BytesDecoder copies bytes from an input sequence to a slice.

This is a oneshot decoder (i.e., it decodes only one item).

Examples

use bytecodec::Decode;
use bytecodec::bytes::BytesDecoder;
use bytecodec::io::IoDecodeExt;

let mut decoder = BytesDecoder::new([0; 3]);
assert_eq!(decoder.requiring_bytes().to_u64(), Some(3));

let item = decoder.decode_exact(b"foobar".as_ref()).unwrap();
assert_eq!(item.as_ref(), b"foo");
assert_eq!(decoder.requiring_bytes().to_u64(), Some(0)); // no more items are decoded

Methods

impl<B: AsRef<[u8]> + AsMut<[u8]>> BytesDecoder<B>
[src]

Makes a new BytesDecoder instance for filling the given byte slice.

Sets the byte slice to be filled.

Trait Implementations

impl<B: Debug> Debug for BytesDecoder<B>
[src]

Formats the value using the given formatter. Read more

impl<B: Default> Default for BytesDecoder<B>
[src]

Returns the "default value" for a type. Read more

impl<B: AsRef<[u8]> + AsMut<[u8]>> Decode for BytesDecoder<B>
[src]

The type of items to be decoded.

Consumes the given buffer (a part of a byte sequence), and proceeds the decoding process. Read more

Finishes the current decoding process and returns the decoded item. Read more

Returns the lower bound of the number of bytes needed to decode the next item. Read more

Returns true if there are no items to be decoded by the decoder at the next invocation of decode method, otherwise false. Read more

Auto Trait Implementations

impl<B> Send for BytesDecoder<B> where
    B: Send

impl<B> Sync for BytesDecoder<B> where
    B: Sync