num-format
num-format copied to clipboard
`Buffer` fails to deserialize with `serde` and binary formats
The Buffer
type will always fail to deserialize when using it with serde
and binary formats, the ones I've tested:
To reproduce (num-format v0.4.4
+ bincode v1.3.3
):
fn main() {
// Create an empty `Buffer`.
let mut buf = num_format::Buffer::new();
// Serialize to bytes.
let ser: Vec<u8> = bincode::serialize(&buf).unwrap();
// Attempt to deserialize. This panics.
let de: num_format::Buffer = bincode::deserialize(&ser).unwrap();
}
Error message:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom("invalid type: byte array, expected bytes of maximum length 191")', src/main.rs:7:70
Culprit code is most likely here.
Regular formats (JSON
, TOML
, etc) will (de)serialize correctly, so I believe it has something to do with the binary formats and the custom serde
implementation on Buffer
.