pub struct Deserializer<'a, 'de> {
inner: Deserializer<ReadReader<&'de [u8]>>,
registry: &'a TagRegistry,
}Expand description
Tagged-map msgpack deserializer.
Constructed internally by msgpack_tagged_deserialize. Exposed as pub
so it can be named from rustdoc; the only stable entry point is still the
free function. A builder for strategy customization will land later
(mirroring the serializer’s plan).
The inner reader is fixed to &'de [u8] (wrapped in rmp_serde’s
ReadReader, the shape RmpDeserializer::new constructs). We don’t
keep the reader generic because two interception paths need to grab a
snapshot of the unread byte slice — deserialize_option’s peek-via-
rewind dance and deserialize_tuple_struct’s buffer-by-tag — and
those slice tricks only work when the reader exposes the underlying
&[u8] directly. The public entry function only ever constructs the
&[u8] shape, so this isn’t a real loss of generality; if/when a
from_read variant lands, that’s a separate type.
Fields§
§inner: Deserializer<ReadReader<&'de [u8]>>§registry: &'a TagRegistryImplementations§
Source§impl<'a, 'de> Deserializer<'a, 'de>
impl<'a, 'de> Deserializer<'a, 'de>
Sourcepub fn new(bytes: &'de [u8], registry: &'a TagRegistry) -> Self
pub fn new(bytes: &'de [u8], registry: &'a TagRegistry) -> Self
Construct a deserializer over bytes borrowing the caller-built
registry. Symmetric with crate::Serializer::new.
Sourcefn read_map_len(&mut self) -> Result<usize, Error>
fn read_map_len(&mut self) -> Result<usize, Error>
Read a msgpack map header (fixmap / map16 / map32) and return
its length as usize. Thin wrapper over rmp::decode::read_map_len
that bakes in our error-formatting + the u32 → usize cast every
caller wants.
Sourcefn read_array_len(&mut self) -> Result<usize, Error>
fn read_array_len(&mut self) -> Result<usize, Error>
Read a msgpack array header (fixarray / array16 / array32)
and return its length as usize. Sibling of Self::read_map_len.
Source§impl<'a, 'de> Deserializer<'a, 'de>
impl<'a, 'de> Deserializer<'a, 'de>
Sourcefn product_for(&self, name: &'static str) -> Product
fn product_for(&self, name: &'static str) -> Product
Resolve a registered Product by serde name. Used by
deserialize_struct (and, once it lands, deserialize_tuple_struct).
Mirrors Serializer::product_for — a registry miss or sum-shaped
entry is a real bug, so we panic loudly per the design doc rather
than fabricating a synthetic shape.
Sourcefn sum_for(&self, name: &'static str) -> Sum
fn sum_for(&self, name: &'static str) -> Sum
Resolve a registered Sum by enum-type name. Mirror of product_for
on the enum side, used by deserialize_enum.
Sourcefn buffer_and_validate_int_keyed_map<'der>(
&'der mut self,
wire_len: usize,
product: &Product,
context: impl FnOnce() -> String,
) -> Result<SmallVec<[(u8, &'de [u8]); 4]>, Error>
fn buffer_and_validate_int_keyed_map<'der>( &'der mut self, wire_len: usize, product: &Product, context: impl FnOnce() -> String, ) -> Result<SmallVec<[(u8, &'de [u8]); 4]>, Error>
Read wire_len (u8 tag, value-bytes) pairs from the inner reader
and return them as a SmallVec for later tag-driven dispatch. Used
by both deserialize_tuple_struct and TaggedEnumAccess::tuple_variant
— they share the int-keyed-map wire shape for tuple-shaped payloads
but their visitors call back positionally rather than by name, so we
can’t dispatch entry-by-entry the way TaggedProductMapAccess does.
Validates tag membership against the type’s registered Product:
- Tag in
product.fields(active position) — fine. - Tag in
product.reserved(retired position) — fine, the visitor will simply never query it. - Otherwise — only fine if
product.allow_unknown_tagsis set.
Performs a cheap upfront cap check (wire_len > active + reserved)
when allow_unknown_tags is off, so grossly oversized wires error
before we walk the bytes. The per-tag scan after buffering catches
the within-bounds-but-still-unknown case.
context is a caller-supplied closure producing a label (e.g.
"tuple-struct \"Foo\"" or "tuple variant \"Carry\"") that gets
embedded in error messages. It’s a closure so the String is only
allocated on the error path — the happy path skips the format call.
Sourcefn buffer_positional_array<'der>(
&'der mut self,
wire_len: usize,
product: &Product,
context: impl FnOnce() -> String,
) -> Result<SmallVec<[(u8, &'de [u8]); 4]>, Error>
fn buffer_positional_array<'der>( &'der mut self, wire_len: usize, product: &Product, context: impl FnOnce() -> String, ) -> Result<SmallVec<[(u8, &'de [u8]); 4]>, Error>
Read wire_len positional value-bytes entries from the inner
reader (the Array-strategy wire shape — fixarray of values, no
per-entry tag) and return them as an IntKeyedEntries with the tag
for each entry synthesized from the merged-sorted (active +
reserved) tag layout. This lets the downstream
TaggedTupleStructAccess dispatch by tag uniformly across both
wire strategies; for tuple structs / tuple variants the access
reuses the same tag-driven path.
Reserved-tag handling under Array. When a V2 schema retires a
field with #[tagged(reserved(N))], the V1 wire (produced before
the retirement) still carries a value at the slot that used to
hold tag N. The merged layout tells us which wire positions
correspond to retired tags so we can drain them silently without
confusing them with the active slots that come after.
Cap check: wire_len > active_count + reserved_count is only
accepted under allow_unknown_tags. Entries beyond that arity
get consumed-and-discarded so the outer stream stays aligned, but
they’re not pushed to the returned buffer.
Sourcefn peek_wire_shape(&mut self) -> Result<WireShape, Error>
fn peek_wire_shape(&mut self) -> Result<WireShape, Error>
Peek the next msgpack marker without advancing the reader and
classify it as a Tagged-strategy map header or an Array-strategy
array header. Used at every product-shaped decode site
(deserialize_struct, deserialize_tuple_struct,
TaggedEnumAccess::tuple_variant / struct_variant) to dispatch
to the right reader.
Any other marker is a malformed-bytes error under
Format::MsgpackTagged — legacy Msgpack / MsgpackCompact data
has its own format byte and never reaches this wrapper, so
string-keyed maps and other shapes are not expected here.
Trait Implementations§
Source§impl<'a, 'de> Deserializer<'de> for &mut Deserializer<'a, 'de>
impl<'a, 'de> Deserializer<'de> for &mut Deserializer<'a, 'de>
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_any<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_bool<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_bool<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a bool value.Source§fn deserialize_i8<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_i8<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_i16<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_i32<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_i64<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_u8<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_u16<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_u32<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_u64<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_f32<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_f64<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a f64 value.Source§fn deserialize_char<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_char<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a char value.Source§fn deserialize_str<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_str<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
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: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_string<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
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: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_bytes<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
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: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_byte_buf<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
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: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_option<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_unit<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_unit<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a unit value.Source§fn deserialize_unit_struct<V: Visitor<'de>>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_unit_struct<V: Visitor<'de>>( self, name: &'static str, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a unit struct with a
particular name.Source§fn deserialize_newtype_struct<V: Visitor<'de>>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_newtype_struct<V: Visitor<'de>>( self, name: &'static str, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a newtype struct with a
particular name.Source§fn deserialize_seq<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_seq<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a sequence of values.Source§fn deserialize_tuple<V: Visitor<'de>>(
self,
len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_tuple<V: Visitor<'de>>( self, len: usize, visitor: V, ) -> Result<V::Value, Self::Error>
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: Visitor<'de>>(
self,
name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_tuple_struct<V: Visitor<'de>>( self, name: &'static str, _len: usize, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_map<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_map<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a map of key-value pairs.Source§fn deserialize_struct<V: Visitor<'de>>(
self,
name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_struct<V: Visitor<'de>>( self, name: &'static str, _fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting a struct with a particular
name and fields.Source§fn deserialize_enum<V: Visitor<'de>>(
self,
name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_enum<V: Visitor<'de>>( self, name: &'static str, _variants: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_identifier<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_identifier<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V: Visitor<'de>>(
self,
visitor: V,
) -> Result<V::Value, Self::Error>
fn deserialize_ignored_any<V: Visitor<'de>>( self, visitor: V, ) -> Result<V::Value, Self::Error>
Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read more