forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: Use msgpack.v5 by default
An user can continue to use msgpack.v2 with tag: go_tarantool_msgpack_v2 There are two problems that cannot be unified: - Different signature and logic of RegisterExt in msgpack.v2[1] and msgpack.v5[2]. - Different logic of map decoding, see[3][4]. These issues have been fixed in msgpack.v5 implementation, see msgpack.go and uuid/msgpack.go. Files naming changed: msgpack.go - msgpack.v5 usage for the code msgpack_helper_test.go - msgpack.v5 usage for tests msgpack_v2.go - msgpack.v2 usage for the code msgpack_v2_helper_test.go - msgpack.v2 usage for tests 1. https://pkg.go.dev/github.com/vmihailenco/msgpack@v2.9.2+incompatible#RegisterExt 2. https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#RegisterExt 3. vmihailenco/msgpack#327 4. https://msgpack.uptrace.dev/guide/#decoding-maps-into-an-interface/
- Loading branch information
1 parent
29ae9a6
commit 6aee9ae
Showing
14 changed files
with
266 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
//go:build !go_tarantool_msgpack_v2 | ||
// +build !go_tarantool_msgpack_v2 | ||
|
||
package tarantool_test | ||
|
||
import ( | ||
. "github.com/tarantool/go-tarantool" | ||
"gopkg.in/vmihailenco/msgpack.v2" | ||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return m.encodeMsgpackImpl(&Encoder{e}) | ||
return m.encodeMsgpackImpl(&Encoder{Encoder: e}) | ||
} | ||
|
||
func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return m.decodeMsgpackImpl(&Decoder{d}) | ||
return m.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (c *Tuple2) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return c.encodeMsgpackImpl(&Encoder{e}) | ||
return c.encodeMsgpackImpl(&Encoder{Encoder: e}) | ||
} | ||
|
||
func (c *Tuple2) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return c.decodeMsgpackImpl(&Decoder{d}) | ||
return c.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//go:build go_tarantool_msgpack_v2 | ||
// +build go_tarantool_msgpack_v2 | ||
|
||
package tarantool | ||
|
||
import ( | ||
"io" | ||
|
||
"gopkg.in/vmihailenco/msgpack.v2" | ||
msgpcode "gopkg.in/vmihailenco/msgpack.v2/codes" | ||
) | ||
|
||
type Encoder struct { | ||
*msgpack.Encoder | ||
} | ||
|
||
type Decoder struct { | ||
*msgpack.Decoder | ||
} | ||
|
||
func newEncoder(w io.Writer) *Encoder { | ||
enc := msgpack.NewEncoder(w) | ||
return &Encoder{Encoder: enc} | ||
} | ||
|
||
func newDecoder(r io.Reader) *Decoder { | ||
dec := msgpack.NewDecoder(r) | ||
return &Decoder{Decoder: dec} | ||
} | ||
|
||
func (e *Encoder) encodeUintImpl(v uint64) error { | ||
return e.EncodeUint(uint(v)) | ||
} | ||
|
||
func (e *Encoder) encodeIntImpl(v int64) error { | ||
return e.EncodeInt(int(v)) | ||
} | ||
|
||
func msgpackIsUint(code byte) bool { | ||
return code == msgpcode.Uint8 || code == msgpcode.Uint16 || | ||
code == msgpcode.Uint32 || code == msgpcode.Uint64 || | ||
msgpcode.IsFixedNum(code) | ||
} | ||
|
||
func msgpackIsMap(code byte) bool { | ||
return code == msgpcode.Map16 || code == msgpcode.Map32 || msgpcode.IsFixedMap(code) | ||
} | ||
|
||
func msgpackIsArray(code byte) bool { | ||
return code == msgpcode.Array16 || code == msgpcode.Array32 || | ||
msgpcode.IsFixedArray(code) | ||
} | ||
|
||
func msgpackIsString(code byte) bool { | ||
return msgpcode.IsFixedString(code) || code == msgpcode.Str8 || | ||
code == msgpcode.Str16 || code == msgpcode.Str32 | ||
} | ||
|
||
func (s *single) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return s.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (space *Space) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return space.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (field *Field) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return field.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (index *Index) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return index.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (indexField *IndexField) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return indexField.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{Encoder: enc}) | ||
} | ||
|
||
func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{Encoder: enc}) | ||
} | ||
|
||
func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{Encoder: enc}) | ||
} | ||
|
||
func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{Encoder: enc}) | ||
} | ||
|
||
func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return o.encodeMsgpackImpl(&Encoder{Encoder: enc}) | ||
} | ||
|
||
func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return o.encodeMsgpackImpl(&Encoder{Encoder: enc}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build go_tarantool_msgpack_v2 | ||
// +build go_tarantool_msgpack_v2 | ||
|
||
package tarantool_test | ||
|
||
import ( | ||
. "github.com/tarantool/go-tarantool" | ||
"gopkg.in/vmihailenco/msgpack.v2" | ||
) | ||
|
||
func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return m.encodeMsgpackImpl(&Encoder{Encoder: e}) | ||
} | ||
|
||
func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return m.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (c *Tuple2) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return c.encodeMsgpackImpl(&Encoder{Encoder: e}) | ||
} | ||
|
||
func (c *Tuple2) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return c.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build go_tarantool_msgpack_v2 | ||
// +build go_tarantool_msgpack_v2 | ||
|
||
package queue | ||
|
||
import ( | ||
"github.com/tarantool/go-tarantool" | ||
"gopkg.in/vmihailenco/msgpack.v2" | ||
) | ||
|
||
func (qd *queueData) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return qd.decodeMsgpackImpl(&tarantool.Decoder{Decoder: d}) | ||
} | ||
|
||
func (t *Task) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return t.decodeMsgpackImpl(&tarantool.Decoder{Decoder: d}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build go_tarantool_msgpack_v2 | ||
// +build go_tarantool_msgpack_v2 | ||
|
||
package queue_test | ||
|
||
import ( | ||
. "github.com/tarantool/go-tarantool" | ||
"gopkg.in/vmihailenco/msgpack.v2" | ||
) | ||
|
||
func (c *customData) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return c.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (c *customData) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return c.encodeMsgpackImpl(&Encoder{Encoder: e}) | ||
} | ||
|
||
func (c *dummyData) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return c.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (c *dummyData) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return c.encodeMsgpackImpl(&Encoder{Encoder: e}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.