-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
I have an object with a value type that is not supported by IPLD { "a": undefined }.
I can use cborg to encode it:
import * as cborg from 'cborg'
import * as ipldDagCbor from '@ipld/dag-cbor'
import { toString } from 'uint8arrays'
const obj = { a: undefined }
const cborgBytes = cborg.encode(obj)
console.info(toString(cborgBytes, 'hex'))
// a16161f7cbor.me displays this as:
A1 # map(1)
61 # text(1)
61 # "a"
F7 # primitive(23)
So far, so good.
@ipld/dag-cbor refuses to encode the object, which seems correct:
ipldDagCbor.encode(obj)
// Error: `undefined` is not supported by the IPLD Data Model and cannot be encodedHowever @ipld/dag-cbor decodes the output of cborg just fine though converts undefined to null:
console.info(cborg.decode(cborgBytes))
// { a: undefined }
console.info(ipldDagCbor.decode(cborgBytes))
// { a: null }I would have expected @ipld/dag-cbor to throw on decode when encountering a forbidden type instead of interpreting it as a different type?
Metadata
Metadata
Assignees
Labels
No labels