Skip to content

Commit

Permalink
migration: Wrap EncodeUint/EncodeInt
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-jukovec committed May 19, 2022
1 parent 6727c41 commit b5f204a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 37 deletions.
16 changes: 8 additions & 8 deletions client_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type IntKey struct {

func (k IntKey) encodeMsgpackImpl(enc *Encoder) error {
enc.EncodeArrayLen(1)
enc.EncodeInt(k.I)
enc.encodeIntImpl(int64(k.I))
return nil
}

Expand All @@ -20,7 +20,7 @@ type UintKey struct {

func (k UintKey) encodeMsgpackImpl(enc *Encoder) error {
enc.EncodeArrayLen(1)
enc.EncodeUint(k.I)
enc.encodeUintImpl(uint64(k.I))
return nil
}

Expand All @@ -44,8 +44,8 @@ type IntIntKey struct {

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

Expand All @@ -59,7 +59,7 @@ type Op struct {
func (o Op) encodeMsgpackImpl(enc *Encoder) error {
enc.EncodeArrayLen(3)
enc.EncodeString(o.Op)
enc.EncodeInt(o.Field)
enc.encodeIntImpl(int64(o.Field))
return enc.Encode(o.Arg)
}

Expand All @@ -74,9 +74,9 @@ type OpSplice struct {
func (o OpSplice) encodeMsgpackImpl(enc *Encoder) error {
enc.EncodeArrayLen(5)
enc.EncodeString(o.Op)
enc.EncodeInt(o.Field)
enc.EncodeInt(o.Pos)
enc.EncodeInt(o.Len)
enc.encodeIntImpl(int64(o.Field))
enc.encodeIntImpl(int64(o.Pos))
enc.encodeIntImpl(int64(o.Len))
enc.EncodeString(o.Replace)
return nil
}
2 changes: 1 addition & 1 deletion example_custom_unpacking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c *Tuple2) encodeMsgpackImpl(e *tarantool.Encoder) error {
if err := e.EncodeArrayLen(3); err != nil {
return err
}
if err := e.EncodeUint(c.Cid); err != nil {
if err := e.EncodeUintImpl(uint64(c.Cid)); err != nil {
return err
}
if err := e.EncodeString(c.Orig); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ package tarantool
func (schema *Schema) ResolveSpaceIndex(s interface{}, i interface{}) (spaceNo, indexNo uint32, err error) {
return schema.resolveSpaceIndex(s, i)
}

func (e *Encoder) EncodeUintImpl(v uint64) error {
return e.encodeUintImpl(v)
}

func (e *Encoder) EncodeIntImpl(v int64) error {
return e.encodeIntImpl(v)
}
8 changes: 8 additions & 0 deletions msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ func newDecoder(r io.Reader) *Decoder {
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 ||
Expand Down
54 changes: 27 additions & 27 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ func (conn *Connection) Ping() (resp *Response, err error) {
}

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

func (req *Future) fillIterator(enc *Encoder, offset, limit, iterator uint32) {
enc.EncodeUint(KeyIterator)
enc.EncodeUint(uint(iterator))
enc.EncodeUint(KeyOffset)
enc.EncodeUint(uint(offset))
enc.EncodeUint(KeyLimit)
enc.EncodeUint(uint(limit))
enc.encodeUintImpl(KeyIterator)
enc.encodeUintImpl(uint64(iterator))
enc.encodeUintImpl(KeyOffset)
enc.encodeUintImpl(uint64(offset))
enc.encodeUintImpl(KeyLimit)
enc.encodeUintImpl(uint64(limit))
}

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

Expand Down Expand Up @@ -300,7 +300,7 @@ func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface
if err := future.fillSearch(enc, spaceNo, indexNo, key); err != nil {
return err
}
enc.EncodeUint(KeyTuple)
enc.encodeUintImpl(KeyTuple)
return enc.Encode(ops)
})
}
Expand All @@ -315,13 +315,13 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in
}
return future.send(conn, func(enc *Encoder) error {
enc.EncodeMapLen(3)
enc.EncodeUint(KeySpaceNo)
enc.EncodeUint(uint(spaceNo))
enc.EncodeUint(KeyTuple)
enc.encodeUintImpl(KeySpaceNo)
enc.encodeUintImpl(uint64(spaceNo))
enc.encodeUintImpl(KeyTuple)
if err := enc.Encode(tuple); err != nil {
return err
}
enc.EncodeUint(KeyDefTuple)
enc.encodeUintImpl(KeyDefTuple)
return enc.Encode(ops)
})
}
Expand All @@ -332,9 +332,9 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future
future := conn.newFuture(CallRequest)
return future.send(conn, func(enc *Encoder) error {
enc.EncodeMapLen(2)
enc.EncodeUint(KeyFunctionName)
enc.encodeUintImpl(KeyFunctionName)
enc.EncodeString(functionName)
enc.EncodeUint(KeyTuple)
enc.encodeUintImpl(KeyTuple)
return enc.Encode(args)
})
}
Expand All @@ -346,9 +346,9 @@ func (conn *Connection) Call17Async(functionName string, args interface{}) *Futu
future := conn.newFuture(Call17Request)
return future.send(conn, func(enc *Encoder) error {
enc.EncodeMapLen(2)
enc.EncodeUint(KeyFunctionName)
enc.encodeUintImpl(KeyFunctionName)
enc.EncodeString(functionName)
enc.EncodeUint(KeyTuple)
enc.encodeUintImpl(KeyTuple)
return enc.Encode(args)
})
}
Expand All @@ -358,9 +358,9 @@ func (conn *Connection) EvalAsync(expr string, args interface{}) *Future {
future := conn.newFuture(EvalRequest)
return future.send(conn, func(enc *Encoder) error {
enc.EncodeMapLen(2)
enc.EncodeUint(KeyExpression)
enc.encodeUintImpl(KeyExpression)
enc.EncodeString(expr)
enc.EncodeUint(KeyTuple)
enc.encodeUintImpl(KeyTuple)
return enc.Encode(args)
})
}
Expand All @@ -371,9 +371,9 @@ func (conn *Connection) ExecuteAsync(expr string, args interface{}) *Future {
future := conn.newFuture(ExecuteRequest)
return future.send(conn, func(enc *Encoder) error {
enc.EncodeMapLen(2)
enc.EncodeUint(KeySQLText)
enc.encodeUintImpl(KeySQLText)
enc.EncodeString(expr)
enc.EncodeUint(KeySQLBind)
enc.encodeUintImpl(KeySQLBind)
return encodeSQLBind(enc, args)
})
}
Expand Down
2 changes: 1 addition & 1 deletion tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (m *Member) encodeMsgpackImpl(e *Encoder) error {
if err := e.EncodeString(m.Name); err != nil {
return err
}
if err := e.EncodeUint(m.Val); err != nil {
if err := e.EncodeUintImpl(uint64(m.Val)); err != nil {
return err
}
return nil
Expand Down

0 comments on commit b5f204a

Please sign in to comment.