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]
pub fn new(bytes: B) -> Self[src]
Makes a new CopyableBytesDecoder instance.
ⓘImportant traits for &'a mut Wpub fn inner_ref(&self) -> &B[src]
ⓘImportant traits for &'a mut W
Returns a reference to the inner bytes.
ⓘImportant traits for &'a mut Wpub fn inner_mut(&mut self) -> &mut B[src]
ⓘImportant traits for &'a mut W
Returns a mutable reference to the inner bytes.
pub fn into_inner(self) -> B[src]
Takes ownership of this instance and returns the inner bytes.
Trait Implementations
impl<B: Debug> Debug for CopyableBytesDecoder<B>[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more
impl<B: Default> Default for CopyableBytesDecoder<B>[src]
fn default() -> CopyableBytesDecoder<B>[src]
Returns the "default value" for a type. Read more
impl<B: AsRef<[u8]> + AsMut<[u8]> + Copy> Decode for CopyableBytesDecoder<B>[src]
type Item = B
The type of items to be decoded.
fn decode(
&mut self,
buf: &[u8],
eos: Eos
) -> Result<(usize, Option<Self::Item>)>[src]
&mut self,
buf: &[u8],
eos: Eos
) -> Result<(usize, Option<Self::Item>)>
Consumes the given buffer (a part of a byte sequence), and decodes an item from it. Read more
fn requiring_bytes(&self) -> ByteCount[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,
B: Send,
impl<B> Sync for CopyableBytesDecoder<B> where
B: Sync,
B: Sync,