ipld / serde_ipld_dagjson

IPLD DAG-JSON support for Serde.
Apache License 2.0
3 stars 2 forks source link

Deserialize doesn't follow IPLD specification (decode NULL type) #10

Closed wellcaffeinated closed 3 months ago

wellcaffeinated commented 4 months ago

Hey there, I ran into a problem using this with IPLD maps that contain a null field. Here's a test:

use ipld_core::codec::Codec;
use libipld::ipld;
use serde_ipld_dagjson::codec::DagJsonCodec;

#[test]
fn test_roundtrip_null(){
    let test = ipld!({
      "test": null
    });
    let s = DagJsonCodec::encode_to_vec(&test).unwrap();
    let decoded: Ipld = DagJsonCodec::decode_from_slice(&s).unwrap();
    assert_eq!(test, decoded);
}

Here's what the result is:

called Result::unwrap() on an Err value: Decode(Message("invalid type: null, expected any valid IPLD kind at line 1 column 12"))

vmx commented 4 months ago

Thanks for the test case. If I add the test to tests/codec.rs (it already has all the imports) it passes for me. If you can push some branch somewhere which reproduces that issue, then I could have a look.

wellcaffeinated commented 3 months ago

Aha. The key is that I'm using the Ipld struct in libipld rather than ipld_core.

If you try it with:

use libipld::{ipld, Ipld};
...

...it should fail.

I'm not sure why that would be... and I'm also a bit confused as to why there are two different crates for this. Is there one I should be using over the other?

vmx commented 3 months ago

Is there one I should be using over the other?

Yes, ipld-core should be used now. libipld will be deprecated soon. My plan is to get in touch with folks using libipld and help with migration, before it's actually deprecated.

wellcaffeinated commented 3 months ago

ah. Ok thanks for the clarification. Maybe the teams could add a note in the readme about this for newcomers.

I'll close this issue. Thanks!