Re: [Cbor] Decoding of 64-bit CBOR ints on 32-bit systems

Carsten Bormann <> Sat, 27 April 2019 22:06 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id C14D01202B9 for <>; Sat, 27 Apr 2019 15:06:35 -0700 (PDT)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -4.2
X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham autolearn_force=no
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id gzV_4yLej1Ht for <>; Sat, 27 Apr 2019 15:06:33 -0700 (PDT)
Received: from ( []) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 389A71202B2 for <>; Sat, 27 Apr 2019 15:06:33 -0700 (PDT)
Received: from [] ( []) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPSA id 44s4kv0xq0zyZD; Sun, 28 Apr 2019 00:06:31 +0200 (CEST)
Content-Type: text/plain; charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\))
From: Carsten Bormann <>
In-Reply-To: <>
Date: Sun, 28 Apr 2019 00:06:30 +0200
X-Mao-Original-Outgoing-Id: 578095588.3287621-aaa741f7c1d92e76dc97ae73500ea59e
Content-Transfer-Encoding: quoted-printable
Message-Id: <>
References: <>
To: Felipe Gasper <>
X-Mailer: Apple Mail (2.3445.9.1)
Archived-At: <>
Subject: Re: [Cbor] Decoding of 64-bit CBOR ints on 32-bit systems
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-Subscribe: <>, <>
X-List-Received-Date: Sat, 27 Apr 2019 22:06:36 -0000

Hi Felipe,

> On Apr 27, 2019, at 23:14, Felipe Gasper <> wrote:
> 	Is there either a custom or a standard that guides interpretation of 64-bit CBOR integers on 32-bit systems that don’t have 64-bit emulation?

How to interpret this question depends a bit on what you are trying to do.  Let me try to list the possibilities:

(1) I have an application protocol that makes use of integers that don’t fit into the 32-bit integers I have on my systems.

(2) I have an application protocol that doesn’t make use of such integers.  A CBOR encoder could still use a 64-bit form for such an integer (non-preferred encoding).

Orthogonal to this is the question whether you are employing a generic CBOR decoder or an application-specific one.

I think for (2) with a generic CBOR decoder, my recommendation would be to handle this in the generic CBOR decoder (e.g., by checking that the upper 32 bits are zero); similarly for an application specific CBOR decoder.  Alternatively, the application protocol could outright forbid 64-bit forms, just like it could forbid floating point numbers.

For (1), any application-specific CBOR decoder would then have to handle this case in a way that makes sense for the application.  A generic CBOR decoder could define its own 64-bit integer type (not necessarily with all the usual operations implemented), e.g. as a struct of two 32-bit unsigned integers.  Such a generic decoder would, of course, also work for (2); I’d probably still recommend that the decoder deliver integers where the upper half is zero as simple 32-bit integers.  An application of type (2) would handle any input that has those 64-bit structures as “unexpected” input.

Similar considerations apply for other data types not supported by the platform, e.g. 64-bit floating point values (or floating point values at all); it is maybe more obvious how to handle these.

After trying to handle your question in a general way, I think you can see what we would like to know about the specific circumstances to really answer this question.

Grüße, Carsten