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
/
msg.rony.go
346 lines (280 loc) · 6.85 KB
/
msg.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package rony
import (
registry "github.com/ronaksoft/rony/registry"
proto "google.golang.org/protobuf/proto"
sync "sync"
)
const C_MessageEnvelope int64 = 535232465
type poolMessageEnvelope struct {
pool sync.Pool
}
func (p *poolMessageEnvelope) Get() *MessageEnvelope {
x, ok := p.pool.Get().(*MessageEnvelope)
if !ok {
return &MessageEnvelope{}
}
return x
}
func (p *poolMessageEnvelope) Put(x *MessageEnvelope) {
x.Constructor = 0
x.RequestID = 0
x.Message = x.Message[:0]
x.Auth = x.Auth[:0]
x.Header = x.Header[:0]
p.pool.Put(x)
}
var PoolMessageEnvelope = poolMessageEnvelope{}
const C_KeyValue int64 = 4276272820
type poolKeyValue struct {
pool sync.Pool
}
func (p *poolKeyValue) Get() *KeyValue {
x, ok := p.pool.Get().(*KeyValue)
if !ok {
return &KeyValue{}
}
return x
}
func (p *poolKeyValue) Put(x *KeyValue) {
x.Key = ""
x.Value = ""
p.pool.Put(x)
}
var PoolKeyValue = poolKeyValue{}
const C_MessageContainer int64 = 1972016308
type poolMessageContainer struct {
pool sync.Pool
}
func (p *poolMessageContainer) Get() *MessageContainer {
x, ok := p.pool.Get().(*MessageContainer)
if !ok {
return &MessageContainer{}
}
return x
}
func (p *poolMessageContainer) Put(x *MessageContainer) {
x.Length = 0
x.Envelopes = x.Envelopes[:0]
p.pool.Put(x)
}
var PoolMessageContainer = poolMessageContainer{}
const C_Error int64 = 2619118453
type poolError struct {
pool sync.Pool
}
func (p *poolError) Get() *Error {
x, ok := p.pool.Get().(*Error)
if !ok {
return &Error{}
}
return x
}
func (p *poolError) Put(x *Error) {
x.Code = ""
x.Items = ""
x.Template = ""
x.TemplateItems = x.TemplateItems[:0]
x.LocalTemplate = ""
x.LocalTemplateItems = x.LocalTemplateItems[:0]
p.pool.Put(x)
}
var PoolError = poolError{}
const C_Redirect int64 = 981138557
type poolRedirect struct {
pool sync.Pool
}
func (p *poolRedirect) Get() *Redirect {
x, ok := p.pool.Get().(*Redirect)
if !ok {
return &Redirect{}
}
return x
}
func (p *poolRedirect) Put(x *Redirect) {
x.Reason = 0
if x.Leader != nil {
PoolNodeInfo.Put(x.Leader)
x.Leader = nil
}
x.Followers = x.Followers[:0]
x.WaitInSec = 0
p.pool.Put(x)
}
var PoolRedirect = poolRedirect{}
const C_NodeInfo int64 = 2894317502
type poolNodeInfo struct {
pool sync.Pool
}
func (p *poolNodeInfo) Get() *NodeInfo {
x, ok := p.pool.Get().(*NodeInfo)
if !ok {
return &NodeInfo{}
}
return x
}
func (p *poolNodeInfo) Put(x *NodeInfo) {
x.ReplicaSet = 0
x.ServerID = ""
x.HostPorts = x.HostPorts[:0]
x.Leader = false
p.pool.Put(x)
}
var PoolNodeInfo = poolNodeInfo{}
const C_GetNodes int64 = 362407405
type poolGetNodes struct {
pool sync.Pool
}
func (p *poolGetNodes) Get() *GetNodes {
x, ok := p.pool.Get().(*GetNodes)
if !ok {
return &GetNodes{}
}
return x
}
func (p *poolGetNodes) Put(x *GetNodes) {
x.ReplicaSet = x.ReplicaSet[:0]
p.pool.Put(x)
}
var PoolGetNodes = poolGetNodes{}
const C_NodeInfoMany int64 = 1963715709
type poolNodeInfoMany struct {
pool sync.Pool
}
func (p *poolNodeInfoMany) Get() *NodeInfoMany {
x, ok := p.pool.Get().(*NodeInfoMany)
if !ok {
return &NodeInfoMany{}
}
return x
}
func (p *poolNodeInfoMany) Put(x *NodeInfoMany) {
x.Nodes = x.Nodes[:0]
p.pool.Put(x)
}
var PoolNodeInfoMany = poolNodeInfoMany{}
func init() {
registry.RegisterConstructor(535232465, "MessageEnvelope")
registry.RegisterConstructor(4276272820, "KeyValue")
registry.RegisterConstructor(1972016308, "MessageContainer")
registry.RegisterConstructor(2619118453, "Error")
registry.RegisterConstructor(981138557, "Redirect")
registry.RegisterConstructor(2894317502, "NodeInfo")
registry.RegisterConstructor(362407405, "GetNodes")
registry.RegisterConstructor(1963715709, "NodeInfoMany")
}
func (x *MessageEnvelope) DeepCopy(z *MessageEnvelope) {
z.Constructor = x.Constructor
z.RequestID = x.RequestID
z.Message = append(z.Message[:0], x.Message...)
z.Auth = append(z.Auth[:0], x.Auth...)
for idx := range x.Header {
if x.Header[idx] != nil {
xx := PoolKeyValue.Get()
x.Header[idx].DeepCopy(xx)
z.Header = append(z.Header, xx)
}
}
}
func (x *KeyValue) DeepCopy(z *KeyValue) {
z.Key = x.Key
z.Value = x.Value
}
func (x *MessageContainer) DeepCopy(z *MessageContainer) {
z.Length = x.Length
for idx := range x.Envelopes {
if x.Envelopes[idx] != nil {
xx := PoolMessageEnvelope.Get()
x.Envelopes[idx].DeepCopy(xx)
z.Envelopes = append(z.Envelopes, xx)
}
}
}
func (x *Error) DeepCopy(z *Error) {
z.Code = x.Code
z.Items = x.Items
z.Template = x.Template
z.TemplateItems = append(z.TemplateItems[:0], x.TemplateItems...)
z.LocalTemplate = x.LocalTemplate
z.LocalTemplateItems = append(z.LocalTemplateItems[:0], x.LocalTemplateItems...)
}
func (x *Redirect) DeepCopy(z *Redirect) {
z.Reason = x.Reason
if x.Leader != nil {
z.Leader = PoolNodeInfo.Get()
x.Leader.DeepCopy(z.Leader)
}
for idx := range x.Followers {
if x.Followers[idx] != nil {
xx := PoolNodeInfo.Get()
x.Followers[idx].DeepCopy(xx)
z.Followers = append(z.Followers, xx)
}
}
z.WaitInSec = x.WaitInSec
}
func (x *NodeInfo) DeepCopy(z *NodeInfo) {
z.ReplicaSet = x.ReplicaSet
z.ServerID = x.ServerID
z.HostPorts = append(z.HostPorts[:0], x.HostPorts...)
z.Leader = x.Leader
}
func (x *GetNodes) DeepCopy(z *GetNodes) {
z.ReplicaSet = append(z.ReplicaSet[:0], x.ReplicaSet...)
}
func (x *NodeInfoMany) DeepCopy(z *NodeInfoMany) {
for idx := range x.Nodes {
if x.Nodes[idx] != nil {
xx := PoolNodeInfo.Get()
x.Nodes[idx].DeepCopy(xx)
z.Nodes = append(z.Nodes, xx)
}
}
}
func (x *MessageEnvelope) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *KeyValue) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *MessageContainer) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *Error) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *Redirect) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *NodeInfo) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *GetNodes) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *NodeInfoMany) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *MessageEnvelope) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *KeyValue) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *MessageContainer) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *Error) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *Redirect) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *NodeInfo) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *GetNodes) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}
func (x *NodeInfoMany) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}