Re: [Cbor] correctness of implied top level array?

Carsten Bormann <> Thu, 28 February 2019 20:47 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id 1948F130FD3 for <>; Thu, 28 Feb 2019 12:47:04 -0800 (PST)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -4.199
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 ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id b7oZlZlTvUrg for <>; Thu, 28 Feb 2019 12:47:01 -0800 (PST)
Received: from ( [IPv6:2001:638:708:30c9::12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 7BD82130FCE for <>; Thu, 28 Feb 2019 12:47:01 -0800 (PST)
X-Virus-Scanned: amavisd-new at
Received: from ( []) by (8.14.5/8.14.5) with ESMTP id x1SKkqDf016670; Thu, 28 Feb 2019 21:46:57 +0100 (CET)
Received: from [] ( []) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPSA id 449Pjm0Gh1z1Bp8; Thu, 28 Feb 2019 21:46:51 +0100 (CET)
Content-Type: text/plain; charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\))
From: Carsten Bormann <>
In-Reply-To: <>
Date: Thu, 28 Feb 2019 21:46:50 +0100
Cc: Michael Richardson <>,, Laurence Lundblade <>
X-Mao-Original-Outgoing-Id: 573079608.596424-c4a42901768017ceaa3bdb1f72f67783
Content-Transfer-Encoding: quoted-printable
Message-Id: <>
References: <> <> <> <> <> <9644.1551315204@localhost> <>
To: Joe Hildebrand <>
X-Mailer: Apple Mail (2.3445.9.1)
Archived-At: <>
Subject: Re: [Cbor] correctness of implied top level array?
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-Subscribe: <>, <>
X-List-Received-Date: Thu, 28 Feb 2019 20:47:04 -0000

> On Feb 28, 2019, at 20:23, Joe Hildebrand <> wrote:
>> On Feb 27, 2019, at 5:53 PM, Michael Richardson <> wrote:
>> An alternative way to do the desired action (and bring this inside of cbor)
>> would be an (indefinite?) array type that was specified to concatenate.
>> I'm not really arguing for this, but I think it's worth knowing why this
>> would be less good a thing.
> It's an interesting idea.  One of the reasons this didn't feel right to me was that my initial take on indefinite-length arrays was to read the whole array, growing memory as needed.  I've moved on from that, but would expect others to find themselves in a similar spot.
> More interestingly though, there are times when I might want to use an optional external length-framing approach, like embedding a single CBOR data item in a WebSocket message.

It is hard for a format like CBOR to take in external length information — data items need to be self-delimiting *within* the tree, so taking in that information at the top level would mean that a different encoding would be needed there.

CBOR sequences are actually exactly that, for the specific case of a top-level array.
So this is your “array type that was specified to concatenate” — except that this cannot be used within a CBOR data item ([[1, 2], [3, 4]] ≠ [[1, 2, 3, 4]]), only right on top.

Whether a single data item or a CBOR sequence is expected is indicated by meta information, such as the Content-Type.  We could define more things like CBOR maps, CBOR strings (hey, we already have ct 0 for text and 42 for bytes).  This is becoming complicated quickly.

CBOR sequences stand out because they are often exactly what is needed for streaming, and for flexible storage of partial streams in containers that can then simply be concatenated.

Next stop: Getting a CDDL spec to define top-level sequences…  (Right now, we simply describe a top-level array and add English-language information that this is to be encoded as a sequence.  Quite similar to how .cborseq works inside the spec.)

Grüße, Carsten