Skip to content

"convert to JS first, then encode" button in playground #88

@rohanmahy

Description

@rohanmahy

Option in the cbor2 playground

The sortKeys pulldown in the cbor2 playground has three options: null, coreDeterministic, lengthFirstDeterministic.

Current behavior

Regardless of the setting, the following map is encoded in the input order of its keys

{
   [1, 2, 3]: true,
   257: true,
   "a": true
}

Expected behavior

sortKeys = null: input order (as expected)

sortKeys = coreDeterministic: expected to sort the map keys in lexicographic order according to the rules of Section 4.2.1 of RFC 8949.

The output would be the same as:

   257: true,
   "a": true,
   [1, 2, 3]: true

Quoting that section:

The keys in every map MUST be sorted in the bytewise lexicographic order of their deterministic encodings. For example, the following keys are sorted correctly:

  1. 10, encoded as 0x0a.
  2. 100, encoded as 0x1864.
  3. -1, encoded as 0x20.
  4. "z", encoded as 0x617a.
  5. "aa", encoded as 0x626161.
  6. [100], encoded as 0x811864.
  7. [-1], encoded as 0x8120.
  8. false, encoded as 0xf4.

sortKeys = lengthFirstDeterministic: expected to sort the map keys in length-first, then lexicographic order of the value omitting the first 3-bit of the major as poorly described in the third bullet item of Section 3.9 of RFC7049.

The output would be the same as:

   "a": true,
   257: true,
   [1, 2, 3]: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions