Skip to content
This repository was archived by the owner on May 8, 2019. It is now read-only.

Commit e7dcf5d

Browse files
committed
improved ReadFloat32Bytes
1 parent 79e2c92 commit e7dcf5d

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

msgp/read_bytes.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,15 @@ func ReadFloat64Bytes(b []byte) (f float64, o []byte, err error) {
280280
// Possible errors:
281281
// - ErrShortBytes (too few bytes)
282282
// - TypeError{} (not a float32)
283-
func ReadFloat32Bytes(b []byte) (f float32, o []byte, err error) {
283+
func ReadFloat32Bytes(b []byte) (float32, []byte, error) {
284284
if len(b) < 5 {
285-
err = ErrShortBytes
286-
return
285+
return 0, b, ErrShortBytes
287286
}
288-
289287
if b[0] != mfloat32 {
290-
err = TypeError{Method: Float32Type, Encoded: getType(b[0])}
291-
return
288+
return 0, b, TypeError{Method: Float32Type, Encoded: getType(b[0])}
292289
}
293-
294-
f = math.Float32frombits(getMuint32(b))
295-
o = b[5:]
296-
return
290+
f := math.Float32frombits(getMuint32(b))
291+
return f, b[5:], nil
297292
}
298293

299294
// ReadBoolBytes tries to read a float64 from b and return the value and the remaining bytes.
@@ -548,7 +543,7 @@ func ReadBytesBytes(b []byte, scratch []byte) (v []byte, o []byte, err error) {
548543
func readBytesBytes(b []byte, scratch []byte, zc bool) (v []byte, o []byte, err error) {
549544
l := len(b)
550545
if l < 1 {
551-
return nil, nil, ErrShortBytes
546+
return nil, b, ErrShortBytes
552547
}
553548

554549
lead := b[0]

0 commit comments

Comments
 (0)