Re: [Cbor] Encoding Arbitrary Time Ratios

Emile Cormier <emile.cormier.jr@gmail.com> Mon, 05 April 2021 22:09 UTC

Return-Path: <emile.cormier.jr@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 8CB753A29FE for <cbor@ietfa.amsl.com>; Mon, 5 Apr 2021 15:09:56 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.097
X-Spam-Level:
X-Spam-Status: No, score=-2.097 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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 ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WQBJQSu_xFXG for <cbor@ietfa.amsl.com>; Mon, 5 Apr 2021 15:09:50 -0700 (PDT)
Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A5ACF3A29F8 for <cbor@ietf.org>; Mon, 5 Apr 2021 15:09:50 -0700 (PDT)
Received: by mail-pf1-x429.google.com with SMTP id i190so764187pfc.12 for <cbor@ietf.org>; Mon, 05 Apr 2021 15:09:50 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=S8v7I1qccgzISytOgG4lGGWuPq4v/srFr2TnZn1rpr8=; b=dWxzDbBDBiwicaRQJxnDcTJHhywabtJFldiBigSQeJY5vn422GuqAvqs56U8PFgR+k PTXipClkjELZJrUdsi6wYokkPMcDAhNleKinEArbDgL2/3m9vu32iDcjnP9RyZ8pCy4l tPvthQyRvCAktO6QwOosGVZMtptnfM7xA2wr14O3LjUcaq6z5Npn4eipL6wnGYmHFCOz b45lYMtmnTKfaWVspU6A1m7vIVPs13g5J6Gyz6sfoLlP/oUXGkV7L78/IplSiLzRVMza SHrZuiob1TeBzVRewoT82W5wkUdzPGeQe35UROe66HCCDojRb79BoeB74N1PmaSMkiNQ zkCg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S8v7I1qccgzISytOgG4lGGWuPq4v/srFr2TnZn1rpr8=; b=cDkDSsuPF4PZgXf+jgIpTonf/5LIhk3gADMXnSVNxl/Kzy/oGuEgz6bhsDtKvW9XaS FJk5bCgkSbi7EOFr4r5Fb1DN1LTMsCdyVsDBulsfZ3LTxnPEx1e/d1i4Q9shsBYYO+hN ctnukxYlxpSwDs9LFdG2sWxa6WJTxejd12uLdkK8uqcruqXrdQOIdnyk4Ae2CmZR+2or rpsOrA5miADgPQZblqFFrXzcWpQUW5LSud3gXbN/mDO+M4SYeIx1E695AUBf/LUuCziD E/1eHtArCqdROqNzFjP+vuZeJG3jHj2AaBMsJkam2h7C9cvhOWapcezMth1UskizLt9u eb5Q==
X-Gm-Message-State: AOAM532XI18NkIIAEBJLRM36mNE09rW1viD7ikVUlqkyN6kcVkP+fvNB hsmimfqxY+2Mzv2YANtJPYT8JwPhlVK8GEhO+mY=
X-Google-Smtp-Source: ABdhPJxsySCgNTv26zMKSyfXignONSb/KGF4QYJoDqw3MdLlU10+XVLKZ6UhVS+rk2bA0ja99nadEWjFqiz4JD3e2NI=
X-Received: by 2002:a63:fa41:: with SMTP id g1mr16346345pgk.143.1617660589133; Mon, 05 Apr 2021 15:09:49 -0700 (PDT)
MIME-Version: 1.0
References: <CAM70yxBF2XeewhsXOGv06kTVitz1kNHkYLHGqm3gX0Vyc2c2YA@mail.gmail.com> <CAM70yxCaOps1n7pLo_BPR0_ggZ_QbJnY-jsNPw2NYPfP=psihg@mail.gmail.com> <45AF20FB-886E-4BB7-9565-FC02E6BD694D@island-resort.com> <2403465.MzrCfxQRY8@tjmaciei-mobl1>
In-Reply-To: <2403465.MzrCfxQRY8@tjmaciei-mobl1>
From: Emile Cormier <emile.cormier.jr@gmail.com>
Date: Mon, 05 Apr 2021 19:09:37 -0300
Message-ID: <CAM70yxAvoZmURMZHNY3-pKceU0mPbny=-QRAEeEzM2P0pcYrAg@mail.gmail.com>
To: Thiago Macieira <thiago.macieira@intel.com>
Cc: cbor@ietf.org
Content-Type: multipart/alternative; boundary="000000000000c8527705bf40f487"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/W2lynGwL3TH6h7_mgT8VCmbX3Ys>
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: Mon, 05 Apr 2021 22:09:57 -0000

On Mon, Apr 5, 2021 at 12:59 PM Thiago Macieira <thiago.macieira@intel.com>
wrote:

> On Saturday, 3 April 2021 20:00:03 PDT Laurence Lundblade wrote:
> > What you propose seems useful in use cases of one C++ talking to another
> > when the protocol is not intended for broad use.
> >
> > LL
>
> Not really,. it's not. It's only useful if both sides already know what
> the
> other will send, otherwise you can't find a std::chrono::time_point
> specialisation to match the type. Note that the std::ratio specialisations
> that time_point are constructed on are compile-time constants. You can't
> match
> them unless you know before hand you may need to.
>

You are indeed correct that std::ratio is compile-time. But passing along
the ratio via CBOR allows the decoder to compute the values needed to store
it under a different compile-time std::ratio used by the receiving
application (as well as detecting overflow). If the destination ratio
happens to be the same, the decoder can bypass all the intermediate
calculations.


>
> For example, ii I sent a time point specifying a ratio of 14609700 : 864,
> I
> REALLY do not expect the receiver to find a matching type (that's an
> average
> century with 36524 and one quarter days). Another "useful" ratio is 1296 :
> 1000, the microfortnight.
>
>
Now, now, no need to get snarky. ;-)  I concede that ratios other than
86400:1 (days) or 1:10^3N are contrived examples and probably have no
practical use over an interoperable protocol.


> So, no, let's be very clear that code meant to be interoperable should
> never
> use one of those. If we think it's useful to allow protocols to specify
> their
> own time points, sure, make it possible to encode them in a specific tag.
> I
> don't think it is.
>
> I would say only decimal powers of the second with values 0, -3, -6 and -9
> are
> meant to be used in interoperable protocols and therefore we should
> optimise
> for size for those and only those.
>
>
I think dates expressed as a number of days since the epoch would also be
useful. Tag 0 (date/time string) has a numeric counterpart under tag 1. I
think tag 1004 (date string) should also have a numeric counterpart under
one form or another.

If tag 30 (rational number) were allowed to express time in seconds, it
could be used to represent integral days with a range of +/-2^61 / 86400 =
+/-26687997791825 days, which corresponds to +/-73069256156.73 years.
That's 5.3 times the age of the universe.

Of course, seconds since epoch (tag 1) could also be used to exchange a
date as days*86400, but the semantics of the value (a date) would be lost.

How about just a new tag for a date expressed as the number of days since
the epoch? This would definitely be useful (and efficient) in C++ when both
ends use std::chrono::sys_date. Decoders for other languages could simply
multiply the value by 86400 and handle it the same way as tag 1.