Integer is not parsed as float in untagged enum
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 162
- PR merge metrics
- No merged PRs in 30d
Description
Thanks to https://github.com/3Hren/msgpack-rust/pull/204, it is possible to parse integers as floats. However, this does not seem to work if the parsed type is nested inside an untagged enum.
For this MessagePack data:
`{b'heartbeat-interval': 1}`
and this code:
```rust
use serde::{Deserialize};
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct MessageFloat {
pub heartbeat_interval: f64,
}
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct MessageInt {
pub heartbeat_interval: u64,
}
#[derive(Deserialize)]
#[serde(untagged)]
pub enum MessageWrapper {
Message(T),
}
fn main() {
let data = std::fs::read("data.bin").unwrap();
// parsing message is fine if the type is exact
let msg: MessageInt = rmp_serde::from_slice(&data).unwrap();
// parsing message is fine if the type is not exact
let msg: MessageFloat = rmp_serde::from_slice(&data).unwrap();
// parsing nested message is fine if the type is exact
let msg: MessageWrapper = rmp_serde::from_slice(&data).unwrap();
// parsing nested message fails if the type is not exact
let msg: MessageWrapper = rmp_serde::from_slice(&data).unwrap();
}
```
all parses work except the last one.
If you consider this to be a bug, let me know if I can help fixing this (point me to some API/file where I could start).
I have prepared a reproduction repository here:
https://github.com/Kobzol/msgpack-nested-float-int
The msgpack binary is in the root of the repository (`data.bin`).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.