Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
olson-sean-k opened this issue Sep 8, 2021 · 1 comment

Comments

@olson-sean-k
Copy link
Owner

olson-sean-k commented Sep 8, 2021

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
Copy link
Owner Author

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 olson-sean-k changed the title De/serialize proxy types transparently with constraints. Implement custom de/serialization for non-real floating-point values. Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant