forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msgpack: add optional msgpack.v5 support
The msgpack.v5 code located in msgpack_v5.go and msgpack_v5_helper_test.go for tests. It is the same logic for submodules. An user can use msgpack.v5 with a build tag: go_tarantool_msgpack_v5 Part of #124
- Loading branch information
1 parent
19da011
commit 4a8fadc
Showing
16 changed files
with
303 additions
and
17 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
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,112 @@ | ||
//go:build go_tarantool_msgpack_v5 | ||
// +build go_tarantool_msgpack_v5 | ||
|
||
package tarantool | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/vmihailenco/msgpack/v5" | ||
"github.com/vmihailenco/msgpack/v5/msgpcode" | ||
) | ||
|
||
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) | ||
dec.SetMapDecoder(func(dec *msgpack.Decoder) (interface{}, error) { | ||
return dec.DecodeUntypedMap() | ||
}) | ||
return &Decoder{Decoder: dec} | ||
} | ||
|
||
func (e *Encoder) encodeUintImpl(v uint64) error { | ||
return e.EncodeUint(v) | ||
} | ||
|
||
func (e *Encoder) encodeIntImpl(v int64) error { | ||
return e.EncodeInt(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 (meta *ColumnMetaData) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return meta.decodeMsgpackImpl(&Decoder{Decoder: d}) | ||
} | ||
|
||
func (info *SQLInfo) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return info.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_v5 | ||
// +build go_tarantool_msgpack_v5 | ||
|
||
package tarantool_test | ||
|
||
import ( | ||
. "github.com/tarantool/go-tarantool" | ||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build !go_tarantool_msgpack_v5 | ||
// +build !go_tarantool_msgpack_v5 | ||
|
||
package queue | ||
|
||
import ( | ||
|
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,3 +1,6 @@ | ||
//go:build !go_tarantool_msgpack_v5 | ||
// +build !go_tarantool_msgpack_v5 | ||
|
||
package queue_test | ||
|
||
import ( | ||
|
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_v5 | ||
// +build go_tarantool_msgpack_v5 | ||
|
||
package queue | ||
|
||
import ( | ||
"github.com/tarantool/go-tarantool" | ||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
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_v5 | ||
// +build go_tarantool_msgpack_v5 | ||
|
||
package queue_test | ||
|
||
import ( | ||
. "github.com/tarantool/go-tarantool" | ||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build !go_tarantool_msgpack_v5 | ||
// +build !go_tarantool_msgpack_v5 | ||
|
||
package uuid | ||
|
||
import ( | ||
|
Oops, something went wrong.