This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
imsg.rony.go
156 lines (130 loc) · 3.22 KB
/
imsg.rony.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package rony
import (
registry "github.com/ronaksoft/rony/registry"
proto "google.golang.org/protobuf/proto"
sync "sync"
)
const C_ClusterMessage int64 = 56353988
type poolClusterMessage struct {
pool sync.Pool
}
func (p *poolClusterMessage) Get() *ClusterMessage {
x, ok := p.pool.Get().(*ClusterMessage)
if !ok {
return &ClusterMessage{}
}
return x
}
func (p *poolClusterMessage) Put(x *ClusterMessage) {
x.Sender = x.Sender[:0]
x.Store = x.Store[:0]
if x.Envelope != nil {
PoolMessageEnvelope.Put(x.Envelope)
x.Envelope = nil
}
p.pool.Put(x)
}
var PoolClusterMessage = poolClusterMessage{}
const C_RaftCommand int64 = 3965951915
type poolRaftCommand struct {
pool sync.Pool
}
func (p *poolRaftCommand) Get() *RaftCommand {
x, ok := p.pool.Get().(*RaftCommand)
if !ok {
return &RaftCommand{}
}
return x
}
func (p *poolRaftCommand) Put(x *RaftCommand) {
x.Sender = x.Sender[:0]
x.Store = x.Store[:0]
if x.Envelope != nil {
PoolMessageEnvelope.Put(x.Envelope)
x.Envelope = nil
}
p.pool.Put(x)
}
var PoolRaftCommand = poolRaftCommand{}
const C_EdgeNode int64 = 2474233262
type poolEdgeNode struct {
pool sync.Pool
}
func (p *poolEdgeNode) Get() *EdgeNode {
x, ok := p.pool.Get().(*EdgeNode)
if !ok {
return &EdgeNode{}
}
return x
}
func (p *poolEdgeNode) Put(x *EdgeNode) {
x.ServerID = x.ServerID[:0]
x.ReplicaSet = 0
x.ShardRangeMin = 0
x.ShardRangeMax = 0
x.RaftPort = 0
x.RaftState = 0
x.GatewayAddr = x.GatewayAddr[:0]
p.pool.Put(x)
}
var PoolEdgeNode = poolEdgeNode{}
func init() {
registry.RegisterConstructor(56353988, "rony.ClusterMessage")
registry.RegisterConstructor(3965951915, "rony.RaftCommand")
registry.RegisterConstructor(2474233262, "rony.EdgeNode")
}
func (x *ClusterMessage) DeepCopy(z *ClusterMessage) {
z.Sender = append(z.Sender[:0], x.Sender...)
for idx := range x.Store {
if x.Store[idx] != nil {
xx := PoolKeyValue.Get()
x.Store[idx].DeepCopy(xx)
z.Store = append(z.Store, xx)
}
}
if x.Envelope != nil {
z.Envelope = PoolMessageEnvelope.Get()
x.Envelope.DeepCopy(z.Envelope)
}
}
func (x *RaftCommand) DeepCopy(z *RaftCommand) {
z.Sender = append(z.Sender[:0], x.Sender...)
for idx := range x.Store {
if x.Store[idx] != nil {
xx := PoolKeyValue.Get()
x.Store[idx].DeepCopy(xx)
z.Store = append(z.Store, xx)
}
}
if x.Envelope != nil {
z.Envelope = PoolMessageEnvelope.Get()
x.Envelope.DeepCopy(z.Envelope)
}
}
func (x *EdgeNode) DeepCopy(z *EdgeNode) {
z.ServerID = append(z.ServerID[:0], x.ServerID...)
z.ReplicaSet = x.ReplicaSet
z.ShardRangeMin = x.ShardRangeMin
z.ShardRangeMax = x.ShardRangeMax
z.RaftPort = x.RaftPort
z.RaftState = x.RaftState
z.GatewayAddr = append(z.GatewayAddr[:0], x.GatewayAddr...)
}
func (x *ClusterMessage) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *RaftCommand) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *EdgeNode) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *ClusterMessage) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *RaftCommand) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *EdgeNode) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}