mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func marshalKey(vals ...int64) []byte {
|
||||
b := strconv.AppendInt(nil, vals[0], 10)
|
||||
for _, v := range vals[1:] {
|
||||
b = append(b, ':')
|
||||
b = strconv.AppendInt(b, v, 10)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func unmarshalKey(text []byte, name string, n int) ([]int64, error) {
|
||||
parts := strings.Split(string(text), ":")
|
||||
if len(parts) != n {
|
||||
return nil, fmt.Errorf("invalid %s: %s", name, text)
|
||||
}
|
||||
out := make([]int64, n)
|
||||
for i, p := range parts {
|
||||
v, err := strconv.ParseInt(p, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out[i] = v
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user