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
220 lines (178 loc) · 4.49 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
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_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.LeaderHostPort = x.LeaderHostPort[:0]
x.HostPorts = x.HostPorts[:0]
x.ServerID = ""
x.WaitInSec = 0
p.pool.Put(x)
}
var PoolRedirect = poolRedirect{}
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{}
func init() {
registry.RegisterConstructor(535232465, "MessageEnvelope")
registry.RegisterConstructor(1972016308, "MessageContainer")
registry.RegisterConstructor(2619118453, "Error")
registry.RegisterConstructor(981138557, "Redirect")
registry.RegisterConstructor(4276272820, "KeyValue")
}
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 *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.LeaderHostPort = append(z.LeaderHostPort[:0], x.LeaderHostPort...)
z.HostPorts = append(z.HostPorts[:0], x.HostPorts...)
z.ServerID = x.ServerID
z.WaitInSec = x.WaitInSec
}
func (x *KeyValue) DeepCopy(z *KeyValue) {
z.Key = x.Key
z.Value = x.Value
}
func (x *MessageEnvelope) 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 *KeyValue) Marshal() ([]byte, error) {
return proto.Marshal(x)
}
func (x *MessageEnvelope) 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 *KeyValue) Unmarshal(b []byte) error {
return proto.UnmarshalOptions{}.Unmarshal(b, x)
}