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]
pub fn new(bytes: B) -> Self
[src]
Makes a new BytesDecoder
instance for filling the given byte slice.
Trait Implementations
impl<B: Debug> Debug for BytesDecoder<B>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<B: AsRef<[u8]> + AsMut<[u8]>> Decode for BytesDecoder<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 has_terminated(&self) -> bool
[src]
Returns true
if the decoder cannot decode items anymore, otherwise false
. 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 BytesDecoder<B> where
B: Send,
B: Send,
impl<B> Sync for BytesDecoder<B> where
B: Sync,
B: Sync,