Skip to content

Update vmihailenco/msgpack to v5 #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ a custom packer/unpacker, but it will work slower.

```go
import (
"fmt"
"github.com/tarantool/go-tarantool"
"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

type Member struct {
Expand All @@ -349,13 +350,13 @@ type Tuple2 struct {
}

func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error {
if err := e.EncodeSliceLen(2); err != nil {
if err := e.EncodeArrayLen(2); err != nil {
return err
}
if err := e.EncodeString(m.Name); err != nil {
return err
}
if err := e.EncodeUint(m.Val); err != nil {
if err := e.EncodeUint(uint64(m.Val)); err != nil {
return err
}
return nil
Expand All @@ -364,7 +365,7 @@ func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error {
func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error {
var err error
var l int
if l, err = d.DecodeSliceLen(); err != nil {
if l, err = d.DecodeArrayLen(); err != nil {
return err
}
if l != 2 {
Expand All @@ -380,7 +381,7 @@ func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error {
}

func (c *Tuple) EncodeMsgpack(e *msgpack.Encoder) error {
if err := e.EncodeSliceLen(3); err != nil {
if err := e.EncodeArrayLen(3); err != nil {
return err
}
if err := e.EncodeUint(c.Cid); err != nil {
Expand Down Expand Up @@ -506,7 +507,7 @@ func decodeTuple(d *msgpack.Decoder, v reflect.Value) error {
```go
package main
import (
"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
"github.com/tarantool/go-tarantool"
"github.com/tarantool/go-tarantool/queue"
"time"
Expand Down
30 changes: 15 additions & 15 deletions client_tools.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tarantool

import (
"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

// IntKey is utility type for passing integer key to Select*, Update* and Delete*
Expand All @@ -11,8 +11,8 @@ type IntKey struct {
}

func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeSliceLen(1)
enc.EncodeInt(k.I)
enc.EncodeArrayLen(1)
enc.EncodeInt(int64(k.I))
return nil
}

Expand All @@ -23,8 +23,8 @@ type UintKey struct {
}

func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeSliceLen(1)
enc.EncodeUint(k.I)
enc.EncodeArrayLen(1)
enc.EncodeUint(uint64(k.I))
return nil
}

Expand All @@ -35,7 +35,7 @@ type StringKey struct {
}

func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeSliceLen(1)
enc.EncodeArrayLen(1)
enc.EncodeString(k.S)
return nil
}
Expand All @@ -47,9 +47,9 @@ type IntIntKey struct {
}

func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeSliceLen(2)
enc.EncodeInt(k.I1)
enc.EncodeInt(k.I2)
enc.EncodeArrayLen(2)
enc.EncodeInt(int64(k.I1))
enc.EncodeInt(int64(k.I2))
return nil
}

Expand All @@ -61,9 +61,9 @@ type Op struct {
}

func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeSliceLen(3)
enc.EncodeArrayLen(3)
enc.EncodeString(o.Op)
enc.EncodeInt(o.Field)
enc.EncodeInt(int64(o.Field))
return enc.Encode(o.Arg)
}

Expand All @@ -76,11 +76,11 @@ type OpSplice struct {
}

func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error {
enc.EncodeSliceLen(5)
enc.EncodeArrayLen(5)
enc.EncodeString(o.Op)
enc.EncodeInt(o.Field)
enc.EncodeInt(o.Pos)
enc.EncodeInt(o.Len)
enc.EncodeInt(int64(o.Field))
enc.EncodeInt(int64(o.Pos))
enc.EncodeInt(int64(o.Len))
enc.EncodeString(o.Replace)
return nil
}
11 changes: 8 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sync/atomic"
"time"

"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

