msgpack-rust: std::net::IpAddr fails to roundtrip using 0.14.1
We recently updated from 0.14.0 to 0.14.1 (and to serde version 1.0.104) and the following minimal test case
use std::net::{IpAddr, Ipv4Addr};
use rmp_serde::{from_slice, to_vec};
#[test]
fn roundtrip_ip_addr() {
let addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let addr1: IpAddr = from_slice(&to_vec(&addr).unwrap()).unwrap();
assert_eq!(addr1, addr);
}
started to fail with
Syntax("invalid type: integer `0`, expected `V4` or `V6`")'
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (8 by maintainers)
https://github.com/3Hren/msgpack-rust/pull/256 updates to the new serde and adds more tests. That should serve as a good foundation for adding new configuration for binary serialization.
Perhaps solution would be to make a newtype
Unreadable
that overridesis_human_readable
, and forwards all other methods to inner (de)serializer.and then instead of
SeqDeserializer::new()
doUnreadable(SeqDeserializer::new())
(and same forMapDeserializer
and others)In the course of looking into this, I discovered that this appears to be a bug in serde, not in msgpack-rust: https://github.com/serde-rs/serde/pull/1888
If I build msgpack-rust against a version of serde with that patch applied, the test case above passes, along with one of the existing ignored FIXME tests, and several additional tests I added. That fix also makes the tests pass with
fn is_human_readable(&self) { false }
added to the serializer and deserializer.As soon as a version of Serde with that patch is released, it should be straightforward to add new
Config
variants forHumanReadableConfig
andBinaryConfig
, which would overrideis_human_readable
.