3Hren / 3Hren/msgpack-rust

Impossible to decode rmp-serde Ext type even with own trait implemented for rmp_serde::decode::Deserializer

Open
#164 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.4k
Forks
162
PR merge metrics
No merged PRs in 30d

Description

There is no way (or it would be very hacky) to read the Ext meta data from the inner `rd` reader (the `get_ref` method only exposes the internal implementation of `rd` but not the `rd` itself).

My approach was to implement my own trait for rmp_serde::decode::Deserializer like this:
```rust
impl<'de, 'a, R> MyDeserializer<'de> for &'a mut rmp_serde::decode::Deserializer
where R: rmp_serde::decode::Read<'de>
{
fn deserialize_foo>(self, visitor: V) -> Result {
self.deserialize_any(visitor).or_else(|err| {
if let rmp_serde::decode::Error::TypeMismatch(marker) = err {
let meta: ExtMeta = self.somehow_get_ext_meta()?;
// do something with meta, .e.g. call self.deserialize_any again if type matches
return Ok(value);
}
Err(err)
})
}
}
```
But, there is no way to read the ExtMeta from the internal `rd` reader of Deserializer. I think the ExtMeta could be easily returned from this place:
https://github.com/3Hren/msgpack-rust/blob/master/rmp-serde/src/decode.rs#L347
like this:
```rust
marker => {
let size = match marker {
Marker::FixExt1 => 1,
Marker::FixExt2 => 2,
Marker::FixExt4 => 4,
Marker::FixExt8 => 8,
Marker::FixExt16 => 16,
Marker::Ext8 => read_u8(&mut self.rd)? as u32,
Marker::Ext16 => read_u16(&mut self.rd)? as u32,
Marker::Ext32 => read_u32(&mut self.rd)?,
marker => return Err(Error::TypeMismatch(marker)),
};
let ty = rmp::decode::read_data_i8(&mut self.rd)?;
let meta = rmp::decode::ExtMeta {
typeid: ty,
size: size,
};
Err(Error::ExtensionFound(meta)) // Would require an ExtensionFound(ExtMeta) variant in Error enum
}
```

Adding a method to get access to the Deserializer `self.rd` would also solve the problem anyway.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.