Skip to content

Commit

Permalink
code health: replace EncodeUint64 by EncodeUint
Browse files Browse the repository at this point in the history
We use everywhere EncodeInt instead of EncodeInt64. Also we use
everywhere EncodeUint64 instead of EncodeUint. It can be confusing.

Although EncodeUint64 and EncodeUint have same logic in msgpack.v2, but
different in msgpack.v5. It's good for migration to msgpack.v5 too.

Part of #124.
  • Loading branch information
oleg-jukovec committed Aug 4, 2022
1 parent 00650f6 commit 3507ee3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ type Prepared struct {

func fillPrepare(enc *msgpack.Encoder, expr string) error {
enc.EncodeMapLen(1)
enc.EncodeUint64(KeySQLText)
enc.EncodeUint(KeySQLText)
return enc.EncodeString(expr)
}

func fillUnprepare(enc *msgpack.Encoder, stmt Prepared) error {
enc.EncodeMapLen(1)
enc.EncodeUint64(KeyStmtID)
return enc.EncodeUint64(uint64(stmt.StatementID))
enc.EncodeUint(KeyStmtID)
return enc.EncodeUint(uint(stmt.StatementID))
}

func fillExecutePrepared(enc *msgpack.Encoder, stmt Prepared, args interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint64(KeyStmtID)
enc.EncodeUint64(uint64(stmt.StatementID))
enc.EncodeUint64(KeySQLBind)
enc.EncodeUint(KeyStmtID)
enc.EncodeUint(uint(stmt.StatementID))
enc.EncodeUint(KeySQLBind)
return encodeSQLBind(enc, args)
}

Expand Down
50 changes: 25 additions & 25 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ import (
)

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

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

func fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint64(KeySpaceNo)
enc.EncodeUint64(uint64(spaceNo))
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeySpaceNo)
enc.EncodeUint(uint(spaceNo))
enc.EncodeUint(KeyTuple)
return enc.Encode(tuple)
}

Expand All @@ -47,19 +47,19 @@ func fillUpdate(enc *msgpack.Encoder, spaceNo, indexNo uint32, key, ops interfac
if err := fillSearch(enc, spaceNo, indexNo, key); err != nil {
return err
}
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeyTuple)
return enc.Encode(ops)
}

func fillUpsert(enc *msgpack.Encoder, spaceNo uint32, tuple, ops interface{}) error {
enc.EncodeMapLen(3)
enc.EncodeUint64(KeySpaceNo)
enc.EncodeUint64(uint64(spaceNo))
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeySpaceNo)
enc.EncodeUint(uint(spaceNo))
enc.EncodeUint(KeyTuple)
if err := enc.Encode(tuple); err != nil {
return err
}
enc.EncodeUint64(KeyDefTuple)
enc.EncodeUint(KeyDefTuple)
return enc.Encode(ops)
}

Expand All @@ -70,25 +70,25 @@ func fillDelete(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{})

func fillCall(enc *msgpack.Encoder, functionName string, args interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint64(KeyFunctionName)
enc.EncodeUint(KeyFunctionName)
enc.EncodeString(functionName)
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeyTuple)
return enc.Encode(args)
}

func fillEval(enc *msgpack.Encoder, expr string, args interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint64(KeyExpression)
enc.EncodeUint(KeyExpression)
enc.EncodeString(expr)
enc.EncodeUint64(KeyTuple)
enc.EncodeUint(KeyTuple)
return enc.Encode(args)
}

func fillExecute(enc *msgpack.Encoder, expr string, args interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint64(KeySQLText)
enc.EncodeUint(KeySQLText)
enc.EncodeString(expr)
enc.EncodeUint64(KeySQLBind)
enc.EncodeUint(KeySQLBind)
return encodeSQLBind(enc, args)
}

Expand Down
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func fillBegin(enc *msgpack.Encoder, txnIsolation TxnIsolationLevel, timeout tim
}

if hasTimeout {
err = enc.EncodeUint64(KeyTimeout)
err = enc.EncodeUint(KeyTimeout)
if err != nil {
return err
}
Expand Down

0 comments on commit 3507ee3

Please sign in to comment.