kriszyp / cbor-x

Ultra-fast CBOR encoder/decoder with extensions for records and structural cloning
MIT License
275 stars 32 forks source link

better structured clone support #50

Open jimmywarting opened 2 years ago

jimmywarting commented 2 years ago

I just publish this test page today to test out different binary package

Maybe this is something you wish to improve on? (you can also click on each ❌ to see more details - and see the result in the console for more detail)

A summary of what i think should be supported

I don't know about Blob/Files. I think it would be better to just encode a references point to some blob index rather than trying encode a hole file into memory. So first you would encode the structure, emit all the data and then transfer/pipe the blobs over the wire later in your own way. kind of how the web has a transferable list when using postMessage

jimmywarting commented 2 years ago

before you jump onto the conclusion of why -0 should be supported:

Code can do different things depending on if it's signed or not.

Math.atan2(0, 0);  //returns 0
Math.atan2(0, -0); //returns Pi

the reason why we have +0 and -0 is mostly due to being able to represent positive and negative ∞ in a mathematically way

kriszyp commented 2 years ago

This is really cool, nice work! Yes, I will take a look to see if there are some improvements that can be made, when I get a chance, although no guarantees, since there may be some limitations from data formats. Again, this is a great analysis and set of tests!

jimmywarting commented 1 year ago

I added the mapsAsObjects: true and then it passed more tests... I update my post to include a list of what i think should be supported. That way you can create sub issues and use this a meta ticket if you like.

jimmywarting commented 1 year ago

I think Object literals could just be as simple as just prefixing the next following value... You don't need a seperate Tags for each String/Boolean/Number/BigInt etc?

var isObjectLiteral = buffer[x]
if (isObjectLiteral) {
  return Object( read_next_value_as_normal() )
}