support multi transaction

This commit is contained in:
hdt3213
2021-05-31 21:20:33 +08:00
parent 9d03314359
commit 67c385ee4a
50 changed files with 1919 additions and 1122 deletions

48
lib/utils/utils.go Normal file
View File

@@ -0,0 +1,48 @@
package utils
// ToCmdLine convert strings to [][]byte
func ToCmdLine(cmd ...string) [][]byte {
args := make([][]byte, len(cmd))
for i, s := range cmd {
args[i] = []byte(s)
}
return args
}
func ToCmdLine2(commandName string, args ...string) [][]byte {
result := make([][]byte, len(args)+1)
result[0] = []byte(commandName)
for i, s := range args {
result[i+1] = []byte(s)
}
return result
}
// Equals check whether the given value is equal
func Equals(a interface{}, b interface{}) bool {
sliceA, okA := a.([]byte)
sliceB, okB := b.([]byte)
if okA && okB {
return BytesEquals(sliceA, sliceB)
}
return a == b
}
// BytesEquals check whether the given bytes is equal
func BytesEquals(a []byte, b []byte) bool {
if (a == nil && b != nil) || (a != nil && b == nil) {
return false
}
if len(a) != len(b) {
return false
}
size := len(a)
for i := 0; i < size; i++ {
av := a[i]
bv := b[i]
if av != bv {
return false
}
}
return true
}