Re: [Cbor] Encoding Arbitrary Time Ratios

Carsten Bormann <> Sat, 03 April 2021 13:00 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id AC3273A0AD4 for <>; Sat, 3 Apr 2021 06:00:18 -0700 (PDT)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -1.92
X-Spam-Status: No, score=-1.92 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id 9_RNL2RCT0iM for <>; Sat, 3 Apr 2021 06:00:16 -0700 (PDT)
Received: from ( []) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 597A83A0AB8 for <>; Sat, 3 Apr 2021 06:00:15 -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 4FCH8D1mlRzyRk; Sat, 3 Apr 2021 15:00:12 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.\))
From: Carsten Bormann <>
In-Reply-To: <>
Date: Sat, 03 Apr 2021 15:00:11 +0200
X-Mao-Original-Outgoing-Id: 639147611.6453789-078ad5bf2a282cd6df5f427166ac610a
Content-Transfer-Encoding: quoted-printable
Message-Id: <>
References: <>
To: Emile Cormier <>
X-Mailer: Apple Mail (2.3608.
Archived-At: <>
Subject: Re: [Cbor] Encoding Arbitrary Time Ratios
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, 03 Apr 2021 13:00:19 -0000

On 2021-04-03, at 03:39, Emile Cormier <> wrote:
> To allow the encoding any arbitrary time ratios, I propose a new CBOR tag wrapping an array of 1 to 3 values:
> [Count, Numerator, Denominator]

Right.  We already have tag 30 for rational numbers of form n/d.
So this would be c*n/d.
I’d imagine that in many applications, n/d would be a “constant” (i.e., available from the application’s context); prefix packing or simply a convention could handle this.

> where Count is an integral or floating point number, and Numerator and Denominator are integers representing the ratio in seconds.The Numerator and Denominator would default to 1 if absent.

Only the trailing elements really can be “absent” (they could be null as well, but why not simply encode the 1 then).  Not sure that the denominator is likely to be the one that one would leave out.

> CBOR tags 1001-1003 would be extended to allow this new CBOR tag as the value key. This would allow me to encode additional metadata on the std::chrono::time_point clock type (POSIX, UTC, TAI, GPS).

Right, similar to the way we already handle 4 and 5 (and probably should add 30).
Alternatively, there could be separate keys for numerator and denominator, so these could be freely left out and/or combined.

I’m not so familiar with the use cases of this except for a scale factor of 86400 (i.e., days).

Grüße, Carsten