Re: [Cbor] A CBOR tag for alternatives/unions, request for comments

Michael Peyton Jones <michael.peyton-jones@iohk.io> Wed, 23 February 2022 15:55 UTC

Return-Path: <michael.peyton-jones@iohk.io>
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 70FA43A110C for <cbor@ietfa.amsl.com>; Wed, 23 Feb 2022 07:55:21 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.088
X-Spam-Level:
X-Spam-Status: No, score=-2.088 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, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_REMOTE_IMAGE=0.01, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=iohk.io
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 CYMbZgFJDSW9 for <cbor@ietfa.amsl.com>; Wed, 23 Feb 2022 07:55:16 -0800 (PST)
Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 6BB4F3A1106 for <cbor@ietf.org>; Wed, 23 Feb 2022 07:55:16 -0800 (PST)
Received: by mail-wr1-x42e.google.com with SMTP id v21so5092326wrv.5 for <cbor@ietf.org>; Wed, 23 Feb 2022 07:55:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iohk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=byTao5+uE8uCn+KxGGijC1i+BKbPecku6hlVrJn0aTU=; b=sTOJEuOe3KfM1AScuFYkyAC6yc9cXrHz2iib4gU6Oo0SlPeVMr9KCyKj4iG7SIoQAW lxZk+zwzPXU1oJUnqEXE36IcMFpYCTonpymKFo14vu+bWUSVOwLljOoxnkIodhmVmyZN 6/Xp5Dar5sox6UvC+tVqWYQGjqPOjniBQ8Ma881zcv90QmD0XHmlJByGfuzeCbQohgtm 6Ewn4gi2MD37M3CgU2Ry+c9dyQg3+zL2Q99OSy8N8V927owFiWQRm33noBgmyV/zpp0a 0lcDkI1KaVB73RS9LQjdmuJa1zVALywK+GYJe9wy3nGACqElP8zAgA/wMJRnePMlbUZR Erjg==
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:cc; bh=byTao5+uE8uCn+KxGGijC1i+BKbPecku6hlVrJn0aTU=; b=jzOUJKpY93V/+/ZOTeppvGXYUTjmUFkDdJI28DOclMZSS4JjTf/npP/dg4BUcyw/PH KQwFonx0MuBi02YE2s1F/IbtLOGrkC6p6uWcbYZJwd3/G8ppsiytK2oaClmJStu1yQar +rciS+7dMQnzU8GJD48pLGkhEEpYgefF1tkAjh3RPrAPlr19YbKi336avhv1fAy7sd/U 2r6u75ZIuf4C0NCxGwb7iEzWEciPeofB9pT+MmU6iiqU2t2kVAupoEMWJ4fLhynlRW4J OYQgjBGSECoNBUCOucm0pfG73RmGRZCLTr/aHELF0RTD33ilYlIijWla+8nVTuWDgMd/ 2O5A==
X-Gm-Message-State: AOAM531UmriAOhvqSaD704WwqIn0Yl4x+rX0psoXn+Yc3AjaDmMjKFN3 fnkcs+NFEscgNkXrHGXKA+Bfac7D9BIKQCj+UvuT4Q==
X-Google-Smtp-Source: ABdhPJxWP91UF2/lmjCNHXofAkdhDZJ8S/Ipy5HSbXUakjGn3HQLiWaLnXCw9zpE2CG+W4mVnTINtf7P7ZQwpbP5nKA=
X-Received: by 2002:adf:f804:0:b0:1ed:c0b4:c597 with SMTP id s4-20020adff804000000b001edc0b4c597mr228794wrp.66.1645631714244; Wed, 23 Feb 2022 07:55:14 -0800 (PST)
MIME-Version: 1.0
References: <9300a81abc33a45a9f3c7c1c62da88908280e54a.camel@well-typed.com> <1D3EF118-0223-43BC-81B2-369D4515DB21@tzi.org> <1ce2c092d3214d5fdce59435fc10b084c1ba48ca.camel@well-typed.com> <DFCBE61C-35B2-42A2-8D1A-A633CF939154@tzi.org> <2e10456c5791a422bf7218e7b84051f2b7121b66.camel@well-typed.com> <CAKoRMYGcwrhVWd-J3dX75WZfc+T_oyb6NCUNaeCXMW5_-VYdTw@mail.gmail.com> <52EDB93C-827A-465F-B644-51B3EF590D06@tzi.org> <C9D895BB-40E6-431F-958F-AC031DE4FB58@tzi.org> <CAKoRMYG9X0JF4ehkMc30_UNi0JtT2YMeG4RgxznS6O3Di6pkRA@mail.gmail.com> <CAKoRMYHwewaYxkX=CsfETBbdV7c9U97jfbd9xg=PyrMX5vJhnA@mail.gmail.com> <3B3B7EF0-152B-4015-8485-B204F7AEFFBC@tzi.org> <CAKoRMYFbEG=TkuZPPOiXv2DjEh23Ujd_Q44kQqiWPGc_0GMTuQ@mail.gmail.com> <CAKoRMYHnF6fGJp1dTrJnRHFTBOhreLRwzR_=cCckW1nBXOEz0A@mail.gmail.com> <E8A9E016-2248-4BB9-9864-C6C7D52A4AE5@tzi.org> <CAKoRMYE+gmWyCL9zYDa-O-c3KV_iuzgYuS+Q4fi=U7VHDNDtkQ@mail.gmail.com> <CAKoRMYFdAr1YY3mtmY0NU5X9Bk8_4WYh7bC0CtXpZc3toLSu8g@mail.gmail.com> <7FA54553-5421-4C45-B7DD-E9B2D379F46F@tzi.org> <CAKoRMYH3MTMi_tX5KHF-O-DTKzopiGqe3fi6XjkPaGCM4823OQ@mail.gmail.com> <7dfd62ccb6c089af90c90f26a8945f23232ecbc1.camel@well-typed.com> <CAKoRMYEOo1Gqfc4W4k3NOLKpFa97Q9YzLCm3r0PJ13V2HJPf3A@mail.gmail.com> <2BBF6463-FDB2-4A8A-B20D-7A1AD976A90D@tzi.org> <CAKoRMYFi8uo2GfHA9s1n+-rMO8Ja9=2qMMzjS9Z=F9r3LFozRQ@mail.gmail.com> <8EA89504-C176-4850-9BB8-C7E7206374FF@tzi.org> <CAKoRMYGmOa0hzEFsJh8kpz0bU5x56Yc9P=DBK-ghU83gXxPv7A@mail.gmail.com> <CAKoRMYGUvmxufQUVyvX2mciq5LCmV0Nz-uE2MJn54GDBB+9DRw@mail.gmail.com> <CAKoRMYF_19V6mu4S9GVqfiNzyQVvvOzX6eYwHp_DtZQoG0xTKg@mail.gmail.com> <4B47F4D7-ADE3-4A22-8A5B-97F4E5FCD933@tzi.org> <CAM70yxACa4ZgOojHLMRv+9Bpuv7dPFtupm+tnrnDZC_i_Dsr8g@mail.gmail.com> <EB822234-89C2-4CFA-8807-2BD2E97D1E60@tzi.org> <CAM70yxAG_rMc8ANWgFvyAao_G5cLNOEL0mrfD8tLmJVxtn_8SA@mail.gmail.com>
In-Reply-To: <CAM70yxAG_rMc8ANWgFvyAao_G5cLNOEL0mrfD8tLmJVxtn_8SA@mail.gmail.com>
From: Michael Peyton Jones <michael.peyton-jones@iohk.io>
Date: Wed, 23 Feb 2022 15:55:02 +0000
Message-ID: <CAKoRMYEarGwqVZcUX0PskLyJUtRNHRUSJ0zGjNTrwGUwkXFrFQ@mail.gmail.com>
To: Emile Cormier <emile.cormier.jr@gmail.com>
Cc: Carsten Bormann <cabo@tzi.org>, Duncan Coutts <duncan@well-typed.com>, cbor@ietf.org, Jared Corduan <jared.corduan@iohk.io>, Alexander Byaly <alexander.byaly@iohk.io>
Content-Type: multipart/alternative; boundary="000000000000c24de405d8b17dae"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/C_yo1YLhRxZHousTZFwaLMOcMO4>
X-Mailman-Approved-At: Wed, 23 Feb 2022 08:11:45 -0800
Subject: Re: [Cbor] A CBOR tag for alternatives/unions, request for comments
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: Wed, 23 Feb 2022 15:57:07 -0000

