|
| 1 | +package tarantool |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + |
| 6 | + "gopkg.in/vmihailenco/msgpack.v2" |
| 7 | + msgpcode "gopkg.in/vmihailenco/msgpack.v2/codes" |
| 8 | +) |
| 9 | + |
| 10 | +type Encoder struct { |
| 11 | + *msgpack.Encoder |
| 12 | +} |
| 13 | + |
| 14 | +type Decoder struct { |
| 15 | + *msgpack.Decoder |
| 16 | +} |
| 17 | + |
| 18 | +func newEncoder(w io.Writer) *Encoder { |
| 19 | + enc := msgpack.NewEncoder(w) |
| 20 | + return &Encoder{Encoder: enc} |
| 21 | +} |
| 22 | + |
| 23 | +func newDecoder(r io.Reader) *Decoder { |
| 24 | + dec := msgpack.NewDecoder(r) |
| 25 | + return &Decoder{Decoder: dec} |
| 26 | +} |
| 27 | + |
| 28 | +func msgpackIsUint(code byte) bool { |
| 29 | + return code == msgpcode.Uint8 || code == msgpcode.Uint16 || |
| 30 | + code == msgpcode.Uint32 || code == msgpcode.Uint64 || |
| 31 | + msgpcode.IsFixedNum(code) |
| 32 | +} |
| 33 | + |
| 34 | +func msgpackIsMap(code byte) bool { |
| 35 | + return code == msgpcode.Map16 || code == msgpcode.Map32 || msgpcode.IsFixedMap(code) |
| 36 | +} |
| 37 | + |
| 38 | +func msgpackIsArray(code byte) bool { |
| 39 | + return code == msgpcode.Array16 || code == msgpcode.Array32 || |
| 40 | + msgpcode.IsFixedArray(code) |
| 41 | +} |
| 42 | + |
| 43 | +func msgpackIsString(code byte) bool { |
| 44 | + return msgpcode.IsFixedString(code) || code == msgpcode.Str8 || |
| 45 | + code == msgpcode.Str16 || code == msgpcode.Str32 |
| 46 | +} |
| 47 | + |
| 48 | +func (s *single) DecodeMsgpack(d *msgpack.Decoder) error { |
| 49 | + return s.decodeMsgpackImpl(&Decoder{d}) |
| 50 | +} |
| 51 | + |
| 52 | +func (space *Space) DecodeMsgpack(d *msgpack.Decoder) error { |
| 53 | + return space.decodeMsgpackImpl(&Decoder{d}) |
| 54 | +} |
| 55 | + |
| 56 | +func (field *Field) DecodeMsgpack(d *msgpack.Decoder) error { |
| 57 | + return field.decodeMsgpackImpl(&Decoder{d}) |
| 58 | +} |
| 59 | + |
| 60 | +func (index *Index) DecodeMsgpack(d *msgpack.Decoder) error { |
| 61 | + return index.decodeMsgpackImpl(&Decoder{d}) |
| 62 | +} |
| 63 | + |
| 64 | +func (indexField *IndexField) DecodeMsgpack(d *msgpack.Decoder) error { |
| 65 | + return indexField.decodeMsgpackImpl(&Decoder{d}) |
| 66 | +} |
| 67 | + |
| 68 | +func (meta *ColumnMetaData) DecodeMsgpack(d *msgpack.Decoder) error { |
| 69 | + return meta.decodeMsgpackImpl(&Decoder{d}) |
| 70 | +} |
| 71 | + |
| 72 | +func (info *SQLInfo) DecodeMsgpack(d *msgpack.Decoder) error { |
| 73 | + return info.decodeMsgpackImpl(&Decoder{d}) |
| 74 | +} |
| 75 | + |
| 76 | +func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error { |
| 77 | + return k.encodeMsgpackImpl(&Encoder{enc}) |
| 78 | +} |
| 79 | + |
| 80 | +func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error { |
| 81 | + return k.encodeMsgpackImpl(&Encoder{enc}) |
| 82 | +} |
| 83 | + |
| 84 | +func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error { |
| 85 | + return k.encodeMsgpackImpl(&Encoder{enc}) |
| 86 | +} |
| 87 | + |
| 88 | +func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error { |
| 89 | + return k.encodeMsgpackImpl(&Encoder{enc}) |
| 90 | +} |
| 91 | + |
| 92 | +func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error { |
| 93 | + return o.encodeMsgpackImpl(&Encoder{enc}) |
| 94 | +} |
| 95 | + |
| 96 | +func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error { |
| 97 | + return o.encodeMsgpackImpl(&Encoder{enc}) |
| 98 | +} |
0 commit comments