Trait bytecodec::Decode [] [src]

pub trait Decode {
    type Item;
    fn decode(&mut self, buf: &mut DecodeBuf) -> Result<Option<Self::Item>>;
fn has_terminated(&self) -> bool;
fn is_idle(&self) -> bool; fn requiring_bytes_hint(&self) -> Option<u64> { ... } }

This trait allows for decoding items from a byte sequence incrementally.

Associated Types

The type of items to be decoded.

Required Methods

Consumes the given buffer (a part of a byte sequence), and decodes an item from it.

If an item is successfully decoded, the decoder will return Ok(Some(..)).

If the buffer does not contain enough bytes to decode the next item, the decoder will return Ok(None). In this case, the decoder must consume all the bytes in the buffer.

Errors

Decoders return the following kinds of errors as necessary:

  • ErrorKind::DecoderTerminated:
    • If all decodable items have been decoded, the decoder must return this kind of error when decode() method is called.
  • ErrorKind::UnexpectedEos:
    • DecodeBuf::is_eos() returns true despite of the decoder requires more bytes to decode the next item.
  • ErrorKind::InvalidInput:
    • Decoded items have invalid values
    • Invalid parameters were given to decoders
  • ErrorKind::Error:
    • Other errors

Returns true if the decoder cannot decode items anymore, otherwise false.

If it returns true, the next invocation of decode method must return an ErrorKind::DecoderTerminated error.

Returns true if the decoder does not have an item that being decoded, otherwise false.

Provided Methods

Returns the lower bound of the number of bytes needed to decode the next item.

If the decoder does not know the value, it will return None (e.g., null-terminated strings have no pre-estimable length).

If the decoder returns Some(0), it means one of the followings:

  • (a) There is an already decoded item
    • The next invocation of decode() will return it without consuming any bytes
  • (b) There are no decodable items
    • All decodable items have been decoded, and the decoder cannot do any further works

The default implementation returns Some(0) if the decoder has terminated, otherwise None.

Implementations on Foreign Types

impl<D: ?Sized + Decode> Decode for Box<D>
[src]

[src]

[src]

[src]

[src]

Implementors