Subject: [Cbor] Map keys?

From: Felipe Gasper <[email-masked]>
Date: Mon, 29 Apr 2019 09:39:10 -0400

Hello,

I’m looking at RFC 8392, which says:

——-
In JSON, maps are called objects and only have one kind of map key: a string. CBOR uses strings, negative integers, and unsigned integers as map keys. The integers are used for compactness of encoding and easy comparison. The inclusion of strings allows for an additional range of short encoded values to be used.
——-

While this doesn’t directly say per se that CBOR _only_ uses strings and integers as map keys, the implication seems strong. I don’t see any such limitation in the CBOR RFC.

Does CBOR intend, then, to restrict map keys to only major types 0, 1, and 3?

Thank you!

-Felipe

---

From: Laurence Lundblade <[email-masked]>
Date: Mon, 29 Apr 2019 06:58:57 -0700

Hi Felipe,

There is no restriction on map keys in CBOR.

But maybe there should be a CBOR protocol design guideline that strongly recommends this. Seems to me that the complexity of implementation of a generic decoder that handles keys that are maps and labels is pretty high. We already have trouble with equivalence and sorting of map keys with just the strings and integers, seems like a protocol using arrays and maps would make that much worse. 

It also seems like a very unusual thing to do and beyond what other protocols and languages do.

I chose to make my C implementation of CBOR <https://github.com/laurencelundblade/QCBOR> have built-in support for keys that are integer or strings, but not arrays or maps. (You can put it in a mode where it will handle any type of key, but you lose most of the the built-in support for maps, because they are just treated like arrays). 

With such a recommendation we’d probably consider the inclusion of binary strings and floating point numbers as keys. 

LL

> On Apr 29, 2019, at 6:39 AM, Felipe Gasper <[email-masked]> wrote:
> 
> Hello,
> 
> _______________________________________________
> CBOR mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/cbor

---

From: Carsten Bormann <[email-masked]>
Date: Mon, 29 Apr 2019 16:02:20 +0200

On Apr 29, 2019, at 15:39, Felipe Gasper <[email-masked]> wrote:
> In JSON, maps are called objects and only have one kind of map key: a string. CBOR uses strings, negative integers, and unsigned integers as map keys. 

Well, it doesn’t say “and nothing else” :-)
RFC 8392 is not intended to update RFC 7049, anyway.

> The integers are used for compactness of encoding and easy comparison. The inclusion of strings allows for an additional range of short encoded values to be used.
> ——-
> 

There is no such intention.

Indeed, major types 0/1 and 3 are the most often used map keys (probably followed by 2).  But there is nothing wrong with 7 (false, true, …), 6 (tagged data), or the containers (4, 5) etc. as map keys.

This may be elucidated a bit more by draft-ietf-cbor-cddl-08.txt (in RFC editor queue), section 2, which distinguishes two kinds of map usage: “structs” (where indeed 0/1 and 3 are usually most convenient), and “tables”, where the ability to use any CBOR data item as a map key is vital.

Grüße, Carsten

---

From: Jim Schaad <[email-masked]>
Date: Mon, 29 Apr 2019 08:49:04 -0700

Please file an errata on this.  The text should be “In JSON,…  CWT uses strings,…”  The document is talking about what CWT uses for keys and not what CBOR is using for keys.

Jim

From: CBOR <[email-masked]> On Behalf Of Felipe Gasper
Sent: Monday, April 29, 2019 6:39 AM
To: [email-masked]
Subject: [Cbor] Map keys?

Hello,

——-

 
 
Thank you!
 
-Felipe

---

From: Felipe Gasper <[email-masked]>
Date: Mon, 29 Apr 2019 11:56:24 -0400

Done.

-FG

> On Apr 29, 2019, at 11:49 AM, Jim Schaad <[email-masked]> wrote:
>