I do think we would prefer to keep the overlapping encoding. Many other
kinds of CBOR encodings have redundancy, starting right from the basics
with the encoding of numbers.

We believe that not only is this approach consistent, but it's actually
helpful: it allows users to decide whether they care more about flexibility
or regularity. If you want, you *can* just encode everything with the long
form and not worry about the compact form. This simplicity is sometimes
helpful.

Of course, we can (and should) require that the canonical version be the
most compact.

Best wishes,
Michael

On Wed, 23 Feb 2022 at 15:06, Emile Cormier <emile.cormier.jr@gmail.com>
wrote:

> On Wed, Feb 23, 2022 at 10:48 AM Carsten Bormann <cabo@tzi.org> wrote:
>
>> I’m not currently proposing to standardize this, but the cbor diagnostic
>> tools support a transform to tunnel CBOR data items through JSON [0]:
>>
>> $ echo "122(h'1234')" | diag2cbor.rb | cbor2json.rb -j
>> {
>>   "@@!t122": {
>>     "@@!b": "EjQ"
>>   }
>> }
>>
>> This works by hijacking JSON object keys starting with @@!; I’m not sure
>> the code handles all cases so we have achieved full transparency yet, but
>> that is a SMOP [1].
>>
>> Grüße, Carsten
>>
>> [0]:
>> https://github.com/cabo/cbor-diag/blob/master/lib/cbor-transform-j.rb
>> [1]: SMOP = Small matter of programming
>>
>
> I was thinking something as simple as:
>
> [<alt_index>, <value>]
>
> where <alt_index> is a JSON number and <value> is the datum transcoded to
> JSON. However, transcoding this back to CBOR would be lossy without any
> other context.
>


-- 

*Michael Peyton Jones*
Software Engineering Lead | London, UK

Website: www.iohk.io <http://iohk.io>
Skype: michael.s.pj
Twitter: @mpeytonjones
PGP Key ID: 29F64616

[image: Input Output] <http://iohk.io>

[image: Twitter] <https://twitter.com/InputOutputHK> [image: Github]
<https://github.com/input-output-hk> [image: LinkedIn]
<https://www.linkedin.com/company/input-output-global>


This e-mail and any file transmitted with it are confidential and intended
solely for the use of the recipient(s) to whom it is addressed.
Dissemination, distribution, and/or copying of the transmission by anyone
other than the intended recipient(s) is prohibited. If you have received
this transmission in error please notify IOHK immediately and delete it
from your system. E-mail transmissions cannot be guaranteed to be secure or
error free. We do not accept liability for any loss, damage, or error
arising from this transmission