const requestsMap = 128
Expand Down Expand Up @@ -228,13 +228,15 @@ type Opts struct {
// - If opts.Reconnect is non-zero, then error will be returned only if authorization// fails. But if Tarantool is not reachable, then it will attempt to reconnect later
// and will not end attempts on authorization failures.
func Connect(addr string, opts Opts) (conn *Connection, err error) {
d := msgpack.NewDecoder(&smallBuf{})
d.UseLooseInterfaceDecoding(true)
conn = &Connection{
addr: addr,
requestId: 0,
Greeting: &Greeting{},
control: make(chan struct{}),
opts: opts,
dec: msgpack.NewDecoder(&smallBuf{}),
dec: d,
}
maxprocs := uint32(runtime.GOMAXPROCS(-1))
if conn.opts.Concurrency == 0 || conn.opts.Concurrency > maxprocs*128 {
Expand Down Expand Up @@ -433,7 +435,9 @@ func (conn *Connection) writeAuthRequest(w *bufio.Writer, scramble []byte) (err
requestCode: AuthRequest,
}
var packet smallWBuf
err = request.pack(&packet, msgpack.NewEncoder(&packet), func(enc *msgpack.Encoder) error {
enc := msgpack.NewEncoder(&packet)
enc.UseCompactInts(true)
err = request.pack(&packet, enc, func(enc *msgpack.Encoder) error {
return enc.Encode(map[uint32]interface{}{
KeyUserName: conn.opts.User,
KeyTuple: []interface{}{string("chap-sha1"), string(scramble)},
Expand Down Expand Up @@ -721,6 +725,7 @@ func (conn *Connection) putFuture(fut *Future, body func(*msgpack.Encoder) error
if shard.buf.Cap() == 0 {
shard.buf.b = make([]byte, 0, 128)
shard.enc = msgpack.NewEncoder(&shard.buf)
shard.enc.UseCompactInts(true)
}
blen := shard.buf.Len()
if err := fut.pack(&shard.buf, shard.enc, body); err != nil {
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ module github.com/tarantool/go-tarantool

go 1.11

require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
google.golang.org/appengine v1.6.6 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/vmihailenco/msgpack.v2 v2.9.1
)
require github.com/vmihailenco/msgpack/v5 v5.1.2
35 changes: 15 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65 h1:+rhAzEzT3f4JtomfC371qB+0Ola2caSKcY69NUBZrRQ=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc=
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/vmihailenco/msgpack.v2 v2.9.1 h1:kb0VV7NuIojvRfzwslQeP3yArBqJHW9tOl4t38VS1jM=
gopkg.in/vmihailenco/msgpack.v2 v2.9.1/go.mod h1:/3Dn1Npt9+MYyLpYYXjInO/5jvMLamn+AEGwNEOatn8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vmihailenco/msgpack/v5 v5.1.2 h1:W0PAZV3UT35gi5ZTdhRilgL7IaviXnwJAu++eeMXXF8=
github.com/vmihailenco/msgpack/v5 v5.1.2/go.mod h1:C5gboKD0TJPqWDTVTtrQNfRbiBwHZGo8UTqP/9/XvLI=
github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc=
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/tarantool/go-tarantool"
msgpack "gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

// Queue is a handle to tarantool queue's tube
Expand Down Expand Up @@ -326,7 +326,7 @@ type queueData struct {
func (qd *queueData) DecodeMsgpack(d *msgpack.Decoder) error {
var err error
var l int
if l, err = d.DecodeSliceLen(); err != nil {
if l, err = d.DecodeArrayLen(); err != nil {
return err
}
if l > 1 {
Expand Down
2 changes: 1 addition & 1 deletion queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

. "github.com/tarantool/go-tarantool"
"github.com/tarantool/go-tarantool/queue"
"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

var server = "127.0.0.1:3013"
Expand Down
4 changes: 2 additions & 2 deletions queue/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package queue
import (
"fmt"

msgpack "gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

// Task represents a task from tarantool queue's tube
Expand All @@ -17,7 +17,7 @@ type Task struct {
func (t *Task) DecodeMsgpack(d *msgpack.Decoder) error {
var err error
var l int
if l, err = d.DecodeSliceLen(); err != nil {
if l, err = d.DecodeArrayLen(); err != nil {
return err
}
if l < 3 {
Expand Down
46 changes: 23 additions & 23 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"time"

"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

// Future is a handle for asynchronous request
Expand All @@ -24,28 +24,28 @@ func (conn *Connection) Ping() (resp *Response, err error) {
return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(0); return nil }).Get()
}

func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{}) error {
enc.EncodeUint64(KeySpaceNo)
enc.EncodeUint64(uint64(spaceNo))
enc.EncodeUint64(KeyIndexNo)
enc.EncodeUint64(uint64(indexNo))
enc.EncodeUint64(KeyKey)
func (fut *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{}) error {
enc.EncodeUint(KeySpaceNo)
enc.EncodeUint32(spaceNo)
enc.EncodeUint(KeyIndexNo)
enc.EncodeUint32(indexNo)
enc.EncodeUint(KeyKey)
return enc.Encode(key)
}

func (req *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator uint32) {
enc.EncodeUint64(KeyIterator)
enc.EncodeUint64(uint64(iterator))
enc.EncodeUint64(KeyOffset)
enc.EncodeUint64(uint64(offset))
enc.EncodeUint64(KeyLimit)
enc.EncodeUint64(uint64(limit))
func (fut *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator uint32) {
enc.EncodeUint(KeyIterator)
enc.EncodeUint32(iterator)
enc.EncodeUint(KeyOffset)
enc.EncodeUint32(offset)
enc.EncodeUint(KeyLimit)
enc.EncodeUint32(limit)
}

func (req *Future) fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error {
enc.EncodeUint64(KeySpaceNo)
enc.EncodeUint64(uint64(spaceNo))
enc.EncodeUint64(KeyTuple)
func (fut *Future) fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error {
enc.EncodeUint(KeySpaceNo)
enc.EncodeUint32(spaceNo)
enc.EncodeUint(KeyTuple)
return enc.Encode(tuple)
}

Expand Down Expand Up @@ -129,7 +129,7 @@ type single struct {
func (s *single) DecodeMsgpack(d *msgpack.Decoder) error {
var err error
var len int
if len, err = d.DecodeSliceLen(); err != nil {
if len, err = d.DecodeArrayLen(); err != nil {
return err
}
if s.found = len >= 1; !s.found {
Expand Down Expand Up @@ -281,7 +281,7 @@ func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface
if err := future.fillSearch(enc, spaceNo, indexNo, key); err != nil {
return err
}
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeyTuple)
return enc.Encode(ops)
})
}
Expand All @@ -296,13 +296,13 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in
}
return future.send(conn, func(enc *msgpack.Encoder) error {
enc.EncodeMapLen(3)
enc.EncodeUint64(KeySpaceNo)
enc.EncodeUint(KeySpaceNo)
enc.EncodeUint64(uint64(spaceNo))
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeyTuple)
if err := enc.Encode(tuple); err != nil {
return err
}
enc.EncodeUint64(KeyDefTuple)
enc.EncodeUint(KeyDefTuple)
return enc.Encode(ops)
})
}
Expand Down
10 changes: 9 additions & 1 deletion response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tarantool
import (
"fmt"

"gopkg.in/vmihailenco/msgpack.v2"
"github.com/vmihailenco/msgpack/v5"
)

type Response struct {
Expand Down Expand Up @@ -64,10 +64,16 @@ func (resp *Response) decodeHeader(d *msgpack.Decoder) (err error) {
return nil
}

func decodeMap(dec *msgpack.Decoder) (interface{}, error) {
return dec.DecodeUntypedMap()
}

func (resp *Response) decodeBody() (err error) {
if resp.buf.Len() > 2 {
var l int
d := msgpack.NewDecoder(&resp.buf)
d.SetMapDecoder(decodeMap)
d.UseLooseInterfaceDecoding(true)
if l, err = d.DecodeMapLen(); err != nil {
return err
}
Expand Down Expand Up @@ -108,6 +114,8 @@ func (resp *Response) decodeBodyTyped(res interface{}) (err error) {
if resp.buf.Len() > 0 {
var l int
d := msgpack.NewDecoder(&resp.buf)
d.SetMapDecoder(decodeMap)
d.UseLooseInterfaceDecoding(true)
if l, err = d.DecodeMapLen(); err != nil {
return err
}
Expand Down
Loading