Repository navigation
Decode integers into floats - #58
Conversation
Encoders without a separate float type, such as JavaScript's, write 5.0 as the integer 5, so a float field received `UnexpectedToken`. Every integer form now decodes into f16, f32 and f64, rounding where needed and giving infinity when the value is too large for the type. The integer path is out of line so the float path stays as small as before.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Encoders without a separate float type, such as JavaScript's, write
5.0as the integer5, so a client sending{price: 5}to anf64field goterror.UnexpectedToken.Decoding into
f16,f32orf64, optional or not, now accepts every MessagePack integer form: positive and negative fixints, uint8 to uint64 and int8 to int64. Large integers round to the nearest float, and one too large for the type decodes to infinity, the same as a float64 that does not fit. Other kinds of value are stillerror.UnexpectedToken.The integer handling is in a separate out-of-line function, so the float32/float64 path is the same as before.