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