Struct bytecodec::bytes::CopyableBytesDecoder[][src]

pub struct CopyableBytesDecoder<B> { /* fields omitted */ }

A variant of BytesDecoder for copyable bytes types.

Unlike BytesDecoder, this has no restriction on decoding count.

Examples

use bytecodec::{Decode, Eos};
use bytecodec::bytes::CopyableBytesDecoder;

let mut decoder = CopyableBytesDecoder::new([0; 3]);
let mut input = b"foobar";

// Decodes first item
assert_eq!(decoder.requiring_bytes().to_u64(), Some(3));
decoder.decode(&input[0..3], Eos::new(false)).unwrap();
assert_eq!(decoder.is_idle(), true);
assert_eq!(decoder.finish_decoding().unwrap(), *b"foo");

// Decodes second item
assert_eq!(decoder.requiring_bytes().to_u64(), Some(3));
decoder.decode(&input[3..5], Eos::new(false)).unwrap();
assert_eq!(decoder.is_idle(), false);
assert_eq!(decoder.requiring_bytes().to_u64(), Some(1));

decoder.decode(&input[5..], Eos::new(true)).unwrap();
assert_eq!(decoder.is_idle(), true);
assert_eq!(decoder.finish_decoding().unwrap(), *b"bar");

Methods

impl<B> CopyableBytesDecoder<B>
[src]

Makes a new CopyableBytesDecoder instance.

Important traits for &'a mut R

Returns a reference to the inner bytes.

Important traits for &'a mut R

Returns a mutable reference to the inner bytes.

Takes ownership of this instance and returns the inner bytes.

Trait Implementations

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

Formats the value using the given formatter. Read more

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

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

impl<B: AsRef<[u8]> + AsMut<[u8]> + Copy> Decode for CopyableBytesDecoder<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 CopyableBytesDecoder<B> where
    B: Send

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