bcmyers / num-format

A Rust crate for producing string representations of numbers, formatted according to international standards
Apache License 2.0
123 stars 22 forks source link

`Buffer` fails to deserialize with `serde` and binary formats #40

Open hinto-janai opened 1 year ago

hinto-janai commented 1 year ago

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.