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.
code health: extract a msgpack code from the code and tests
The patch replaces the msgpack code by internal wrappers. The msgpack usage have been extracted to msgpack.go file for the code and to msgpack_helper_test.go for tests. It is the same logic for submodules. Part of #124
- Loading branch information
1 parent
eb72cb3
commit 6038440
Showing
19 changed files
with
251 additions
and
106 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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
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 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{d}) | ||
} | ||
|
||
func (space *Space) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return space.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (field *Field) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return field.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (index *Index) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return index.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (indexField *IndexField) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return indexField.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (meta *ColumnMetaData) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return meta.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (info *SQLInfo) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return info.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{enc}) | ||
} | ||
|
||
func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{enc}) | ||
} | ||
|
||
func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{enc}) | ||
} | ||
|
||
func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return k.encodeMsgpackImpl(&Encoder{enc}) | ||
} | ||
|
||
func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return o.encodeMsgpackImpl(&Encoder{enc}) | ||
} | ||
|
||
func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
return o.encodeMsgpackImpl(&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,22 @@ | ||
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{e}) | ||
} | ||
|
||
func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return m.decodeMsgpackImpl(&Decoder{d}) | ||
} | ||
|
||
func (c *Tuple2) EncodeMsgpack(e *msgpack.Encoder) error { | ||
return c.encodeMsgpackImpl(&Encoder{e}) | ||
} | ||
|
||
func (c *Tuple2) DecodeMsgpack(d *msgpack.Decoder) error { | ||
return c.decodeMsgpackImpl(&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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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,22 @@ | ||
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
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.