Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Incorrect behavior for Option<()> #185

Open
syntacticsugarglider opened this issue Mar 25, 2020 · 0 comments
Open

Incorrect behavior for Option<()> #185

syntacticsugarglider opened this issue Mar 25, 2020 · 0 comments

Comments

@syntacticsugarglider
Copy link

assert_eq!(
        Some(()),
        serde_cbor::from_slice::<Option<()>>(serde_cbor::to_vec(&Some(())).unwrap().as_slice()).unwrap()
);

fails, as serialize_unit is implemented by simply calling serialize_none and serialize_some does not prepend a determinant (per CBOR specification). This leads to this incorrect behavior where a type implementing Serialize + Deserialize is not correctly isomorphic to its wire representation. I'm not fully familiar with the CBOR spec but presumably one could choose to serialize an empty tuple or other sequential structure or maybe a single-variant enum to represent the unit type. This is distinct to the failure to round-trip observed in #5 as the fundamental cause here is the use of 0xF6 as a marker value for both None and () leading to None::<()> and Some(()) having the same representation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant