Commit 606e9f5a authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Kamil Kisiel

encoder: Fix float wrt protocol version

We can use BINFLOAT opcode only starting from protocol >= 1.
At protocol 0 we must use ASCII FLOAT.
parent 9053359b
......@@ -254,10 +254,16 @@ func (e *Encoder) encodeBytes(byt []byte) error {
}
func (e *Encoder) encodeFloat(f float64) error {
u := math.Float64bits(f)
var b = [1+8]byte{opBinfloat}
binary.BigEndian.PutUint64(b[1:], u)
return e.emitb(b[:])
// protocol >= 1: BINFLOAT
if e.config.Protocol >= 1 {
u := math.Float64bits(f)
var b = [1+8]byte{opBinfloat}
binary.BigEndian.PutUint64(b[1:], u)
return e.emitb(b[:])
}
// protocol 0: FLOAT
return e.emitf("%c%g\n", opFloat, f)
}
func (e *Encoder) encodeInt(k reflect.Kind, i int64) error {
......
......@@ -167,7 +167,8 @@ var tests = []TestEntry{
P1_("J\x45\x23\x01\x00.")), // BININT
X("float", float64(1.23),
I("F1.23\n.")), // FLOAT
P0("F1.23\n."), // FLOAT
P1_("G?\xf3\xae\x14z\xe1G\xae.")), // BINFLOAT
X("long", bigInt("12321231232131231231"),
P0("L12321231232131231231L\n.")), // LONG
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment