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

Emile Cormier <emile.cormier.jr@gmail.com> Thu, 02 December 2021 00:02 UTC

Return-Path: <emile.cormier.jr@gmail.com>
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 A13093A0D17 for <cbor@ietfa.amsl.com>; Wed, 1 Dec 2021 16:02:52 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.097
X-Spam-Level:
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: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 EQ5u-MB2qd5t for <cbor@ietfa.amsl.com>; Wed, 1 Dec 2021 16:02:47 -0800 (PST)
Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 3B7C43A0D09 for <cbor@ietf.org>; Wed, 1 Dec 2021 16:02:47 -0800 (PST)
Received: by mail-yb1-xb2f.google.com with SMTP id q74so68309470ybq.11 for <cbor@ietf.org>; Wed, 01 Dec 2021 16:02:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; 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; d=1e100.net; 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: <CAM70yxC_6JnG+CbumDs+-maOcMYyRZXAD1QJgXJQsG2tYFVVdQ@mail.gmail.com>
In-Reply-To: <CAM70yxC_6JnG+CbumDs+-maOcMYyRZXAD1QJgXJQsG2tYFVVdQ@mail.gmail.com>
From: Emile Cormier <emile.cormier.jr@gmail.com>
Date: Wed, 1 Dec 2021 20:02:34 -0400
Message-ID: <CAM70yxCznYR4BtNxrpe6can6Y57A+3EAjkjkQBmKNDY6XXAL=A@mail.gmail.com>
To: Carsten Bormann <cabo@tzi.org>, cbor@ietf.org
Content-Type: multipart/alternative; boundary="0000000000009299d405d21e82e3"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/cWXAsKzxaFWF9oUGnPOLQPEYcwQ>
Subject: Re: [Cbor] CBOR tag proposal for enumerated alternatives (tagged unions)
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: 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).

Cheers,
Emile Cormier

On Wed, Apr 7, 2021 at 6:37 PM Emile Cormier <emile.cormier.jr@gmail.com>
wrote:

> On Wed, Mar 31, 2021 at 9:38 AM Carsten Bormann <cabo@tzi.org> wrote:
>
>> I’m not sure we discussed this one yet in detail:
>>
>>
>> https://docs.google.com/document/d/16aiDEBhJj3kipj_7PVppEhxAr5E6QhQreN61eCxvBjU/edit#
>>
>> 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
>