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));
let (_, item) = decoder.decode(&input[0..3], Eos::new(false)).unwrap();
assert_eq!(item.as_ref(), Some(b"foo"));

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

let (_, item) = decoder.decode(&input[5..], Eos::new(true)).unwrap();
assert_eq!(item.as_ref(), Some(b"bar"));

Methods

impl<B> CopyableBytesDecoder<B>
[src]

[src]

Makes a new CopyableBytesDecoder instance.

Important traits for &'a mut W
[src]

Returns a reference to the inner bytes.

Important traits for &'a mut W
[src]

Returns a mutable reference to the inner bytes.

[src]

Takes ownership of this instance and returns the inner bytes.

Trait Implementations

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

[src]

Formats the value using the given formatter. Read more

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

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

[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 CopyableBytesDecoder<B> where
    B: Send

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