1#[derive(Debug, PartialEq, Copy, Clone)]
18pub enum RemotingSysResponseCode {
19 Success = 0,
20 SystemError = 1,
21 SystemBusy = 2,
22 RequestCodeNotSupported = 3,
23 TransactionFailed = 4,
24 NoPermission = 16,
25}
26
27impl From<RemotingSysResponseCode> for i32 {
28 #[inline]
29 fn from(value: RemotingSysResponseCode) -> Self {
30 value as i32
31 }
32}
33
34impl From<i32> for RemotingSysResponseCode {
35 fn from(value: i32) -> Self {
36 match value {
37 0 => RemotingSysResponseCode::Success,
38 1 => RemotingSysResponseCode::SystemError,
39 2 => RemotingSysResponseCode::SystemBusy,
40 3 => RemotingSysResponseCode::RequestCodeNotSupported,
41 4 => RemotingSysResponseCode::TransactionFailed,
42 16 => RemotingSysResponseCode::NoPermission,
43 _ => RemotingSysResponseCode::SystemError,
44 }
45 }
46}
47
48#[derive(Debug, PartialEq, Copy, Clone)]
49pub enum ResponseCode {
50 Success = 0,
51 SystemError = 1,
52 SystemBusy = 2,
53 RequestCodeNotSupported = 3,
54 TransactionFailed = 4,
55 FlushDiskTimeout = 10,
56 SlaveNotAvailable = 11,
57 FlushSlaveTimeout = 12,
58 MessageIllegal = 13,
59 ServiceNotAvailable = 14,
60 VersionNotSupported = 15,
61 NoPermission = 16,
62 TopicNotExist = 17,
63 TopicExistAlready = 18,
64 PullNotFound = 19,
65 PullRetryImmediately = 20,
66 PullOffsetMoved = 21,
67 QueryNotFound = 22,
68 SubscriptionParseFailed = 23,
69 SubscriptionNotExist = 24,
70 SubscriptionNotLatest = 25,
71 SubscriptionGroupNotExist = 26,
72 FilterDataNotExist = 27,
73 FilterDataNotLatest = 28,
74 TransactionShouldCommit = 200,
75 TransactionShouldRollback = 201,
76 TransactionStateUnknow = 202,
77 TransactionStateGroupWrong = 203,
78 NoBuyerId = 204,
79 NotInCurrentUnit = 205,
80 ConsumerNotOnline = 206,
81 ConsumeMsgTimeout = 207,
82 NoMessage = 208,
83 PollingFull = 209,
87 PollingTimeout = 210,
88 BrokerNotExist = 211,
89 BrokerDispatchNotComplete = 212,
90 BroadcastConsumption = 213,
91 FlowControl = 215,
92 NotLeaderForQueue = 501,
93 IllegalOperation = 604,
94 RpcUnknown = -1000,
95 RpcAddrIsNull = -1002,
96 RpcSendToChannelFailed = -1004,
97 RpcTimeOut = -1006,
98 GoAway = 1500,
99 ControllerFencedMasterEpoch = 2000,
100 ControllerFencedSyncStateSetEpoch = 2001,
101 ControllerInvalidMaster = 2002,
102 ControllerInvalidReplicas = 2003,
103 ControllerMasterNotAvailable = 2004,
104 ControllerInvalidRequest = 2005,
105 ControllerBrokerNotAlive = 2006,
106 ControllerNotLeader = 2007,
107 ControllerBrokerMetadataNotExist = 2008,
108 ControllerInvalidCleanBrokerMetadata = 2009,
109 ControllerBrokerNeedToBeRegistered = 2010,
110 ControllerMasterStillExist = 2011,
111 ControllerElectMasterFailed = 2012,
112 ControllerAlterSyncStateSetFailed = 2013,
113 ControllerBrokerIdInvalid = 2014,
114}
115
116impl From<ResponseCode> for i32 {
117 fn from(value: ResponseCode) -> Self {
118 value as i32
119 }
120}
121
122impl From<i32> for ResponseCode {
123 fn from(value: i32) -> Self {
124 match value {
125 0 => ResponseCode::Success,
126 1 => ResponseCode::SystemError,
127 2 => ResponseCode::SystemBusy,
128 3 => ResponseCode::RequestCodeNotSupported,
129 4 => ResponseCode::TransactionFailed,
130 10 => ResponseCode::FlushDiskTimeout,
131 11 => ResponseCode::SlaveNotAvailable,
132 12 => ResponseCode::FlushSlaveTimeout,
133 13 => ResponseCode::MessageIllegal,
134 14 => ResponseCode::ServiceNotAvailable,
135 15 => ResponseCode::VersionNotSupported,
136 16 => ResponseCode::NoPermission,
137 17 => ResponseCode::TopicNotExist,
138 18 => ResponseCode::TopicExistAlready,
139 19 => ResponseCode::PullNotFound,
140 20 => ResponseCode::PullRetryImmediately,
141 21 => ResponseCode::PullOffsetMoved,
142 22 => ResponseCode::QueryNotFound,
143 23 => ResponseCode::SubscriptionParseFailed,
144 24 => ResponseCode::SubscriptionNotExist,
145 25 => ResponseCode::SubscriptionNotLatest,
146 26 => ResponseCode::SubscriptionGroupNotExist,
147 27 => ResponseCode::FilterDataNotExist,
148 28 => ResponseCode::FilterDataNotLatest,
149 200 => ResponseCode::TransactionShouldCommit,
150 201 => ResponseCode::TransactionShouldRollback,
151 202 => ResponseCode::TransactionStateUnknow,
152 203 => ResponseCode::TransactionStateGroupWrong,
153 204 => ResponseCode::NoBuyerId,
154 205 => ResponseCode::NotInCurrentUnit,
155 206 => ResponseCode::ConsumerNotOnline,
156 207 => ResponseCode::ConsumeMsgTimeout,
157 208 => ResponseCode::NoMessage,
158 209 => ResponseCode::PollingFull,
159 210 => ResponseCode::PollingTimeout,
160 211 => ResponseCode::BrokerNotExist,
161 212 => ResponseCode::BrokerDispatchNotComplete,
162 213 => ResponseCode::BroadcastConsumption,
163 215 => ResponseCode::FlowControl,
164 501 => ResponseCode::NotLeaderForQueue,
165 604 => ResponseCode::IllegalOperation,
166 -1000 => ResponseCode::RpcUnknown,
167 -1002 => ResponseCode::RpcAddrIsNull,
168 -1004 => ResponseCode::RpcSendToChannelFailed,
169 -1006 => ResponseCode::RpcTimeOut,
170 1500 => ResponseCode::GoAway,
171 2000 => ResponseCode::ControllerFencedMasterEpoch,
172 2001 => ResponseCode::ControllerFencedSyncStateSetEpoch,
173 2002 => ResponseCode::ControllerInvalidMaster,
174 2003 => ResponseCode::ControllerInvalidReplicas,
175 2004 => ResponseCode::ControllerMasterNotAvailable,
176 2005 => ResponseCode::ControllerInvalidRequest,
177 2006 => ResponseCode::ControllerBrokerNotAlive,
178 2007 => ResponseCode::ControllerNotLeader,
179 2008 => ResponseCode::ControllerBrokerMetadataNotExist,
180 2009 => ResponseCode::ControllerInvalidCleanBrokerMetadata,
181 2010 => ResponseCode::ControllerBrokerNeedToBeRegistered,
182 2011 => ResponseCode::ControllerMasterStillExist,
183 2012 => ResponseCode::ControllerElectMasterFailed,
184 2013 => ResponseCode::ControllerAlterSyncStateSetFailed,
185 2014 => ResponseCode::ControllerBrokerIdInvalid,
186 _ => ResponseCode::SystemError,
187 }
188 }
189}
190
191#[cfg(test)]
192mod tests {
193 use super::*;
194
195 #[test]
196 fn remoting_sys_response_code_from_i32() {
197 assert_eq!(
198 RemotingSysResponseCode::from(0),
199 RemotingSysResponseCode::Success
200 );
201 assert_eq!(
202 RemotingSysResponseCode::from(1),
203 RemotingSysResponseCode::SystemError
204 );
205 assert_eq!(
206 RemotingSysResponseCode::from(2),
207 RemotingSysResponseCode::SystemBusy
208 );
209 assert_eq!(
210 RemotingSysResponseCode::from(3),
211 RemotingSysResponseCode::RequestCodeNotSupported
212 );
213 assert_eq!(
214 RemotingSysResponseCode::from(4),
215 RemotingSysResponseCode::TransactionFailed
216 );
217 assert_eq!(
218 RemotingSysResponseCode::from(999),
219 RemotingSysResponseCode::SystemError
220 ); }
222
223 #[test]
224 fn response_code_from_i32() {
225 assert_eq!(ResponseCode::from(0), ResponseCode::Success);
226 assert_eq!(ResponseCode::from(1), ResponseCode::SystemError);
227 assert_eq!(ResponseCode::from(2), ResponseCode::SystemBusy);
228 assert_eq!(ResponseCode::from(3), ResponseCode::RequestCodeNotSupported);
229 assert_eq!(ResponseCode::from(4), ResponseCode::TransactionFailed);
230 assert_eq!(ResponseCode::from(10), ResponseCode::FlushDiskTimeout);
231 assert_eq!(ResponseCode::from(11), ResponseCode::SlaveNotAvailable);
232 assert_eq!(ResponseCode::from(12), ResponseCode::FlushSlaveTimeout);
233 assert_eq!(ResponseCode::from(13), ResponseCode::MessageIllegal);
234 assert_eq!(ResponseCode::from(14), ResponseCode::ServiceNotAvailable);
235 assert_eq!(ResponseCode::from(15), ResponseCode::VersionNotSupported);
236 assert_eq!(ResponseCode::from(16), ResponseCode::NoPermission);
237 assert_eq!(ResponseCode::from(17), ResponseCode::TopicNotExist);
238 assert_eq!(ResponseCode::from(18), ResponseCode::TopicExistAlready);
239 assert_eq!(ResponseCode::from(19), ResponseCode::PullNotFound);
240 assert_eq!(ResponseCode::from(20), ResponseCode::PullRetryImmediately);
241 assert_eq!(ResponseCode::from(21), ResponseCode::PullOffsetMoved);
242 assert_eq!(ResponseCode::from(22), ResponseCode::QueryNotFound);
243 assert_eq!(
244 ResponseCode::from(23),
245 ResponseCode::SubscriptionParseFailed
246 );
247 assert_eq!(ResponseCode::from(24), ResponseCode::SubscriptionNotExist);
248 assert_eq!(ResponseCode::from(25), ResponseCode::SubscriptionNotLatest);
249 assert_eq!(
250 ResponseCode::from(26),
251 ResponseCode::SubscriptionGroupNotExist
252 );
253 assert_eq!(ResponseCode::from(27), ResponseCode::FilterDataNotExist);
254 assert_eq!(ResponseCode::from(28), ResponseCode::FilterDataNotLatest);
255 assert_eq!(
256 ResponseCode::from(200),
257 ResponseCode::TransactionShouldCommit
258 );
259 assert_eq!(
260 ResponseCode::from(201),
261 ResponseCode::TransactionShouldRollback
262 );
263 assert_eq!(
264 ResponseCode::from(202),
265 ResponseCode::TransactionStateUnknow
266 );
267 assert_eq!(
268 ResponseCode::from(203),
269 ResponseCode::TransactionStateGroupWrong
270 );
271 assert_eq!(ResponseCode::from(204), ResponseCode::NoBuyerId);
272 assert_eq!(ResponseCode::from(205), ResponseCode::NotInCurrentUnit);
273 assert_eq!(ResponseCode::from(206), ResponseCode::ConsumerNotOnline);
274 assert_eq!(ResponseCode::from(207), ResponseCode::ConsumeMsgTimeout);
275 assert_eq!(ResponseCode::from(208), ResponseCode::NoMessage);
276 assert_eq!(ResponseCode::from(209), ResponseCode::PollingFull);
277 assert_eq!(ResponseCode::from(210), ResponseCode::PollingTimeout);
278 assert_eq!(ResponseCode::from(211), ResponseCode::BrokerNotExist);
279 assert_eq!(
280 ResponseCode::from(212),
281 ResponseCode::BrokerDispatchNotComplete
282 );
283 assert_eq!(ResponseCode::from(213), ResponseCode::BroadcastConsumption);
284 assert_eq!(ResponseCode::from(215), ResponseCode::FlowControl);
285 assert_eq!(ResponseCode::from(501), ResponseCode::NotLeaderForQueue);
286 assert_eq!(ResponseCode::from(604), ResponseCode::IllegalOperation);
287 assert_eq!(ResponseCode::from(-1000), ResponseCode::RpcUnknown);
288 assert_eq!(ResponseCode::from(-1002), ResponseCode::RpcAddrIsNull);
289 assert_eq!(
290 ResponseCode::from(-1004),
291 ResponseCode::RpcSendToChannelFailed
292 );
293 assert_eq!(ResponseCode::from(-1006), ResponseCode::RpcTimeOut);
294 assert_eq!(ResponseCode::from(1500), ResponseCode::GoAway);
295 assert_eq!(
296 ResponseCode::from(2000),
297 ResponseCode::ControllerFencedMasterEpoch
298 );
299 assert_eq!(
300 ResponseCode::from(2001),
301 ResponseCode::ControllerFencedSyncStateSetEpoch
302 );
303 assert_eq!(
304 ResponseCode::from(2002),
305 ResponseCode::ControllerInvalidMaster
306 );
307 assert_eq!(
308 ResponseCode::from(2003),
309 ResponseCode::ControllerInvalidReplicas
310 );
311 assert_eq!(
312 ResponseCode::from(2004),
313 ResponseCode::ControllerMasterNotAvailable
314 );
315 assert_eq!(
316 ResponseCode::from(2005),
317 ResponseCode::ControllerInvalidRequest
318 );
319 assert_eq!(
320 ResponseCode::from(2006),
321 ResponseCode::ControllerBrokerNotAlive
322 );
323 assert_eq!(ResponseCode::from(2007), ResponseCode::ControllerNotLeader);
324 assert_eq!(
325 ResponseCode::from(2008),
326 ResponseCode::ControllerBrokerMetadataNotExist
327 );
328 assert_eq!(
329 ResponseCode::from(2009),
330 ResponseCode::ControllerInvalidCleanBrokerMetadata
331 );
332 assert_eq!(
333 ResponseCode::from(2010),
334 ResponseCode::ControllerBrokerNeedToBeRegistered
335 );
336 assert_eq!(
337 ResponseCode::from(2011),
338 ResponseCode::ControllerMasterStillExist
339 );
340 assert_eq!(
341 ResponseCode::from(2012),
342 ResponseCode::ControllerElectMasterFailed
343 );
344 assert_eq!(
345 ResponseCode::from(2013),
346 ResponseCode::ControllerAlterSyncStateSetFailed
347 );
348 assert_eq!(
349 ResponseCode::from(2014),
350 ResponseCode::ControllerBrokerIdInvalid
351 );
352 assert_eq!(ResponseCode::from(9999), ResponseCode::SystemError); }
354}