Trait bytecodec::Encode [] [src]

pub trait Encode {
    type Item;
    fn encode(&mut self, buf: &mut EncodeBuf) -> Result<()>;
fn start_encoding(&mut self, item: Self::Item) -> Result<()>;
fn is_idle(&self) -> bool; fn requiring_bytes_hint(&self) -> Option<u64> { ... } }

This trait allows for encoding items into a byte sequence incrementally.

Associated Types

The type of items to be encoded.

Required Methods

Encodes the current item and writes the encoded bytes to the given buffer as many as possible.

If the encoded bytes are larger than the length of buf, the encoder must consume all the bytes in the buffer. The encoded bytes that could not be written is held by the encoder until the next invocation of the encode() method.

Errors

Encoders return the following kinds of errors as necessary:

  • ErrorKind::InvalidInput:
    • An item that the encoder could not encode was passed
  • ErrorKind::UnexpectedEos:
    • The output byte sequence has reached the end in the middle of an encoding process
  • ErrorKind::Other:
    • Other errors has occurred

Tries to start encoding the given item.

If the encoding has no items to be encoded (i.e., is_idle() returns true) and the item is valid, the encoder should accept it.

Errors

  • ErrorKind::EncoderFull:
    • The encoder cannot accept any more items
  • ErrorKind::InvalidInput:
    • An invalid item was passed
  • ErrorKind::Other:
    • Other errors has occurred

Returns true if there are no items to be encoded in the encoder, otherwise false.

Provided Methods

Returns the number of bytes required to encode all the items in the encoder.

If the encoder does not known the value, it will return None.

If there is no items to be encoded, the encoder should return Ok(0).

The default implementation returns Some(0) if the encoder is idle, otherwise None.

Implementations on Foreign Types

impl<E: ?Sized + Encode> Encode for Box<E>
[src]

[src]

[src]

[src]

[src]

Implementors