Re: [Cbor] extensible enumerations, ignoring unknown values in CDDL

Rohan Mahy <rohan.mahy@gmail.com> Sun, 14 April 2024 15:40 UTC

Return-Path: <rohan.mahy@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 C2FA6C14F6A3 for <cbor@ietfa.amsl.com>; Sun, 14 Apr 2024 08:40:40 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.094
X-Spam-Level:
X-Spam-Status: No, score=-2.094 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, 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
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 ZkjCjKYijW4t for <cbor@ietfa.amsl.com>; Sun, 14 Apr 2024 08:40:36 -0700 (PDT)
Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 EA248C14F5F4 for <cbor@ietf.org>; Sun, 14 Apr 2024 08:40:36 -0700 (PDT)
Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-56fffb1d14bso3340269a12.1 for <cbor@ietf.org>; Sun, 14 Apr 2024 08:40:36 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713109234; x=1713714034; darn=ietf.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=R8fzsbz/Munu1nhikXijxzuiOklRhdg+voiZu8qyoOo=; b=WAOhXppSN+BVitNlzbZsff4sQv7sfLUdxk3fU2ZR2pz2sxtYupkgO7O53XxL0J4sRt Wy06uEGPOKppOaTyAGM/kn6pUrqetf6790ZQIpy+oKYezRVSdMrN6PvZ7YKX0oR+jByM hyuA/uudO8C8cDetA6NLZVrH0U8BVSsB63eb1GRAk762bv4rL6A1N9TNfBVzrZy+/3QW qExQjQHSFaYtxZAFMg2oy/kYrXWZpqefhwIdrW4sDFj/kj+sirTCLpW/D8Da/rzM6kMN Pn1C9MLz/MMcCFbZXV0xlPDQP38PJU9sfWiy0ZgZeQL5U1oc6zL3A0W/6X7KgRg8QhBE Vj0A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713109234; x=1713714034; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R8fzsbz/Munu1nhikXijxzuiOklRhdg+voiZu8qyoOo=; b=Z17jkKbphIuJNVnhMq5/6E6ThstkwoiLZmGvuJB5NTgZVo0cgisFJ5DnAAFmA207Qy uaMhu4ltU4/tXwFnHE8f9qf1RPsRgyN2fK11tc0eXd12CnOpsd6ZggEtv9X3uqz6T2rI PhX2ByY/aCR9Bnmr8pp2YRt4WkW6ZyhXO2uCXmE1pCEOimaTc976fUG8B9+HHDIhZFWk jlge9qN7e3xw4FxoloAuVWsqN75OG4UEulYvVZqFfXLLmGTg3qwNHMchPgtkQKj490rV 9rhoOyhRGAC3luQLmB7cCtzpUW6WKcTy8gA/njjK7DK8DQzx/yR4OxuduVf1xhDoZv2n vcMQ==
X-Gm-Message-State: AOJu0YzVNB6YVZtrkJ5/YGh8TSZZg4Gir2ZWgpCuLDe1Ng02mH0cIF4f AEIyeO4GWo1twjRNUEkA0B+WYlcxqyvCIRGPJCud5mF9EiNmrY+VcSiU+NMybexVLjIfW70WQIl iXkIHbIG3H3VQlfWo1RuPxIfPfuqRIldq
X-Google-Smtp-Source: AGHT+IE6HwDpBQ3c1B2xPCLLPT2jHMwRL55/IavCVXYXfiFiegmBRyfm6eY57aePXUWysVIDZUAXV4wuF4VodUB1uu4=
X-Received: by 2002:a05:6402:5419:b0:570:2502:9fab with SMTP id ev25-20020a056402541900b0057025029fabmr1013463edb.16.1713109234260; Sun, 14 Apr 2024 08:40:34 -0700 (PDT)
MIME-Version: 1.0
References: <CAKoiRua7YXqw4T2zOfoQG7LkaUZ6he1jTsniWC0EPFnunsSzkw@mail.gmail.com> <0966BC9D-70A3-4C48-A719-81D2B3771EAB@tzi.org>
In-Reply-To: <0966BC9D-70A3-4C48-A719-81D2B3771EAB@tzi.org>
From: Rohan Mahy <rohan.mahy@gmail.com>
Date: Sun, 14 Apr 2024 08:40:22 -0700
Message-ID: <CAKoiRuY3XYi=Aefdp_hGVEiKWxw8W_YN-UOaY62V2s9hUA8DZw@mail.gmail.com>
To: Carsten Bormann <cabo@tzi.org>
Cc: cbor@ietf.org
Content-Type: multipart/alternative; boundary="0000000000005ea20c061610539d"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/3I2-07fonsoCHOrguNMA8ULJvmo>
Subject: Re: [Cbor] extensible enumerations, ignoring unknown values in 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: Sun, 14 Apr 2024 15:40:40 -0000

