Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Cbor Tags are not unmarshalled properly #13

Closed
dignifiedquire opened this issue Nov 16, 2017 · 4 comments
Closed

Nested Cbor Tags are not unmarshalled properly #13

dignifiedquire opened this issue Nov 16, 2017 · 4 comments

Comments

@dignifiedquire
Copy link
Contributor

dignifiedquire commented Nov 16, 2017

Something strange is going on when trying to unmarshal cbor tags that are nested. Object in question can be found here: https://github.com/ipfs/go-ipld-cbor/blob/refmt/node_test.go#L124-L133

obj := map[string]interface{}{
    "foo":   "bar",
    "hello": c1,
    "baz": []interface{}{
      c1,
      c2,
    },
    "cats": map[string]interface{}{
      "qux": c3,
    },
  }

The byte code looks fine

a36362617a82d82a5823001220aed1fe98cda4ba5a1681a19aa768f73b9d707c5621c7effdf2938e242080505ed82a58230012205773487d221545d26fd0f57fdb3a7d986bc479a850d7b0d762e8c7f4772790a06463617473a163717578d82a5823001220434be0538b88f385bdb9d62de34e296a0908c857a876aec09e1f52673596d89763666f6f63626172

Diagnostic view from cbor.me

{"baz": [42(h'001220AED1FE98CDA4BA5A1681A19AA768F73B9D707C5621C7EFFDF2938E242080505E'), 42(h'0012205773487D221545D26FD0F57FDB3A7D986BC479A850D7B0D762E8C7F4772790A0')], "cats": {"qux": 42(h'001220434BE0538B88F385BDB9D62DE34E296A0908C857A876AEC09E1F52673596D897')}, "foo": "bar"}

But after unmarshalling this is what I get as json representation:

original

{"baz": [{"/":"Qma75NN8GaM99ioqsNUF9Ho816SonoGsVrvSnqz9uL4LPF"},{"/":"QmUE28rcN99es8ntD4T3sBScfyrADkF3q8qzM1gEW82oMh"}],"cats":{"qux":{"/":"QmSsM8Xm1g5WtfwkBvnttZafpDhaW6jkXeSFccECUnx7hg"}},"foo":"bar","hello":{"/":"Qma75NN8GaM99ioqsNUF9Ho816SonoGsVrvSnqz9uL4LPF"}} 

after roundtrip

{"baz":[{},{}],"cats":{"qux":{}},"foo":"bar","hello":{}}
@dignifiedquire
Copy link
Contributor Author

It works fine for top level tags, i.e. "baz": mycustomtagtype.

@warpfork
Copy link
Member

Just to give a quick update: yes, I saw the issue :) I have a couple more unit tests staged, but haven't gotten to the bottom of the problem yet. Sorry, it's been a real wild week. Trying to schedule a block of time to make sure I can knock it out tomorrow.

@warpfork
Copy link
Member

I think I made a fixture that's almost the same and that test seems to pass.

Can you spot where we've diverged? I tried to replicate your setup but admittedly without recursing to look up too many files.

@dignifiedquire
Copy link
Contributor Author

I think this can be closed, this was due to other issues, thanks for checking.

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

No branches or pull requests

2 participants