Re: [Cbor] Encoding Arbitrary Time Ratios

Carsten Bormann <cabo@tzi.org> Sat, 03 April 2021 13:00 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 AC3273A0AD4 for <cbor@ietfa.amsl.com>; Sat, 3 Apr 2021 06:00:18 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.92
X-Spam-Level:
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 mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9_RNL2RCT0iM for <cbor@ietfa.amsl.com>; Sat, 3 Apr 2021 06:00:16 -0700 (PDT)
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 597A83A0AB8 for <cbor@ietf.org>; Sat, 3 Apr 2021 06:00:15 -0700 (PDT)
Received: from client-0137.vpn.uni-bremen.de (client-0137.vpn.uni-bremen.de [134.102.107.137]) (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 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.120.23.2.4\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <CAM70yxBF2XeewhsXOGv06kTVitz1kNHkYLHGqm3gX0Vyc2c2YA@mail.gmail.com>
Date: Sat, 03 Apr 2021 15:00:11 +0200
Cc: cbor@ietf.org
X-Mao-Original-Outgoing-Id: 639147611.6453789-078ad5bf2a282cd6df5f427166ac610a
Content-Transfer-Encoding: quoted-printable
Message-Id: <A96FD12B-2F8B-495B-83F1-4A0F50DAA12C@tzi.org>
References: <CAM70yxBF2XeewhsXOGv06kTVitz1kNHkYLHGqm3gX0Vyc2c2YA@mail.gmail.com>
To: Emile Cormier <emile.cormier.jr@gmail.com>
X-Mailer: Apple Mail (2.3608.120.23.2.4)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/0VjeXh-qW9ka1nczxyz_5gJGhMU>
Subject: Re: [Cbor] Encoding Arbitrary Time Ratios
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: Sat, 03 Apr 2021 13:00:19 -0000

On 2021-04-03, at 03:39, Emile Cormier <emile.cormier.jr@gmail.com> 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