ipld / serde_ipld_dagcbor

DAG-CBOR implementation for Serde
Other
8 stars 8 forks source link

feat: introduce no-cid-as-bytes feature #23

Closed vmx closed 7 months ago

vmx commented 7 months ago

This commit changes the default behaviour of the deserializer. It's now possible to deserialize CIDs into bytes. This is needed in order to have the Serde derives for internally tagged and untagged enums working correctly.

If you need the current behaviour of erroring at run-time in case a CID is tried to be deserialized as bytes, you can enable the no-cid-as-bytes feature.

BREAKING CHANGE: CIDs may be deserialized into bytes. In order to restore the original behaviour, enable the no-cid-as-bytes feature.

rvagg commented 7 months ago

CIDs may be deserialized into bytes

I think if you want to go with this as the default and document it like this you're going to have to demonstrate how this might happen. It's still a little bit lost on me how this will happen, is it simply that I may have a

    #[derive(Debug, Deserialize, PartialEq)]
    pub enum Boop {
        Cid(Vec<u8>),
    }

And that receives the raw bytes? It seems like users might need guidance on the subtleties here since many are not going to be as familiar with the internals of serde that may this a problem. Perhaps even some test cases for both feature on and feature off that show how this can happen.

vmx commented 7 months ago

Perhaps even some test cases for both feature on and feature off that show how this can happen.

Tests for both cases are part of this PR.