Re: [Cbor] Decoding numbers and compliance verification in dCBOR

Anders Rundgren <anders.rundgren.net@gmail.com> Sat, 11 March 2023 07:06 UTC

Return-Path: <anders.rundgren.net@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 6A8A6C15152D for <cbor@ietfa.amsl.com>; Fri, 10 Mar 2023 23:06:41 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.096
X-Spam-Level:
X-Spam-Status: No, score=-2.096 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, NICE_REPLY_A=-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 Xi1XvUK2RZtv for <cbor@ietfa.amsl.com>; Fri, 10 Mar 2023 23:06:37 -0800 (PST)
Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 AF2DAC1516E1 for <cbor@ietf.org>; Fri, 10 Mar 2023 23:06:37 -0800 (PST)
Received: by mail-wm1-x330.google.com with SMTP id d41-20020a05600c4c2900b003e9e066550fso4768773wmp.4 for <cbor@ietf.org>; Fri, 10 Mar 2023 23:06:37 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678518395; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=1VUYw0QY2U7OEW9jBBDT1O+aaXuBmjN07YL5JbMEA+E=; b=ANA4j1zJTPdGy7RXdu7zTnAoxfuGHQQZhYNHOrIzy+ypC0v188BLcHCkiptQuBYDnP Mq1UbwJFRiEPYRgeaVPpIFR+sF8pf3n0qdrlx7pkOpRfSBq8KNKGT3QbvZcETfURSyOf 0wwUuzdIsLRg4F94MOMgiPluaXYaR4GcdC9So6lLZmKPVqV0t4VuZqbsG/QqaSgfTBhz VV/kRSJ4LaZk2EJYHjwa2OGYZbwY6fK6GVnXGhCM/bt2wG4fquB4LN9AG1VRtbKiBXgk BQ0BQvCrR4w7CHDLb4f9KMQ37VTlYJ+ofpbbuVkErlDU/OHdERCG/FPnbHxFm7CgAbrx kfCw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678518395; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1VUYw0QY2U7OEW9jBBDT1O+aaXuBmjN07YL5JbMEA+E=; b=EUXaxfPcaQV757l09g34WP794pUBltdV4XU3AuquJyCdrNEQveDVncI0H07rU6aGXL RqOUrXiFcKmdYj6hHkU6uO9zcZ7oTHEKawXTvoOUyPj1QiWAUjSs532vvzOix2Fv4Ny/ nNbGnrCwsdDYxWW7WVVAUce+FolHlMArkl3bJKFaFoWzqqY6XJpxpseYP1w69UKii1ut wBnDzU3tNwNyXUJbJgWIRAL8680vR8QHLVR2l26oYfskHWqlqkfpbdjzERY5sOTIvGhx W/W5+OczR1sYZ4g49bF+AV/L6v2iXOFIgXsTfmU9HPYscgLcukPQhr/JciprU64mVz9E /1dw==
X-Gm-Message-State: AO0yUKUkygOsaa8NKv9y0f+SVnBwQtQOXh9uh8s+ieXtXoDl3SpCypfe uL5pKF7VW/NXaw9k3Pf2XQc=
X-Google-Smtp-Source: AK7set//U2LnORtpPthDIi6Azq6r7Y+JYUaXGW16nxHOltQbdCMZu67ADibq/P+Hg8rVfMpS8drwxg==
X-Received: by 2002:a05:600c:5253:b0:3eb:3b7e:7b82 with SMTP id fc19-20020a05600c525300b003eb3b7e7b82mr4883810wmb.27.1678518395110; Fri, 10 Mar 2023 23:06:35 -0800 (PST)
Received: from ?IPV6:2a01:e34:ec4e:5670:58c7:2aad:cc47:2c3? ([2a01:e34:ec4e:5670:58c7:2aad:cc47:2c3]) by smtp.googlemail.com with ESMTPSA id c21-20020a05600c0ad500b003e71a6be279sm1875127wmr.37.2023.03.10.23.06.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Mar 2023 23:06:34 -0800 (PST)
Message-ID: <38de8a78-0140-45af-b4fb-f601265809e4@gmail.com>
Date: Sat, 11 Mar 2023 08:06:33 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0
Content-Language: en-US
To: Carsten Bormann <cabo@tzi.org>, Laurence Lundblade <lgl@island-resort.com>
Cc: cbor@ietf.org, Wolf McNally <wolf@wolfmcnally.com>
References: <83BF059D-BEF2-4C5F-9DE8-7A99A529833F@island-resort.com> <8999DCEA-6572-4A69-85EC-AA7AD0170837@tzi.org>
From: Anders Rundgren <anders.rundgren.net@gmail.com>
In-Reply-To: <8999DCEA-6572-4A69-85EC-AA7AD0170837@tzi.org>
Content-Type: text/plain; charset="UTF-8"; format="flowed"
Content-Transfer-Encoding: 8bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/d66weNoGpFmTHAwG_bl-2UzUnu4>
Subject: Re: [Cbor] Decoding numbers and compliance verification in dCBOR
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, 11 Mar 2023 07:06:41 -0000

If shortest possible number representation is an absolute goal, you already have a problem with "pure" integers.  An integer value of 1099511627775 (0xffffffffff) would actually yield two bytes less(!) using the Bignums type.

It would (IMO) be unwise trying to fix this in dCBOR.

Anders

On 2023-03-10 20:14, Carsten Bormann wrote:
> Hi Laurence,
> 
> I think your arguments are important.
> But for a receiver of information, there are also benefits from knowing what to expect.
> In particular map processing can be simpler if only a specific sequence of the entries needs to be accepted.
> 
> Whether floating point values are important for an application may also influence whether it is worth to expend some additional processing.  The simplest devices often get by without any floating point operations.  Once floating point becomes important for the functioning of a device, processors such as those of ARM’s Cortex M4 series can help reduce the power-hungry on-time of the device by efficiently performing the floating point computations.  With these processors (and certainly with processors of the smartphone, laptop, and server classes), the requirements of dCBOR become almost trivial.
> 
> I don’t want to take a particular side here, just point out that not all applications are the same.  Having a go-to profile of CBOR that covers an interesting subset of applications appears to be a net win to me.
> 
> Additional CDDL support such as that provided in draft-bormann-cbor-cddl-more-control with .cbordet and .cborseqdet may be desirable.  There is currently no way in CDDL to express the rules about number representation that dCBOR has adopted; that may be one interesting gap.
> 
> Little aside: When I started to think about this, I started to wonder: What is the dCBOR way to represent 65536000000.0?
> 
> 5 bytes:
>>> 65536000000.0.to_cbor.hexs
> => "fa 51 74 24 00"
> 
> 9 bytes:
>>> 65536000000.to_cbor.hexs
> => "1b 00 00 00 0f 42 40 00 00”
> 
> Here, the floating point representation is shorter…
> But wait, even if float32 cannot be exact (e.g., for 65536000001), try:
> 
> 7 bytes:
>>> CBOR.decode("c2 45 0f 42 40 00 01".xeh)
> => 65536000001
> 
> 9 bytes:
>>> CBOR.decode("c2 45 0f 42 40 00 01".xeh).to_cbor.hexs
> => "1b 00 00 00 0f 42 40 00 01”
> 
> (Number systems are always an unwieldy part of representation formats.)
> 
> Grüße, Carsten
> 
> _______________________________________________
> CBOR mailing list
> CBOR@ietf.org
> https://www.ietf.org/mailman/listinfo/cbor