[][src]Trait async_codec::Encode

pub trait Encode {
    type Item;
    type Error;
    fn encode(
        &mut self,
        item: &Self::Item,
        buf: &mut [u8]
    ) -> EncodeResult<Self::Error>; fn reset(&mut self) { ... } }

Trait for things that can be encoded to a byte buffer

Associated Types

type Item

The item being encoded

type Error

The error that may arise from serializing the value

Loading content...

Required methods

fn encode(
    &mut self,
    item: &Self::Item,
    buf: &mut [u8]
) -> EncodeResult<Self::Error>

Encode self and place the encoded representation in the provided buffer.

Returns either a usize representing the length of the buffer used, or an EncodeResult::Overflow containing either the minimum required buffer length, or the error arising from the serialization itself.

Types implementing Encode may employ internal buffering to make repeated calls to encode with the same object cheaper in the event of an overflow error. If buffering is employed, the internal buffer should be cleared after the item has been successfully copied into the provided one.

Loading content...

Provided methods

fn reset(&mut self)

Signal the encoder that it should discard its internal buffer if it has one.

This may be needed if the encoder caches the result of encoding an Item between an Overflow result and the Ok once the caller has provided an adequate buffer. Because the caller may not support a growable buffer, encoders cannot rely on being able to discard thier buffer when returning Ok.

Loading content...

Implementors

Loading content...