[−][src]Trait bytecodec::Encode
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 [u8], eos: Eos) -> Result<usize>
Encodes the items in the encoder and writes the encoded bytes to the given buffer.
It returns the number of bytes written to the given buffer.
If the encoded bytes are larger than the length of buf
,
the encoder must consume as many bytes in the buffer as possible.
The completion of the encoding can be detected by using is_idle
method.
If self.is_idle()
returns false
but the number of written bytes in the last encode
invocation
is smaller than the length of buf
, it means the encoder has been suspended its work in any reasons.
In that case the encoder may require some instructions from clients to resume the work,
but its concrete method is beyond the scope of this trait.
The encoded bytes that could not be written to the given buffer 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 stream has reached the end in the middle of an encoding process
ErrorKind::InconsistentState
:- The state of the encoder bocame inconsistent
- This means the implementation contains a bug
ErrorKind::Other
:- Other errors has occurred
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
Tries to start encoding the given item.
If the encoder has no items to be encoded and the passed item is valid, it must accept the item.
Errors
ErrorKind::EncoderFull
:- The encoder currently cannot accept any more items
ErrorKind::InvalidInput
:- An invalid item was passed
ErrorKind::InconsistentState
:- The state of the encoder bocame inconsistent
- This means the implementation contains a bug
ErrorKind::Other
:- Other errors has occurred
fn requiring_bytes(&self) -> ByteCount
Returns the number of bytes required to encode all the items in the encoder.
If there are no items to be encoded, the encoder must return ByteCount::Finite(0)
.
Provided methods
fn is_idle(&self) -> bool
Returns true
if there are no items to be encoded in the encoder, otherwise false
.
The default implementation returns the result of self.requiring_bytes() == ByteCount::Finite(0)
.
Implementations on Foreign Types
impl<'a, E: ?Sized + Encode> Encode for &'a mut E
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E: ?Sized + Encode> Encode for Box<E>
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
Implementors
impl Encode for F32beEncoder
[src]
type Item = f32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for F32leEncoder
[src]
type Item = f32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for F64beEncoder
[src]
type Item = f64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for F64leEncoder
[src]
type Item = f64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I16beEncoder
[src]
type Item = i16
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I16leEncoder
[src]
type Item = i16
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I32beEncoder
[src]
type Item = i32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I32leEncoder
[src]
type Item = i32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I64beEncoder
[src]
type Item = i64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I64leEncoder
[src]
type Item = i64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for I8Encoder
[src]
type Item = i8
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U16beEncoder
[src]
type Item = u16
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U16leEncoder
[src]
type Item = u16
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U24beEncoder
[src]
type Item = u32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U24leEncoder
[src]
type Item = u32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U32beEncoder
[src]
type Item = u32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U32leEncoder
[src]
type Item = u32
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U40beEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U40leEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U48beEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U48leEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U56beEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U56leEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U64beEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U64leEncoder
[src]
type Item = u64
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for U8Encoder
[src]
type Item = u8
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for NullEncoder
[src]
type Item = ()
fn encode(&mut self, _buf: &mut [u8], _eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, _item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl Encode for PaddingEncoder
[src]
type Item = u8
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<B: AsRef<[u8]>> Encode for BytesEncoder<B>
[src]
type Item = B
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<C, E, F> Encode for MapErr<C, E, F> where
C: Encode,
F: Fn(Error) -> E,
Error: From<E>,
[src]
C: Encode,
F: Fn(Error) -> E,
Error: From<E>,
type Item = C::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
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>,
[src]
C: Encode,
F: Fn(T) -> Result<C::Item, E>,
Error: From<E>,
type Item = T
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E, I> Encode for Repeat<E, I> where
E: Encode,
I: Iterator<Item = E::Item>,
[src]
E: Encode,
I: Iterator<Item = E::Item>,
type Item = I
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E, T, F> Encode for MapFrom<E, T, F> where
E: Encode,
F: Fn(T) -> E::Item,
[src]
E: Encode,
F: Fn(T) -> E::Item,
type Item = T
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1> Encode for TupleEncoder<(E0, E1)> where
E0: Encode,
E1: Encode,
[src]
E0: Encode,
E1: Encode,
type Item = (E0::Item, E1::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1, E2> Encode for TupleEncoder<(E0, E1, E2)> where
E0: Encode,
E1: Encode,
E2: Encode,
[src]
E0: Encode,
E1: Encode,
E2: Encode,
type Item = (E0::Item, E1::Item, E2::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1, E2, E3> Encode for TupleEncoder<(E0, E1, E2, E3)> where
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
[src]
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
type Item = (E0::Item, E1::Item, E2::Item, E3::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1, E2, E3, E4> Encode for TupleEncoder<(E0, E1, E2, E3, E4)> where
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
[src]
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
type Item = (E0::Item, E1::Item, E2::Item, E3::Item, E4::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1, E2, E3, E4, E5> Encode for TupleEncoder<(E0, E1, E2, E3, E4, E5)> where
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
E5: Encode,
[src]
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
E5: Encode,
type Item = (E0::Item, E1::Item, E2::Item, E3::Item, E4::Item, E5::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1, E2, E3, E4, E5, E6> Encode for TupleEncoder<(E0, E1, E2, E3, E4, E5, E6)> where
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
E5: Encode,
E6: Encode,
[src]
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
E5: Encode,
E6: Encode,
type Item = (E0::Item, E1::Item, E2::Item, E3::Item, E4::Item, E5::Item, E6::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E0, E1, E2, E3, E4, E5, E6, E7> Encode for TupleEncoder<(E0, E1, E2, E3, E4, E5, E6, E7)> where
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
E5: Encode,
E6: Encode,
E7: Encode,
[src]
E0: Encode,
E1: Encode,
E2: Encode,
E3: Encode,
E4: Encode,
E5: Encode,
E6: Encode,
E7: Encode,
type Item = (E0::Item, E1::Item, E2::Item, E3::Item, E4::Item, E5::Item, E6::Item, E7::Item)
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, t: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E: MonolithicEncode> Encode for MonolithicEncoder<E>
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn is_idle(&self) -> bool
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
impl<E: Encode> Encode for Last<E>
[src]
type Item = Never
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, _item: Self::Item) -> Result<()>
[src]
fn is_idle(&self) -> bool
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
impl<E: Encode> Encode for Length<E>
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E: Encode> Encode for MaxBytes<E>
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E: Encode> Encode for Optional<E>
[src]
type Item = Option<E::Item>
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E: Encode> Encode for PreEncode<E>
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<E: Encode> Encode for Slice<E>
[src]
type Item = E::Item
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn is_idle(&self) -> bool
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
impl<S: AsRef<str>> Encode for Utf8Encoder<S>
[src]
type Item = S
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
fn is_idle(&self) -> bool
[src]
impl<T> Encode for BincodeEncoder<T> where
T: Serialize,
[src]
T: Serialize,
type Item = T
fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>
[src]
fn start_encoding(&mut self, item: Self::Item) -> Result<()>
[src]
fn is_idle(&self) -> bool
[src]
fn requiring_bytes(&self) -> ByteCount
[src]
impl<T> Encode for JsonEncoder<T> where
T: Serialize,
[src]
T: Serialize,