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'))
// a16161f7
cbor.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 encoded
However @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?
I have an object with a value type that is not supported by IPLD
{ "a": undefined }.I can use
cborgto encode it:cbor.me displays this as:
So far, so good.
@ipld/dag-cborrefuses to encode the object, which seems correct:However
@ipld/dag-cbordecodes the output ofcborgjust fine though convertsundefinedtonull:I would have expected
@ipld/dag-cborto throw on decode when encountering a forbidden type instead of interpreting it as a different type?