kriszyp/cbor-x

sorting

jimmywarting opened this issue · 2 comments

I'm required to be quite strict and follow this rule:
https://cbor-wg.github.io/CBORbis/draft-ietf-cbor-7049bis.html#section-4.2.1-2.3.1

if i don't then my program complains that my cbor data is invalid...

maybe related to #49 (although I am more concerned about records than plain maps, the mechanics and motivations are the same)

I think this would be best done outside of the core cbor-x encoder (like #49). Since JavaScript objects are ordered, rearranging properties is incompatible with correct preservation of object state (which is already a deterministic encoding). But, of course, if we had a separate module that created new JS objects/maps that had been explicitly re-ordered to match the "deterministic encoding" requirement of this spec (that is clearly intended for unordered maps), that would be the best way to match this.