-
Notifications
You must be signed in to change notification settings - Fork 34
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
Cannot read properties of undefined (reading 'get') on referenceMap.get(id) #89
Comments
Here is another version that fails: import * as cbor from 'cbor-x'
const encoder = new cbor.Encoder({
structuredClone: true,
pack: true,
mapsAsObjects: true
})
const f = {}
const res = [...encoder.encodeAsIterable({
arr: Array(2).fill({}),
// baz: new Blob(['ss'])
})]
const u8 = new Uint8Array(await new Blob(res).arrayBuffer())
console.log(u8)
console.log(encoder.decode(u8)) |
Yes, this is a bug; or perhaps I should say that there simply is no support/implementation for structuredClone for encodeAsIterable yet. |
Can you explain what the problem is, why there is no support or what needs to be fixed? |
Sure, the standard encode function works by inserting all the ids necessary for marking and referencing linked objects (in your case the first object has to be marked so the second object can reference it). |
Hmm. Do you know what this reference talk reminds me of? trying to mimic browsers structural clone alg. and also of how node:v8 (de)serialize works like. import v8 from 'node:v8'
const a = Array(2).fill({})
const ab = new ArrayBuffer(16)
const b = new Uint8Array(ab)
const c = new Uint16Array(ab)
const d = new Uint32Array(32)
const value = { a, b, c, d }
const buf = v8.serialize(value)
const deserialized = v8.deserialize(buf)
console.assert(deserialized.a[0] === deserialized.a[1])
console.assert(deserialized.b.buffer === deserialized.c.buffer)
console.assert(deserialized.b.buffer !== deserialized.d.buffer) I think i would like to treat any ArrayBufferView as something more like a generic-object. Two different type of TypedArrays can both references the same underlying ArrayBuffer. (like So i would actually like to have TypedArrays to be encoded more like: |
Do you know what's wrong with this code?
is this a bug or a misstake on my side?
if i set structuredClone to false, then it works alright...
The text was updated successfully, but these errors were encountered: