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

pub struct BytesDecoder<B> { /* 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]

[src]

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

[src]

Sets the byte slice to be filled.

Trait Implementations

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

[src]

Formats the value using the given formatter. Read more

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

[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.

[src]

Consumes the given buffer (a part of a byte sequence), and decodes an item from it. Read more

[src]

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

Auto Trait Implementations

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

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