summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/caches/encode.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/xorm.io/xorm/caches/encode.go')
-rw-r--r--vendor/xorm.io/xorm/caches/encode.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/vendor/xorm.io/xorm/caches/encode.go b/vendor/xorm.io/xorm/caches/encode.go
index 4ba39924a5..95536d7e54 100644
--- a/vendor/xorm.io/xorm/caches/encode.go
+++ b/vendor/xorm.io/xorm/caches/encode.go
@@ -13,22 +13,26 @@ import (
"io"
)
-// md5 hash string
+// Md5 return md5 hash string
func Md5(str string) string {
m := md5.New()
io.WriteString(m, str)
return fmt.Sprintf("%x", m.Sum(nil))
}
+
+// Encode Encode data
func Encode(data interface{}) ([]byte, error) {
//return JsonEncode(data)
return GobEncode(data)
}
+// Decode decode data
func Decode(data []byte, to interface{}) error {
//return JsonDecode(data, to)
return GobDecode(data, to)
}
+// GobEncode encode data with gob
func GobEncode(data interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
@@ -39,12 +43,14 @@ func GobEncode(data interface{}) ([]byte, error) {
return buf.Bytes(), nil
}
+// GobDecode decode data with gob
func GobDecode(data []byte, to interface{}) error {
buf := bytes.NewBuffer(data)
dec := gob.NewDecoder(buf)
return dec.Decode(to)
}
+// JsonEncode encode data with json
func JsonEncode(data interface{}) ([]byte, error) {
val, err := json.Marshal(data)
if err != nil {
@@ -53,6 +59,7 @@ func JsonEncode(data interface{}) ([]byte, error) {
return val, nil
}
+// JsonDecode decode data with json
func JsonDecode(data []byte, to interface{}) error {
return json.Unmarshal(data, to)
}