Re: [Cbor] CBOR tag proposal for enumerated alternatives (tagged unions)

Emile Cormier <> Thu, 02 December 2021 00:02 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id A13093A0D17 for <>; Wed, 1 Dec 2021 16:02:52 -0800 (PST)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -2.097
X-Spam-Status: No, score=-2.097 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: (amavisd-new); dkim=pass (2048-bit key)
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id EQ5u-MB2qd5t for <>; Wed, 1 Dec 2021 16:02:47 -0800 (PST)
Received: from ( [IPv6:2607:f8b0:4864:20::b2f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 3B7C43A0D09 for <>; Wed, 1 Dec 2021 16:02:47 -0800 (PST)
Received: by with SMTP id q74so68309470ybq.11 for <>; Wed, 01 Dec 2021 16:02:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=MgTPq0czc5m0UnDwq+hi//LTC2Tf6uYq8lKsTVvVVTw=; b=AcYMZa2ihzLWgJISRXBh8FiTSFZfy9/B5HUMwBLvtMNcva/RiEmUVWlaRoluKfpyH0 bMbvtAbHDbud+mnV6PcbuOLRw0RZIaProa1f4AVhMUVZ1yLcrtoK/xmh1FHtx+129yE+ khEo9cYsMFiGukwBf/aIYouRyxYUiawzP6TZ+zrEqy+jrPG5owgL6Jz/6efYwVGS36xk HEo3hhtgs1j0iTbWpNiQst6TSbvfM6cxmfmFIgmoyRwrsN0VEpMZ0YIUmAOQ8v/PXFck rq4nhsIejgDWXQmLfl6hKwYDIoPKl7XCw1/9lCG8TV/+AkAWxuBXsbC4zcmb/RCCH15m nhrg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=MgTPq0czc5m0UnDwq+hi//LTC2Tf6uYq8lKsTVvVVTw=; b=wgeJOl7L8wO0iHxGro9I2n3JnPU8PlglqERQf3J2l0fgWLHGXXv5xr5J7EQjaPR6Xd 1bAYw5OCpKtAiIAZnvxiCO9T+D3cCOiDeKxDWMzBJBJWX502/St4g1gI3++l4s7gCzxT eWG1dqsaHuwTdDKxJf6yjbIu7ud1kWWWQVu3ndiFbsEAA3JyHZmctg69Ks3FD+hU9A7q pGwo7tFGZOgehj7pXgbrQE22ZGd3W/T7qiIaE5YUqSRr366c0RNPufstg+qWySRoS5ek BXkbxtQ6AS5BLNS1hZijTtFf3RZHDtsr6cckdBI2ojRET0eQmMFgJf9oPZ0o1frarCpv 6AqQ==
X-Gm-Message-State: AOAM533YzrPq6izRr2J1db89OZk4Fy+T+Uifa22xahUlsl2tUB1fCQ9o eb2X9eVCuPEvpm+Ib1L/+xlm7vZkfmoSCDO1uoo=
X-Google-Smtp-Source: ABdhPJyil1w7Gsc/q7xl/MIDibV0ANeISJT9xn99oUDx5JYXAJ3XiGozbaXZ1dwfkhrdW33ZDSsrtDqGZSVd4Rvi60g=
X-Received: by 2002:a25:bfca:: with SMTP id q10mr10689134ybm.68.1638403365049; Wed, 01 Dec 2021 16:02:45 -0800 (PST)
MIME-Version: 1.0
References: <>
In-Reply-To: <>
From: Emile Cormier <>
Date: Wed, 1 Dec 2021 20:02:34 -0400
Message-ID: <>
To: Carsten Bormann <>,
Content-Type: multipart/alternative; boundary="0000000000009299d405d21e82e3"
Archived-At: <>
Subject: Re: [Cbor] CBOR tag proposal for enumerated alternatives (tagged unions)
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, 02 Dec 2021 00:02:53 -0000

I don't know where we are with this proposal, but I'd like to point that it
suffers from the same problem I've mentioned recently for bignum and
records: too much information is embedded in the tag, which results in the
data items being unusable when transcoded to JSON (or when a CBOR decoder
discards the tags).

Emile Cormier

On Wed, Apr 7, 2021 at 6:37 PM Emile Cormier <>

> On Wed, Mar 31, 2021 at 9:38 AM Carsten Bormann <> wrote:
>> I’m not sure we discussed this one yet in detail:
>> This is a (cbor-tags) registration request, so the WG does not have to
>> have an opinion, but the designated expert would be interested in it
>> nonetheless.
>> (I’m personally pretty convinced of the use case; this is more of an
>> issue of keeping tabs on available tag numbers and looking out for related
>> use cases.)
> As I had mentioned in the interim meeting, a related use case is
> optional<T> (aka Nullable<T>). The meeting host (Christian?) was
> questioning whether separate tags would be more appropriate to represent
> the optional<T> semantic.
> It would indeed be possible for the enumerated alternatives tags to be
> used for representing an optional<T>. For instance, alternative 0 would
> represent the "no value" state, followed by a null data item (0xF6),
> whereas alternative 1 would represent the "has value" state followed by the
> actual value. However, this is just an arbitrary convention and the
> enumerated alternatives tags used in this fashion don't explicitly express
> the "optional" semantic (it has to be assumed by the application). I
> therefore agree that separate tags would be preferable for the optional<T>
> use case.
> I communicated with one of the co-authors of the enumerated alternatives
> proposal about the possibility of including extra tags for the optional<T>
> use case. They declined, not wanting to expand the scope of their proposal,
> which is perfectly understandable.
> My idea of tags for representing optional<T> might be overkill. One can
> simply encode an optional value as either null (0xF6) or the actual value.
> A contrived example where this would not work is encoding
> optional<null_type> (i.e. "optional null").
> Anyway, the idea of tags for optional values is out there for the
> designated expert to consider. I cannot say if it's an idea actually worth
> pursuing. I don't currently need them for encoding/decoding
> std::optional<T> in my C++ work (I just check for null when deserializing
> an optional value). However, I could definitely make use of the enumerated
> alternatives tags for encoding/decoding std::variant<T0, T1, T2...>,
> especially when the alternative types are ambiguous once converted to CBOR.
> Cheers,
> Emile Cormier