I agree we should add floats to the data model. If we are going to mess with the model, do it once, do it right. And once you start considering that, we have to think beyond just ATprotocol because we may end up having to interoperate with other systems. Two systems that almost but not quite interoperate can be the very worst. See base64 and base64urlencoded.
I would add the following to the JSON model:
Binary: byte
Float64: IEEE 754 binary64
Decimal64: IEEE 754 decimal64
Float80: Intel 80 bit binary float
These are the formats that are most widely supported with hardware assist. While 754 specified 128 and 256 bit floats, I am not aware of any hardware support. The 64bit binary only makes use of 53 bits of the large adder/multiplier so Intel and most other manufacturers support a mode with a 64 bit mantissa and 15 bit exponent.
Currently, pretty much everyone who uses a schema driven approach has a data model that includes binary as a type and these are serialized as base64url blobs. I suggest doing the same for binary floats to maintain backwards compatibility. Decimal floats can use the existing serialization without loss of precision.
If we use a non JSON serialization, there are three approaches that make sense:
-
Add hexadecimal encoding of binary floats. This preserves most of the advantages of a text based format. While few of us can read hex floats, this is probably not necessary for debugging purposes. It means that someone can edit a control file in a JSON like format without needing a special editor. (e.g. JSON-A)
-
Extend the JSON serialization to incorporate binary blobs using code points 128-255 for binary extensions. I did this with my JSON-B encoding which has the advantage that a single decoder can consume either straight JSON or extended editions. (e.g. my JSON-B encoding)
-
Use ASN.1, CBOR or other serialization of your choice.
I will be supporting all three approaches in my systems. I use a schema format that allows me to emit JSON, JSON-A, JSON-B and so on, ASN.1, DNS RR type encodings, protobuf etc.
The wider industry has pretty much settled on JSON though and I strongly suspect that if there is any change to JSON to support binary floats without loss of precision it will take either the hex approach or attempt the round trip serialization of IEEE754 which exists but is amazingly painful to implement.
While I was using JSON-B in my work, I have found a far more performant approach to avoiding the base64 expansion of ciphertext and signed plainted payloads. I use an envelope format based on QUIC varints. This allows me to create a CMS/PKCS#7 type envelope structure (as used in S/MIME) using JSON/JOSE for all the content metadata, key exchange, signatures etc. without the base64 penalty.
So if there is change in the wider industry, I would expect that hex representation of binary floats will be the way they go.