Thanks Carsten,
How about the following:

disposition = ( std_dispos // $$ext_dispos // unknown_dispos )

std-dispos = &(
    unspecified: 0,
    render: 1,
    reaction: 2,
    profile: 3,
    inline: 4,
    icon: 5,
    attachment: 6,
    session: 7,
    preview: 8
)
unknown_dispos = &( unknown: 8..255 ) ; Note: any ext_dispos take precedence

Then later document 1 could add

$$ext_dispos //= &(
    background: 9,
    mood: 10
)

And later document 2 could add

$$ext_dispos //= &(
    playlist: 11,
    game: 10
)

Did I get the syntax and precedence correct?

Cheers,
-rohan

On Sun, Apr 14, 2024 at 1:23 AM Carsten Bormann <cabo@tzi.org> wrote:

> Hi Rohan,
>
> CDDL does have an enum-like feature [1].
>
> [1]: https://www.rfc-editor.org/rfc/rfc8610.html#section-2.2.2.2
>
> > One of the enums we are using, "Disposition" should have a valid range
> from 0 to 255, but only the values from 0 to 8 have known values. The
> intent is that new values between 9 and 255 inclusive will be valid, and if
> unknown they will be treated as if they had the default disposition
> (render).
> > enum Disposition {
> >     unspecified = 0,
> >     render = 1,
> >     reaction = 2,
> >     profile = 3,
> >     inline = 4,
> >     icon = 5,
> >     attachment = 6,
> >     session = 7,
> >     preview = 8
> > };
>
> [1] has this example (abbreviated)
>
>               terminal-color = &basecolors
>               basecolors = (
>                 black: 0,  red: 1,  green: 2,  yellow: 3,
>                 blue: 4,  magenta: 5,  cyan: 6,  white: 7,
>               )
>
> This could be extended to include 8..255:
>
>               terminal-color = &basecolors
>               basecolors = (
>                 black: 0,  red: 1,  green: 2,  yellow: 3,
>                 blue: 4,  magenta: 5,  cyan: 6,  white: 7,
>                 reserved: 8..255
>               )
>
> Using the .feature mechanism, the validator could show that an extension
> was used:
>
>               terminal-color = &basecolors
>               basecolors = (
>                 black: 0,  red: 1,  green: 2,  yellow: 3,
>                 blue: 4,  magenta: 5,  cyan: 6,  white: 7,
>                 reserved: (8..255) .feature "extension"
>               )
>
> (Use a better name than “extension”.)
>
> This works great for a single document that is designed to be extensible.
> (It can also be done without using »&« by creating a simple choice.)
>
> Now, the question is, how to enable further documents to write their own
> CDDL about the extensions they define.
>
> This can be done with a socket [2]:
>
> [2]: https://www.rfc-editor.org/rfc/rfc8610.html#section-3.9
>
> terminal-color = $terminal-color / (0..255) .feature “extension"
> $terminal-color /= &basecolors
> basecolors = (
>                 black: 0,  red: 1,  green: 2,  yellow: 3,
>                 blue: 4,  magenta: 5,  cyan: 6,  white: 7,
>               )
>
> The extending spec then says:
>
> pastelcolors = ( pink: 9, mauve: 10, peach: 11, lavender: 12 )
> $terminal-color /= &pastelcolors
>
> Note how the prioritized choice semantics of CDDL [3] make sure that, with
> these rules added, lavender is always matched for 12 instead of any
> extension feature.  Prioritized choice is also the reason why the example
> puts its catch-all 0..255 not as part of the socket, but adds it as a
> choice with a lower priority than the socket.
>
> [3]: https://www.rfc-editor.org/rfc/rfc8610.html#appendix-A
>
> I should probably mention that another CDDL mechanism that can come in
> handy for structural extensibility is .within [4]; I don’t think we’d need
> it here.
>
> [4]: https://www.rfc-editor.org/rfc/rfc8610.html#section-3.8.5
>
> Grüße, Carsten
>
>