Skip to content

Commit 8ab808c

Browse files
committed
msgpack: fix number types conversions after decoding
msgpack v2.9.2 decodes all numbers as uint[1] or int[2], but msgpack.v5 decodes numbers as a MessagePack type[3]. We need to unify the type conversions in the code. 1. https://github.com/vmihailenco/msgpack/blob/23644a15054d8b9f8a9fca3e041f3419504b9c21/decode.go#L283 2. https://github.com/vmihailenco/msgpack/blob/23644a15054d8b9f8a9fca3e041f3419504b9c21/decode.go#L285 3. https://github.com/vmihailenco/msgpack/blob/233c977ae92b215a9aa7eb420bbe67da99f05ab6/decode.go#L410 Part of #124
1 parent 813bda0 commit 8ab808c

File tree

6 files changed

+89
-77
lines changed

6 files changed

+89
-77
lines changed

call_16_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestConnection_Call(t *testing.T) {
2222
if err != nil {
2323
t.Errorf("Failed to use Call")
2424
}
25-
if resp.Data[0].([]interface{})[0].(uint64) != 2 {
25+
if val, err := convertUint64(resp.Data[0].([]interface{})[0]); err != nil || val != 2 {
2626
t.Errorf("result is not {{1}} : %v", resp.Data)
2727
}
2828
}
@@ -39,7 +39,7 @@ func TestCallRequest(t *testing.T) {
3939
if err != nil {
4040
t.Errorf("Failed to use Call")
4141
}
42-
if resp.Data[0].([]interface{})[0].(uint64) != 2 {
42+
if val, err := convertUint64(resp.Data[0].([]interface{})[0]); err != nil || val != 2 {
4343
t.Errorf("result is not {{1}} : %v", resp.Data)
4444
}
4545
}

call_17_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestConnection_Call(t *testing.T) {
2222
if err != nil {
2323
t.Errorf("Failed to use Call")
2424
}
25-
if resp.Data[0].(uint64) != 2 {
25+
if val, err := convertUint64(resp.Data[0]); err != nil || val != 2 {
2626
t.Errorf("result is not {{1}} : %v", resp.Data)
2727
}
2828
}
@@ -39,7 +39,7 @@ func TestCallRequest(t *testing.T) {
3939
if err != nil {
4040
t.Errorf("Failed to use Call")
4141
}
42-
if resp.Data[0].(uint64) != 2 {
42+
if val, err := convertUint64(resp.Data[0]); err != nil || val != 2 {
4343
t.Errorf("result is not {{1}} : %v", resp.Data)
4444
}
4545
}

example_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ func ExampleFuture_GetIterator() {
240240
resp := it.Value()
241241
if resp.Code == tarantool.PushCode {
242242
// It is a push message.
243-
fmt.Printf("push message: %d\n", resp.Data[0].(uint64))
243+
fmt.Printf("push message: %v\n", resp.Data[0])
244244
} else if resp.Code == tarantool.OkCode {
245245
// It is a regular response.
246-
fmt.Printf("response: %d", resp.Data[0].(uint64))
246+
fmt.Printf("response: %v", resp.Data[0])
247247
} else {
248248
fmt.Printf("an unexpected response code %d", resp.Code)
249249
}

queue/msgpack.go

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"gopkg.in/vmihailenco/msgpack.v2"
66
)
77

8+
func (r *kickResult) DecodeMsgpack(d *msgpack.Decoder) error {
9+
return r.decodeMsgpackImpl(&tarantool.Decoder{Decoder: d})
10+
}
11+
812
func (qd *queueData) DecodeMsgpack(d *msgpack.Decoder) error {
913
return qd.decodeMsgpackImpl(&tarantool.Decoder{Decoder: d})
1014
}

queue/queue.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,27 @@ func (q *queue) produce(cmd string, params ...interface{}) (string, error) {
283283
return qd.task.status, nil
284284
}
285285

286+
type kickResult struct {
287+
id uint64
288+
}
289+
290+
func (r *kickResult) decodeMsgpackImpl(d *tarantool.Decoder) (err error) {
291+
var l int
292+
if l, err = d.DecodeArrayLen(); err != nil {
293+
return err
294+
}
295+
if l > 1 {
296+
return fmt.Errorf("array len doesn't match for queue kick data: %d", l)
297+
}
298+
r.id, err = d.DecodeUint64()
299+
return
300+
}
301+
286302
// Reverse the effect of a bury request on one or more tasks.
287303
func (q *queue) Kick(count uint64) (uint64, error) {
288-
resp, err := q.conn.Call17(q.cmds.kick, []interface{}{count})
289-
var id uint64
290-
if err == nil {
291-
id = resp.Data[0].(uint64)
292-
}
293-
return id, err
304+
var r kickResult
305+
err := q.conn.Call17Typed(q.cmds.kick, []interface{}{count}, &r)
306+
return r.id, err
294307
}
295308

296309
// Delete the task identified by its id.

0 commit comments

Comments
 (0)