Re: [Cbor] Map keys?

Carsten Bormann <cabo@tzi.org> Mon, 29 April 2019 14:02 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0ED831200C7 for <cbor@ietfa.amsl.com>; Mon, 29 Apr 2019 07:02:27 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.199
X-Spam-Level:
X-Spam-Status: No, score=-4.199 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tnzkujUM_4MX for <cbor@ietfa.amsl.com>; Mon, 29 Apr 2019 07:02:23 -0700 (PDT)
Received: from smtp.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de [134.102.50.17]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 123CA120329 for <cbor@ietf.org>; Mon, 29 Apr 2019 07:02:23 -0700 (PDT)
Received: from [192.168.217.106] (p54A6CC75.dip0.t-ipconnect.de [84.166.204.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.uni-bremen.de (Postfix) with ESMTPSA id 44t5vK2XLZzyTV; Mon, 29 Apr 2019 16:02:21 +0200 (CEST)
Content-Type: text/plain; charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <8269CD1C-B024-4961-A889-C8543502596A@felipegasper.com>
Date: Mon, 29 Apr 2019 16:02:20 +0200
Cc: cbor@ietf.org
X-Mao-Original-Outgoing-Id: 578239338.536196-d428c5c7a5a7c2eea61f9747bbe6914a
Content-Transfer-Encoding: quoted-printable
Message-Id: <A30D4B40-875C-4119-8BEC-E7038E22CDA5@tzi.org>
References: <8269CD1C-B024-4961-A889-C8543502596A@felipegasper.com>
To: Felipe Gasper <felipe@felipegasper.com>
X-Mailer: Apple Mail (2.3445.9.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/LyndIfQipxUfx0cu6nlOwi6ceOY>
Subject: Re: [Cbor] Map keys?
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 29 Apr 2019 14:02:27 -0000

On Apr 29, 2019, at 15:39, Felipe Gasper <felipe@felipegasper.com>; wrote:
> 
> 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. 

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.
> ——-
> 
> 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?

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