decorum icon indicating copy to clipboard operation
decorum copied to clipboard

Implement custom de/serialization for non-real floating-point values.

Open olson-sean-k opened this issue 2 years ago • 1 comments

Proxy implements de/serialization using Serde, but currently serializes as a structure with a single field. It would probably be better to serialize proxy types as raw floating-point primitives instead (as seen in #25).

Care must be taken to enforce constraints when deserializing, especially if the serialized format gives no indication that any such constraints should be applied. I have a working approach in d93535c on the serde branch. It uses an intermediate type with transparent de/serialization and a conversion into/from proxy types that applies constraints.

One remaining problem is that serde_json does not support serialization of non-real values for floating-point primitives out of the box. NaNs and infinities are serialized as "null", which cannot be deserialized. Not only does this lose information, but there is no way to round-trip a non-real value. Note that commonly used serializations like "nan" are not supported. One option for improving this is custom de/serialization via additional types gated by a Cargo feature. Gating would be necessary, since the de/serialization would be non-standard, but could be used on a case-by-case basis for any downstream crates that want to be able to de/serialize non-real floating-point values.

olson-sean-k avatar Sep 08 '21 04:09 olson-sean-k

ce7ae3e has landed on master and implements transparent serialization for Proxy. However, that change does not address the lossy serialization of non-real floating-point primitives. I'll rename this issue to track the work to provide a custom de/serialization as described previously.

olson-sean-k avatar Oct 21 '22 22:10 olson-sean-k