quininer / cbor4ii

CBOR: Concise Binary Object Representation
MIT License
54 stars 5 forks source link

serde-derived `Serialize`/`Deserialize` impl for `Value` is not working as expected #6

Closed bdbai closed 2 years ago

bdbai commented 2 years ago

The Value type is expected to serialize/deserialize from data it represents. For the following test code:

    fn test_deserialize_null_value() {
        let val = crate::core::Value::Null;
        let ret = crate::serde::to_vec(vec![], &val).unwrap();
        eprintln!("{:02x?}", &ret);
    }

Expected Output:

[f6]

which is the primitive value null, but

Actual Output:

[64, 4e, 75, 6c, 6c]

which is a 4-character UTF-8 text Null.

It looks like the generated implementation from the derive directives interprets Value as a externally tagged enum. Is it a mistake or a feature by design?

quininer commented 2 years ago

Ah, this is a bug. thanks for your report.

quininer commented 2 years ago

The 0.2.4 version has been released and it fixes this problem.

bdbai commented 2 years ago

@quininer thanks for your prompt fix! 0.2.4 works perfectly now.