Struct bytecodec::combinator::MaxBytes [−][src]
pub struct MaxBytes<C> { /* fields omitted */ }Combinator that will fail if the number of consumed bytes exceeds the specified size.
This is created by calling {DecodeExt, EncodeExt}::max_bytes method.
Note that MaxBytes assumes the inner decoder will consume all the bytes in the target stream.
Methods
impl<C> MaxBytes<C>[src]
impl<C> MaxBytes<C>pub fn consumed_bytes(&self) -> u64[src]
pub fn consumed_bytes(&self) -> u64Returns the number of bytes consumed for encoding/decoding the current item.
pub fn max_bytes(&self) -> u64[src]
pub fn max_bytes(&self) -> u64Returns the maximum number of bytes that can be consumed for encoding/decoding an item.
pub fn set_max_bytes(&mut self, n: u64) -> Result<()>[src]
pub fn set_max_bytes(&mut self, n: u64) -> Result<()>Sets the maximum number of bytes that can be consumed for encoding/decoding an item.
Error
If n is smaller than self.consumed_bytes(), an ErrorKind::InvalidInput error will be returned.
ⓘImportant traits for &'a mut Rpub fn inner_ref(&self) -> &C[src]
pub fn inner_ref(&self) -> &CReturns a reference to the inner encoder or decoder.
ⓘImportant traits for &'a mut Rpub fn inner_mut(&mut self) -> &mut C[src]
pub fn inner_mut(&mut self) -> &mut CReturns a mutable reference to the inner encoder or decoder.
pub fn into_inner(self) -> C[src]
pub fn into_inner(self) -> CTakes ownership of this instance and returns the inner encoder or decoder.
Trait Implementations
impl<C: Debug> Debug for MaxBytes<C>[src]
impl<C: Debug> Debug for MaxBytes<C>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<C: Default> Default for MaxBytes<C>[src]
impl<C: Default> Default for MaxBytes<C>impl<D: Decode> Decode for MaxBytes<D>[src]
impl<D: Decode> Decode for MaxBytes<D>type Item = D::Item
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) -> ByteCountReturns 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) -> boolReturns true if there are no items to be decoded by the decoder at the next invocation of decode method, otherwise false. Read more
impl<E: Encode> Encode for MaxBytes<E>[src]
impl<E: Encode> Encode for MaxBytes<E>type Item = E::Item
The type of items to be encoded.
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>[src]
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>Encodes the items in the encoder and writes the encoded bytes to the given buffer. Read more
fn start_encoding(&mut self, item: Self::Item) -> Result<()>[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>Tries to start encoding the given item. Read more
fn requiring_bytes(&self) -> ByteCount[src]
fn requiring_bytes(&self) -> ByteCountReturns the number of bytes required to encode all the items in the encoder. Read more
fn is_idle(&self) -> bool[src]
fn is_idle(&self) -> boolReturns true if there are no items to be encoded in the encoder, otherwise false. Read more
impl<E: SizedEncode> SizedEncode for MaxBytes<E>[src]
impl<E: SizedEncode> SizedEncode for MaxBytes<E>fn exact_requiring_bytes(&self) -> u64[src]
fn exact_requiring_bytes(&self) -> u64Returns the exact number of bytes required to encode all the items remaining in the encoder.