reading float32 from float64 without error

This commit is contained in:
Pavel Merzlyakov 2024-03-15 16:36:12 +03:00
parent 9324aeae5f
commit 219428c7f6
1 changed files with 15 additions and 0 deletions

View File

@ -255,6 +255,21 @@ func decodeBool(dec *msgpack.Decoder, v *bool) error {
}
func decodeFloat32(dec *msgpack.Decoder, v *float32) error {
code, err := dec.PeekCode()
if err != nil {
return errors.WithStack(err)
}
if code == msgpcode.Double {
var tmp float64
if err := decodeFloat64(dec, &tmp); err != nil {
return err
}
*v = float32(tmp)
return nil
}
tmp, err := dec.DecodeFloat32()
if err != nil {
return errors.WithStack(err)