From 219428c7f68524ee73b73728267973f210592f49 Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Fri, 15 Mar 2024 16:36:12 +0300 Subject: [PATCH] reading float32 from float64 without error --- msgpack_reader.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/msgpack_reader.go b/msgpack_reader.go index 7d1a88f..33ac95b 100644 --- a/msgpack_reader.go +++ b/msgpack_reader.go @@ -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)