Re: [Cbor] Bignums and the generic data models (Re: đź”” WGLC on draft-ietf-cbor-7049bis-09)

Carsten Bormann <cabo@tzi.org> Wed, 15 January 2020 21:26 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 C580A12097F; Wed, 15 Jan 2020 13:26:32 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.2
X-Spam-Level:
X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
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 JQZbJ3aLy_C1; Wed, 15 Jan 2020 13:26:27 -0800 (PST)
Received: from gabriel-vm-2.zfn.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de [134.102.50.17]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 84A6F1209CB; Wed, 15 Jan 2020 13:26:27 -0800 (PST)
Received: from [192.168.217.119] (p548DC4D8.dip0.t-ipconnect.de [84.141.196.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gabriel-vm-2.zfn.uni-bremen.de (Postfix) with ESMTPSA id 47ygPF5R4bzygG; Wed, 15 Jan 2020 22:26:25 +0100 (CET)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <F3BA1A90-763C-476A-A771-79C8F53C707A@island-resort.com>
Date: Wed, 15 Jan 2020 22:26:25 +0100
Cc: Jeffrey Yasskin <jyasskin@chromium.org>, "draft-ietf-cbor-7049bis@ietf.org" <draft-ietf-cbor-7049bis@ietf.org>, Francesca Palombini <francesca.palombini=40ericsson.com@dmarc.ietf.org>, "cbor-chairs@ietf.org" <cbor-chairs@ietf.org>, "cbor@ietf.org" <cbor@ietf.org>
X-Mao-Original-Outgoing-Id: 600816385.263083-a3ccdb80545423b363f7de12684b0f56
Content-Transfer-Encoding: quoted-printable
Message-Id: <334EE56C-6140-47D6-BB58-49A53184E847@tzi.org>
References: <293AFF31-D0EF-45D6-9B9D-E8136481C404@ericsson.com> <CANh-dXnPRd7w_z2LA0gYD0GHVbmych4BGA5_-vmJz+Zn1qBh_w@mail.gmail.com> <A4756143-2E47-474C-8EBD-0632DD3B659D@tzi.org> <CANh-dXnfhoDO_Q9X+B73EtsHH89MjayeturjNOiBkKFaLL3NiQ@mail.gmail.com> <F3BA1A90-763C-476A-A771-79C8F53C707A@island-resort.com>
To: Laurence Lundblade <lgl@island-resort.com>
X-Mailer: Apple Mail (2.3608.40.2.2.4)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/7Bcz0qWI_96SeWBMkqvXI-8DR3g>
Subject: Re: [Cbor] Bignums and the generic data models (Re: đź”” WGLC on draft-ietf-cbor-7049bis-09)
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, 15 Jan 2020 21:26:33 -0000

Hi Laurence,

The juicy bit was your last paragraph:

> I don’t think anyone is going to send smaller integer values as the bignum type (some integer values like 0xffffff encode smaller as a bignum type than they would as type 0 and 1, but I don’t think we want to encourage that). 

Exactly.  By making the basic integer the preferred serialization, we make sure that bignums only occur where they are actually needed.  That is a strong reason to keep bignums in the same space as basic integers and to make basic integers, when they fit, the preferred serialization for a single integer domain.

On 2020-01-15, at 22:00, Laurence Lundblade <lgl@island-resort.com> wrote:
> 
> I’m in favor of bignums being quite separate:
> - There are very very few use cases for them, many fewer than floating point, as we just don’t need the the range and the precision at the same time

That depends a lot on the application.

If we hadn’t provided bignums as a catch-all, I’m sure we would already have activated ai=30 for 128-bit integers.  With bignums, we probably will never need that (we can still make that step if we really have to).

Bignums are the “design for decades” relief for limiting basic integers to 64 bits.

> - CPUs and programming languages don’t generally or generically support them — if you are writing code for bignums you are writing very specific code

Again, that depends a lot on your application.

> For example, I don’t think it would be useful for a generic decoder to convert bignums less than 0xffffffff to uint32_t and those larger than that to a byte array when returned to the caller.

I would expect the generic decoder to decode a bignum as an integer in the representations provided by the platform (*), just as with basic integers.

Now if the platform doesn’t have such representations, handing up the tag (for plus/minus) and the byte string is exactly what I would recommend a generic decoder to do.

Not being able to decode 2(h’12’) as 18 is somewhat equivalent to not being able to decode 0x1B0000000000000012 as a 32-bit integer on a 32-bit platform — not recommended, but an option that CBOR gives to a generic decoder (both 2(h’12’) and 0x1B0000000000000012 are not in preferred encoding).

> Bignum spelling auto correct: big numb lignum bingo bigness!

My Mac has quickly adapted: bignum (look, ma, no autocorrect!).

GrĂĽĂźe, Carsten

(*) Popular platforms that don’t have arbitrary limits on integer sizes include: Common Lisp, Erlang (of WhatsApp fame), Haskell, Prolog, Python, Racket, Ruby, TCL.
Other platforms such as C#, D, Go, Java, JavaScript, Julia, OCaml provide standard libraries for handling unrestricted integers.  For other languages, there are multiple libraries available to get these, e.g., for C/C++ you can find Boost, GMP, mbedTLS, OpenSSL.