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
type Item
The type of items to be decoded.
Required Methods
fn decode(&mut self, buf: &mut DecodeBuf) -> Result<Option<Self::Item>>
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.
- If all decodable items have been decoded,
the decoder must return this kind of error when
ErrorKind::UnexpectedEos:DecodeBuf::is_eos()returnstruedespite 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
fn has_terminated(&self) -> bool
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.
fn is_idle(&self) -> bool
Returns true if the decoder does not have an item that being decoded, otherwise false.
Provided Methods
fn requiring_bytes_hint(&self) -> Option<u64>
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
- The next invocation of
- (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]
Implementors
impl<T> Decode for BincodeDecoder<T> where
T: for<'de> Deserialize<'de>, type Item = T;impl<B: AsRef<[u8]> + AsMut<[u8]> + Copy> Decode for CopyableBytesDecoder<B> type Item = B;impl<B: AsRef<[u8]> + AsMut<[u8]>> Decode for BytesDecoder<B> type Item = B;impl Decode for RemainingBytesDecoder type Item = Vec<u8>;impl<D> Decode for Utf8Decoder<D> where
D: Decode<Item = Vec<u8>>, type Item = String;impl<D, T, F> Decode for Map<D, T, F> where
D: Decode,
F: Fn(D::Item) -> T, type Item = T;impl<D, F, E> Decode for MapErr<D, F, E> where
D: Decode,
F: Fn(Error) -> E,
Error: From<E>, type Item = D::Item;impl<D0, D1, F> Decode for AndThen<D0, D1, F> where
D0: Decode,
D1: Decode,
F: Fn(D0::Item) -> D1, type Item = D1::Item;impl<D: Decode> Decode for Omit<D> type Item = Option<D::Item>;impl<D, T: Default> Decode for Collect<D, T> where
D: Decode,
T: Extend<D::Item>, type Item = T;impl<D: Decode> Decode for Length<D> type Item = D::Item;impl<D: Decode> Decode for Take<D> type Item = D::Item;impl<D, F, T, E> Decode for TryMap<D, F, T, E> where
D: Decode,
F: Fn(D::Item) -> Result<T, E>,
Error: From<E>, type Item = T;impl<D: Decode> Decode for SkipRemaining<D> type Item = D::Item;impl<D: Decode> Decode for MaxBytes<D> type Item = D::Item;impl<D: Decode, F> Decode for Assert<D, F> where
F: for<'a> Fn(&'a D::Item) -> bool, type Item = D::Item;impl Decode for U8Decoder type Item = u8;impl Decode for I8Decoder type Item = i8;impl Decode for U16beDecoder type Item = u16;impl Decode for U16leDecoder type Item = u16;impl Decode for I16beDecoder type Item = i16;impl Decode for I16leDecoder type Item = i16;impl Decode for U24beDecoder type Item = u32;impl Decode for U24leDecoder type Item = u32;impl Decode for U32beDecoder type Item = u32;impl Decode for U32leDecoder type Item = u32;impl Decode for I32beDecoder type Item = i32;impl Decode for I32leDecoder type Item = i32;impl Decode for U40beDecoder type Item = u64;impl Decode for U40leDecoder type Item = u64;impl Decode for U48beDecoder type Item = u64;impl Decode for U48leDecoder type Item = u64;impl Decode for U56beDecoder type Item = u64;impl Decode for U56leDecoder type Item = u64;impl Decode for U64beDecoder type Item = u64;impl Decode for U64leDecoder type Item = u64;impl Decode for I64beDecoder type Item = i64;impl Decode for I64leDecoder type Item = i64;impl Decode for F32beDecoder type Item = f32;impl Decode for F32leDecoder type Item = f32;impl Decode for F64beDecoder type Item = f64;impl Decode for F64leDecoder type Item = f64;impl<T> Decode for JsonDecoder<T> where
T: for<'de> Deserialize<'de>, type Item = T;impl<D: MonolithicDecode> Decode for MonolithicDecoder<D> type Item = D::Item;impl<D> Decode for DecoderChain<StartDecoderChain, D, ()> where
D: Decode, type Item = (D::Item,);impl<D0, D1, T0> Decode for DecoderChain<D0, D1, (T0,)> where
D0: Decode<Item = (T0,)>,
D1: Decode, type Item = (T0, D1::Item);impl<D0, D1, T0, T1> Decode for DecoderChain<D0, D1, (T0, T1)> where
D0: Decode<Item = (T0, T1)>,
D1: Decode, type Item = (T0, T1, D1::Item);impl<D0, D1, T0, T1, T2> Decode for DecoderChain<D0, D1, (T0, T1, T2)> where
D0: Decode<Item = (T0, T1, T2)>,
D1: Decode, type Item = (T0, T1, T2, D1::Item);impl<D0, D1, T0, T1, T2, T3> Decode for DecoderChain<D0, D1, (T0, T1, T2, T3)> where
D0: Decode<Item = (T0, T1, T2, T3)>,
D1: Decode, type Item = (T0, T1, T2, T3, D1::Item);impl<D0, D1, T0, T1, T2, T3, T4> Decode for DecoderChain<D0, D1, (T0, T1, T2, T3, T4)> where
D0: Decode<Item = (T0, T1, T2, T3, T4)>,
D1: Decode, type Item = (T0, T1, T2, T3, T4, D1::Item);impl<D0, D1, T0, T1, T2, T3, T4, T5> Decode for DecoderChain<D0, D1, (T0, T1, T2, T3, T4, T5)> where
D0: Decode<Item = (T0, T1, T2, T3, T4, T5)>,
D1: Decode, type Item = (T0, T1, T2, T3, T4, T5, D1::Item);impl<D0, D1, T0, T1, T2, T3, T4, T5, T6> Decode for DecoderChain<D0, D1, (T0, T1, T2, T3, T4, T5, T6)> where
D0: Decode<Item = (T0, T1, T2, T3, T4, T5, T6)>,
D1: Decode, type Item = (T0, T1, T2, T3, T4, T5, T6, D1::Item);impl<T> Decode for DecodedValue<T> type Item = T;