/
obj.go
65 lines (55 loc) · 1 KB
/
obj.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Created: 2020/3/25
* @author: Jason
*/
package common
import (
"github.com/json-iterator/go"
"github.com/lightning-go/lightning/utils"
"bytes"
"compress/zlib"
"io"
)
const (
ST_NIL = iota
ST_GATE
ST_LOGIC
ST_CENTER
ST_FIGHT
ST_MAX
)
const (
GateKey = "helloGateo3@#^34Sdsdfj@5"
LogicKey = "helloLogic*&12@$sdlkl$sdf"
)
const (
ETCD_LOGIC_PATH = "/game/logic"
ETCD_GATE_PATH = "/game/gate"
)
func MarshalDataEx(v interface{}) []byte {
d, err := jsoniter.Marshal(v)
if err != nil || d == nil {
return utils.NullData
}
return d
}
func MarshalData(v interface{}) ([]byte, error) {
return jsoniter.Marshal(v)
}
func Unmarshal(data []byte, v interface{}) error {
return jsoniter.Unmarshal(data, v)
}
func ZlibCompress(src []byte) []byte {
var in bytes.Buffer
w := zlib.NewWriter(&in)
w.Write(src)
w.Close()
return in.Bytes()
}
func ZlibUnCompress(src []byte) []byte {
b := bytes.NewReader(src)
var out bytes.Buffer
r, _ := zlib.NewReader(b)
io.Copy(&out, r)
return out.Bytes()
}