[Cbor] Co-occurrence constraints (Re: CDDL optionality and choices and optionality in CBOR and CDDL)

Carsten Bormann <cabo@tzi.org> Sat, 13 April 2024 06:10 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 DF41BC14F6F1 for <cbor@ietfa.amsl.com>; Fri, 12 Apr 2024 23:10:26 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.896
X-Spam-Level:
X-Spam-Status: No, score=-1.896 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f5SX8xnPP4xt for <cbor@ietfa.amsl.com>; Fri, 12 Apr 2024 23:10:23 -0700 (PDT)
Received: from smtp.zfn.uni-bremen.de (smtp.zfn.uni-bremen.de [134.102.50.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 02CE0C14F68B for <cbor@ietf.org>; Fri, 12 Apr 2024 23:10:21 -0700 (PDT)
Received: from smtpclient.apple (p5089a211.dip0.t-ipconnect.de [80.137.162.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.zfn.uni-bremen.de (Postfix) with ESMTPSA id 4VGjhq2N5LzDCcw; Sat, 13 Apr 2024 08:10:19 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <CAKoiRubb4GMm1sTq_1XRZt3+-hy+Z8ZXD21DpK5voneXFRcW6A@mail.gmail.com>
Date: Sat, 13 Apr 2024 08:10:08 +0200
Cc: cbor@ietf.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <0C90A33E-1612-490A-B525-8E9E3379DC88@tzi.org>
References: <CAKoiRubb4GMm1sTq_1XRZt3+-hy+Z8ZXD21DpK5voneXFRcW6A@mail.gmail.com>
To: Rohan Mahy <rohan.mahy@gmail.com>
X-Mailer: Apple Mail (2.3774.500.171.1.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/XjkdHLFEqTjErV0m3EtJubPC0Xw>
Subject: [Cbor] Co-occurrence constraints (Re: CDDL optionality and choices and optionality in CBOR and CDDL)
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
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: Sat, 13 Apr 2024 06:10:27 -0000

On 13. Apr 2024, at 02:49, Rohan Mahy <rohan.mahy@gmail.com> wrote:
> 
> Order = [
>   food = [ * food_items ], 
>   ( includes_alcohol: true, drinks = [ * drink_items ] ) / ( includes_alcohol: false, to_go: bool )
> ]

Almost (modulo some syntax issues).
The constructs in the parentheses are CDDL groups, so you would need a group choice:

> Order = [
>   food: [ * food_item ], 
>   ( includes_alcohol: true, drinks: [ * drink_item ] //
>     includes_alcohol: false, to_go: bool )
> ]

(Note the low operator precedence of group choices.
I also used the singular form for the items, because each item is just one item.)

This approach can solve a certain subset of the use cases that we call “co-occurrence constraints”; a more general solution usually requires some predicate language that in turn requires a navigation mechanism such as JSONPath [2]. 

BTW:

> bool = true / false

You don’t have to say this, because it already is defined [almost] that way in the CDDL prelude [1].
(Because of the “almost”, you actually cannot say it this way.)

Grüße, Carsten

[1]: https://www.rfc-editor.org/rfc/rfc8610.html#appendix-D
[2]: https://www.rfc-editor.org/rfc/rfc9535.html