Deserialize Enum discriminant as Uint
The serializer encodes the variant of an enum as a BARE Uint, so the deserializer should do the inverse when trying to deserialize a message. Serde's serialize interface only receives variant indexes as u32, despite the compiler allowing a cast to virtually any primitive integer type.
This commit is contained in:
parent
6695663b5b
commit
cde8ea7f52
10
src/de.rs
10
src/de.rs
|
@ -516,12 +516,16 @@ where
|
||||||
visitor.visit_enum(Enum::<'a, R>(self))
|
visitor.visit_enum(Enum::<'a, R>(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Error::IdentifierUnsupported.
|
/// Deserialize the enum discriminant as a BARE Uint
|
||||||
fn deserialize_identifier<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where
|
where
|
||||||
V: de::Visitor<'de>,
|
V: de::Visitor<'de>,
|
||||||
{
|
{
|
||||||
Err(Error::IdentifierUnsupported)
|
let Uint(id) = <Uint as de::Deserialize>::deserialize(&mut *self)?;
|
||||||
|
let variant: u32 = id.try_into().map_err(|_| {
|
||||||
|
Error::Message("Enum identifiers larger than u32 are not supported".to_string())
|
||||||
|
})?;
|
||||||
|
visitor.visit_u32(variant)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Error::AnyUnsupported.
|
/// Returns Error::AnyUnsupported.
|
||||||
|
|
Loading…
Reference in New Issue