Expand description
What a value file is written in.
The probe’s value representation is JSON, because a probe has to be callable from a shell script and diffable by a human. This is the whole of what that costs: two trait implementations, and the four rules that are JSON’s rather than IDL’s.
§The four rules
- A 64-bit integer is a string. A JSON number is a double, so
9007199254740993read back through one is9007199254740992. A value file that spells a 64-bit integer as a number therefore says a different number than its author typed and every reader of the file agrees on the wrong one. Refused on the way in (EXACT_JSON_INTEGER) and never produced on the way out — for every value of those two widths and not only the large ones, because a form that changed shape at 2^53 would compare unequal across the boundary. - A
long doubleis a string. Sixty of a binary128 significand’s 113 bits do not fit a double. A number is still accepted on the way in, because1.5in a value file means 1.5 and every double widens into binary128 exactly; the way out is always the exact decimal. - A
fixed<P, S>is a string, for the same reason: afixed<31, 2>is exactly the value a double cannot carry. - NaN and infinity have no spelling. JSON has neither, so a
sample carrying one has no canonical form and is refused out loud
rather than written as
null, which would compare equal to an absent member.
Everything else about what a value means is in
crate::contract and is the same in every representation.
§Why this is here and not in zerodds-wire-probe
It belongs with the probe, which is the crate that reads value files;
Rust’s orphan rule puts it here instead. Both traits and
serde_json::Value are foreign to the probe, so the probe cannot
implement one for the other. Behind the default serde-json feature,
so a caller that brings its own representation does not take the
dependency.
Constants§
- EXACT_
JSON_ INTEGER - The largest integer a JSON number carries without loss.