-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathmodel_redis.go
104 lines (86 loc) · 2.04 KB
/
model_redis.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 模型来自pb
// 特别注意,lua只至此double,int64的数据如果进行cmsgpack打包解包可能出现精度问题导致bug
package antnet
import (
"github.com/golang/protobuf/proto"
"github.com/vmihailenco/msgpack"
)
type RedisModel struct{}
func (r *RedisModel) DBData(v proto.Message) []byte {
return DBData(v)
}
func (r *RedisModel) DBStr(v proto.Message) string {
return DBStr(v)
}
func (r *RedisModel) PbData(v proto.Message) []byte {
return PbData(v)
}
func (r *RedisModel) PbStr(v proto.Message) string {
return PbStr(v)
}
func (r *RedisModel) ParseDBData(data []byte, v proto.Message) bool {
return ParseDBData(data, v)
}
func (r *RedisModel) ParseDBStr(str string, v proto.Message) bool {
return ParseDBStr(str, v)
}
func (r *RedisModel) ParsePbData(data []byte, v proto.Message) bool {
return ParsePbData(data, v)
}
func (r *RedisModel) ParsePbStr(str string, v proto.Message) bool {
return ParsePbStr(str, v)
}
func DBData(v proto.Message) []byte {
data, err := msgpack.Marshal(v)
if err != nil {
LogError(err)
}
return data
}
func DBStr(v proto.Message) string {
data, err := msgpack.Marshal(v)
if err != nil {
LogError(err)
}
return string(data)
}
func PbData(v proto.Message) []byte {
data, err := proto.Marshal(v)
if err != nil {
LogError(err)
}
return data
}
func PbStr(v proto.Message) string {
data, err := proto.Marshal(v)
if err != nil {
LogError(err)
}
return string(data)
}
func ParseDBData(data []byte, v proto.Message) bool {
if err := msgpack.Unmarshal(data, v); err != nil {
return ParsePbData(data, v)
}
return true
}
func ParseDBStr(str string, v proto.Message) bool {
if err := msgpack.Unmarshal([]byte(str), v); err != nil {
return ParsePbStr(str, v)
}
return true
}
func ParsePbData(data []byte, v proto.Message) bool {
if err := proto.Unmarshal(data, v); err != nil {
LogError(err)
return false
}
return true
}
func ParsePbStr(str string, v proto.Message) bool {
if err := proto.Unmarshal([]byte(str), v); err != nil {
LogError(err)
return false
}
return true
}