pub struct Deserializer<'de> { /* private fields */ }Expand description
Serde MessagePack deserializer.
- deserializes data from a slice,
- deserializes borrowed references to
&strand&[u8]types, - deserializes structs from MessagePack maps or arrays.
- deserializes enum variants and struct fields from MessagePack strings or integers.
- deserializes integers from any MessagePack integer type as long as the number can be casted safely
- deserializes floats from any MessagePack integer or float types
- deserializes floats as
NaNfromnil
Implementations§
Source§impl<'de> Deserializer<'de>
Some methods in a Deserializer object are made public to allow custom
manipulation of MessagePack encoded data for other purposes than simply
deserializing.
impl<'de> Deserializer<'de>
Some methods in a Deserializer object are made public to allow custom
manipulation of MessagePack encoded data for other purposes than simply
deserializing.
For example, splitting a stream of messages encoded with the MessagePack format without fully decoding messages.
Sourcepub fn from_slice(input: &'de [u8]) -> Self
pub fn from_slice(input: &'de [u8]) -> Self
Create a new decoder instance by providing a slice from which to deserialize messages.
Sourcepub fn end(self) -> Result<usize>
pub fn end(self) -> Result<usize>
Consume Deserializer and return the number of unparsed bytes in
the input slice on success.
If the input cursor points outside the input slice, an error
Error::UnexpectedEof is returned.
Sourcepub fn remaining_len(&self) -> usize
pub fn remaining_len(&self) -> usize
Return the remaining number of unparsed bytes in the input slice.
Returns 0 when the input cursor points either at the end or beyond the end of the input slice.
Sourcepub fn peek(&self) -> Result<u8>
pub fn peek(&self) -> Result<u8>
Peek at the next byte code and return it on success, otherwise return
Err(Error::UnexpectedEof) if there are no more unparsed bytes
remaining in the input slice.
Sourcepub fn eat_some(&mut self, len: usize)
pub fn eat_some(&mut self, len: usize)
Advance the input cursor by len bytes.
Note: this function only increases a cursor without any checks!
Sourcepub fn input_ref(&self) -> Result<&[u8]>
pub fn input_ref(&self) -> Result<&[u8]>
Return a reference to the unparsed portion of the input slice on success.
If the input cursor points outside the input slice, an error
Error::UnexpectedEof is returned.
Sourcepub fn split_input(&mut self, len: usize) -> Result<&'de [u8]>
pub fn split_input(&mut self, len: usize) -> Result<&'de [u8]>
Split the unparsed portion of the input slice between 0..len and on success
return it with the lifetime of the original slice container.
The returned slice can be passed to visit_borrowed_* functions of a Visitor.
Drop already parsed bytes and the new unparsed input slice will begin at len.
Panics if cursor + len overflows usize integer capacity.
Sourcepub fn fetch(&mut self) -> Result<u8>
pub fn fetch(&mut self) -> Result<u8>
Fetch the next byte from input or return an Err::UnexpectedEof error.
Sourcepub fn eat_message(&mut self) -> Result<()>
pub fn eat_message(&mut self) -> Result<()>
Attempts to consume a single MessagePack message from the input without fully decoding its content.
Return Ok(()) on success or Err(Error::UnexpectedEof) if there was not enough data
to fully decode a MessagePack item.
Trait Implementations§
Source§impl<'de> Deserializer<'de> for &mut Deserializer<'de>
impl<'de> Deserializer<'de> for &mut Deserializer<'de>
Source§type Error = Error
type Error = Error
Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read moreSource§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a bool value.Source§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a f64 value.Source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a char value.Source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a unit value.Source§fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a unit struct with a
particular name.Source§fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a newtype struct with a
particular name.Source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a sequence of values.Source§fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a map of key-value pairs.Source§fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting a struct with a particular
name and fields.Source§fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read more