]> git.lizzy.rs Git - rust.git/commit
libserialize: Remove float preprocessing in serialize::json::Encoder
authorBarosl Lee <vcs@barosl.com>
Sun, 23 Nov 2014 17:22:30 +0000 (02:22 +0900)
committerBarosl Lee <vcs@barosl.com>
Mon, 8 Dec 2014 09:02:12 +0000 (18:02 +0900)
commitca4f53655e82a0a0e1d613b16108720bb7a50fde
tree72d36b4ee75e4676c5610c0b1b8c6024f7b82746
parent83a44c7fa676b4e5e546ce3d4624e585f9a1e899
libserialize: Remove float preprocessing in serialize::json::Encoder

serialize::json::Encoder currently uses f64 to emit any integral type.
This is possibly due to the behavior of JavaScript, which uses f64 to
represent any numeric value.

This leads to a problem that only the integers in the range of [-2^53+1,
2^53-1] can be encoded. Therefore, i64 and u64 cannot be used reliably
in the current implementation.

RFC 7159 suggests that good interoperability can be achieved if the
range is respected by implementations. However, it also says that
implementations are allowed to set the range of number accepted. And it
seems that the JSON encoders outside of the JavaScript world usually
make use of i64 values.

This commit removes the float preprocessing done in the emit_* methods.
It also increases performance, because transforming f64 into String
costs more than that of an integral type.

Fixes #18319

[breaking-change]
src/libserialize/json.rs