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
type Item
The type of items to be encoded.
Required Methods
fn encode(&mut self, buf: &mut EncodeBuf) -> Result<()>
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
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
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
fn is_idle(&self) -> bool
Returns true if there are no items to be encoded in the encoder, otherwise false.
Provided Methods
fn requiring_bytes_hint(&self) -> Option<u64>
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]
Implementors
impl<T> Encode for BincodeEncoder<T> where
T: Serialize, type Item = T;impl<B: AsRef<[u8]>> Encode for BytesEncoder<B> type Item = B;impl<S: AsRef<str>> Encode for Utf8Encoder<S> type Item = S;impl<C, F, E> Encode for MapErr<C, F, E> where
C: Encode,
F: Fn(Error) -> E,
Error: From<E>, type Item = C::Item;impl<E, T, F> Encode for MapFrom<E, T, F> where
E: Encode,
F: Fn(T) -> E::Item, type Item = T;impl<C, T, E, F> Encode for TryMapFrom<C, T, E, F> where
C: Encode,
F: Fn(T) -> Result<C::Item, E>,
Error: From<E>, type Item = T;impl<E, I> Encode for Repeat<E, I> where
E: Encode,
I: Iterator<Item = E::Item>, type Item = I;impl<E: Encode> Encode for Optional<E> type Item = Option<E::Item>;impl<E: Encode> Encode for Length<E> type Item = E::Item;impl<E: Encode> Encode for MaxBytes<E> type Item = E::Item;impl<E: Encode> Encode for Padding<E> type Item = E::Item;impl<E0, E1, F> Encode for WithPrefix<E0, E1, F> where
E0: Encode,
E1: Encode,
F: Fn(&E0) -> E1::Item, type Item = E0::Item;impl Encode for U8Encoder type Item = u8;impl Encode for I8Encoder type Item = i8;impl Encode for U16beEncoder type Item = u16;impl Encode for U16leEncoder type Item = u16;impl Encode for I16beEncoder type Item = i16;impl Encode for I16leEncoder type Item = i16;impl Encode for U24beEncoder type Item = u32;impl Encode for U24leEncoder type Item = u32;impl Encode for U32beEncoder type Item = u32;impl Encode for U32leEncoder type Item = u32;impl Encode for I32beEncoder type Item = i32;impl Encode for I32leEncoder type Item = i32;impl Encode for U40beEncoder type Item = u64;impl Encode for U40leEncoder type Item = u64;impl Encode for U48beEncoder type Item = u64;impl Encode for U48leEncoder type Item = u64;impl Encode for U56beEncoder type Item = u64;impl Encode for U56leEncoder type Item = u64;impl Encode for U64beEncoder type Item = u64;impl Encode for U64leEncoder type Item = u64;impl Encode for I64beEncoder type Item = i64;impl Encode for I64leEncoder type Item = i64;impl Encode for F32beEncoder type Item = f32;impl Encode for F32leEncoder type Item = f32;impl Encode for F64beEncoder type Item = f64;impl Encode for F64leEncoder type Item = f64;impl<T> Encode for JsonEncoder<T> where
T: Serialize, type Item = T;impl<E: MonolithicEncode> Encode for MonolithicEncoder<E> type Item = E::Item;impl Encode for StartEncoderChain type Item = ();impl<E> Encode for EncoderChain<StartEncoderChain, E, ()> where
E: Encode, type Item = (E::Item,);impl<E0, E1, T0> Encode for EncoderChain<E0, E1, (T0,)> where
E0: Encode<Item = (T0,)>,
E1: Encode, type Item = (T0, E1::Item);impl<E0, E1, T0, T1> Encode for EncoderChain<E0, E1, (T0, T1)> where
E0: Encode<Item = (T0, T1)>,
E1: Encode, type Item = (T0, T1, E1::Item);impl<E0, E1, T0, T1, T2> Encode for EncoderChain<E0, E1, (T0, T1, T2)> where
E0: Encode<Item = (T0, T1, T2)>,
E1: Encode, type Item = (T0, T1, T2, E1::Item);impl<E0, E1, T0, T1, T2, T3> Encode for EncoderChain<E0, E1, (T0, T1, T2, T3)> where
E0: Encode<Item = (T0, T1, T2, T3)>,
E1: Encode, type Item = (T0, T1, T2, T3, E1::Item);impl<E0, E1, T0, T1, T2, T3, T4> Encode for EncoderChain<E0, E1, (T0, T1, T2, T3, T4)> where
E0: Encode<Item = (T0, T1, T2, T3, T4)>,
E1: Encode, type Item = (T0, T1, T2, T3, T4, E1::Item);impl<E0, E1, T0, T1, T2, T3, T4, T5> Encode for EncoderChain<E0, E1, (T0, T1, T2, T3, T4, T5)> where
E0: Encode<Item = (T0, T1, T2, T3, T4, T5)>,
E1: Encode, type Item = (T0, T1, T2, T3, T4, T5, E1::Item);impl<E0, E1, T0, T1, T2, T3, T4, T5, T6> Encode for EncoderChain<E0, E1, (T0, T1, T2, T3, T4, T5, T6)> where
E0: Encode<Item = (T0, T1, T2, T3, T4, T5, T6)>,
E1: Encode, type Item = (T0, T1, T2, T3, T4, T5, T6, E1::Item);