1pub mod metadata {
3 use super::*;
4
5 pub const NAME: &str = "AMQP";
7 pub const MAJOR_VERSION: ShortShortUInt = 0;
9 pub const MINOR_VERSION: ShortShortUInt = 9;
11 pub const REVISION: ShortShortUInt = 1;
13 pub const PORT: LongUInt = 5672;
15 pub const COPYRIGHT: &str = r#"Copyright (C) 2007-2024 Broadcom Inc. and its subsidiaries. All rights reserved.
17
18Permission is hereby granted, free of charge, to any person
19obtaining a copy of this file (the "Software"), to deal in the
20Software without restriction, including without limitation the
21rights to use, copy, modify, merge, publish, distribute,
22sublicense, and/or sell copies of the Software, and to permit
23persons to whom the Software is furnished to do so, subject to
24the following conditions:
25
26The above copyright notice and this permission notice shall be
27included in all copies or substantial portions of the Software.
28
29THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
31OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36OTHER DEALINGS IN THE SOFTWARE.
37
38Class information entered from amqp_xml0-8.pdf and domain types from amqp-xml-doc0-9.pdf
39Updated for 0-9-1 by Tony Garnock-Jones
40
41b3cb053f15e7b98808c0ccc67f23cb3e amqp_xml0-8.pdf
42http://twiststandards.org/?option=com_docman&task=cat_view&gid=28&Itemid=90
438444db91e2949dbecfb2585e9eef6d64 amqp-xml-doc0-9.pdf
44https://jira.amqp.org/confluence/download/attachments/720900/amqp-xml-doc0-9.pdf?version=1
45"#;
46}
47
48pub mod constants {
50 use super::*;
51
52 pub const FRAME_METHOD: ShortShortUInt = 1;
54 pub const FRAME_HEADER: ShortShortUInt = 2;
56 pub const FRAME_BODY: ShortShortUInt = 3;
58 pub const FRAME_HEARTBEAT: ShortShortUInt = 8;
60 pub const FRAME_MIN_SIZE: LongUInt = 8192;
62 pub const FRAME_END: ShortShortUInt = 206;
64 pub const REPLY_SUCCESS: ShortUInt = 200;
66}
67
68#[derive(Clone, Debug, PartialEq)]
70pub enum AMQPSoftError {
71 CONTENTTOOLARGE,
73 NOROUTE,
75 NOCONSUMERS,
77 ACCESSREFUSED,
79 NOTFOUND,
81 RESOURCELOCKED,
83 PRECONDITIONFAILED,
85}
86
87impl AMQPSoftError {
88 pub fn get_id(&self) -> Identifier {
90 match *self {
91 AMQPSoftError::CONTENTTOOLARGE => 311,
92 AMQPSoftError::NOROUTE => 312,
93 AMQPSoftError::NOCONSUMERS => 313,
94 AMQPSoftError::ACCESSREFUSED => 403,
95 AMQPSoftError::NOTFOUND => 404,
96 AMQPSoftError::RESOURCELOCKED => 405,
97 AMQPSoftError::PRECONDITIONFAILED => 406,
98 }
99 }
100
101 pub fn from_id(id: Identifier) -> Option<AMQPSoftError> {
103 match id {
104 311 => Some(AMQPSoftError::CONTENTTOOLARGE),
105 312 => Some(AMQPSoftError::NOROUTE),
106 313 => Some(AMQPSoftError::NOCONSUMERS),
107 403 => Some(AMQPSoftError::ACCESSREFUSED),
108 404 => Some(AMQPSoftError::NOTFOUND),
109 405 => Some(AMQPSoftError::RESOURCELOCKED),
110 406 => Some(AMQPSoftError::PRECONDITIONFAILED),
111 _ => None,
112 }
113 }
114}
115
116impl fmt::Display for AMQPSoftError {
117 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118 match self {
119 AMQPSoftError::CONTENTTOOLARGE => write!(f, "CONTENT-TOO-LARGE"),
120 AMQPSoftError::NOROUTE => write!(f, "NO-ROUTE"),
121 AMQPSoftError::NOCONSUMERS => write!(f, "NO-CONSUMERS"),
122 AMQPSoftError::ACCESSREFUSED => write!(f, "ACCESS-REFUSED"),
123 AMQPSoftError::NOTFOUND => write!(f, "NOT-FOUND"),
124 AMQPSoftError::RESOURCELOCKED => write!(f, "RESOURCE-LOCKED"),
125 AMQPSoftError::PRECONDITIONFAILED => write!(f, "PRECONDITION-FAILED"),
126 }
127 }
128}
129
130#[derive(Clone, Debug, PartialEq)]
132pub enum AMQPHardError {
133 CONNECTIONFORCED,
135 INVALIDPATH,
137 FRAMEERROR,
139 SYNTAXERROR,
141 COMMANDINVALID,
143 CHANNELERROR,
145 UNEXPECTEDFRAME,
147 RESOURCEERROR,
149 NOTALLOWED,
151 NOTIMPLEMENTED,
153 INTERNALERROR,
155}
156
157impl AMQPHardError {
158 pub fn get_id(&self) -> Identifier {
160 match *self {
161 AMQPHardError::CONNECTIONFORCED => 320,
162 AMQPHardError::INVALIDPATH => 402,
163 AMQPHardError::FRAMEERROR => 501,
164 AMQPHardError::SYNTAXERROR => 502,
165 AMQPHardError::COMMANDINVALID => 503,
166 AMQPHardError::CHANNELERROR => 504,
167 AMQPHardError::UNEXPECTEDFRAME => 505,
168 AMQPHardError::RESOURCEERROR => 506,
169 AMQPHardError::NOTALLOWED => 530,
170 AMQPHardError::NOTIMPLEMENTED => 540,
171 AMQPHardError::INTERNALERROR => 541,
172 }
173 }
174
175 pub fn from_id(id: Identifier) -> Option<AMQPHardError> {
177 match id {
178 320 => Some(AMQPHardError::CONNECTIONFORCED),
179 402 => Some(AMQPHardError::INVALIDPATH),
180 501 => Some(AMQPHardError::FRAMEERROR),
181 502 => Some(AMQPHardError::SYNTAXERROR),
182 503 => Some(AMQPHardError::COMMANDINVALID),
183 504 => Some(AMQPHardError::CHANNELERROR),
184 505 => Some(AMQPHardError::UNEXPECTEDFRAME),
185 506 => Some(AMQPHardError::RESOURCEERROR),
186 530 => Some(AMQPHardError::NOTALLOWED),
187 540 => Some(AMQPHardError::NOTIMPLEMENTED),
188 541 => Some(AMQPHardError::INTERNALERROR),
189 _ => None,
190 }
191 }
192}
193
194impl fmt::Display for AMQPHardError {
195 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
196 match self {
197 AMQPHardError::CONNECTIONFORCED => write!(f, "CONNECTION-FORCED"),
198 AMQPHardError::INVALIDPATH => write!(f, "INVALID-PATH"),
199 AMQPHardError::FRAMEERROR => write!(f, "FRAME-ERROR"),
200 AMQPHardError::SYNTAXERROR => write!(f, "SYNTAX-ERROR"),
201 AMQPHardError::COMMANDINVALID => write!(f, "COMMAND-INVALID"),
202 AMQPHardError::CHANNELERROR => write!(f, "CHANNEL-ERROR"),
203 AMQPHardError::UNEXPECTEDFRAME => write!(f, "UNEXPECTED-FRAME"),
204 AMQPHardError::RESOURCEERROR => write!(f, "RESOURCE-ERROR"),
205 AMQPHardError::NOTALLOWED => write!(f, "NOT-ALLOWED"),
206 AMQPHardError::NOTIMPLEMENTED => write!(f, "NOT-IMPLEMENTED"),
207 AMQPHardError::INTERNALERROR => write!(f, "INTERNAL-ERROR"),
208 }
209 }
210}
211
212use self::access::parse_access;
213use self::basic::parse_basic;
214use self::channel::parse_channel;
215use self::confirm::parse_confirm;
216use self::connection::parse_connection;
217use self::exchange::parse_exchange;
218use self::queue::parse_queue;
219use self::tx::parse_tx;
220pub fn parse_class<I: ParsableInput>(i: I) -> ParserResult<I, AMQPClass> {
222 context(
223 "parse_class",
224 map_opt(
225 flat_map(parse_id, |id| {
226 move |i| match id {
227 60 => map(map(parse_basic, AMQPClass::Basic), Some)(i),
228 10 => map(map(parse_connection, AMQPClass::Connection), Some)(i),
229 20 => map(map(parse_channel, AMQPClass::Channel), Some)(i),
230 30 => map(map(parse_access, AMQPClass::Access), Some)(i),
231 40 => map(map(parse_exchange, AMQPClass::Exchange), Some)(i),
232 50 => map(map(parse_queue, AMQPClass::Queue), Some)(i),
233 90 => map(map(parse_tx, AMQPClass::Tx), Some)(i),
234 85 => map(map(parse_confirm, AMQPClass::Confirm), Some)(i),
235 _ => Ok((i, None)),
236 }
237 }),
238 std::convert::identity,
239 ),
240 )(i)
241}
242
243pub fn gen_class<'a, W: Write + BackToTheBuffer + 'a>(
245 class: &'a AMQPClass,
246) -> impl SerializeFn<W> + 'a {
247 move |input| match *class {
248 AMQPClass::Basic(ref basic) => basic::gen_basic(basic)(input),
249 AMQPClass::Connection(ref connection) => connection::gen_connection(connection)(input),
250 AMQPClass::Channel(ref channel) => channel::gen_channel(channel)(input),
251 AMQPClass::Access(ref access) => access::gen_access(access)(input),
252 AMQPClass::Exchange(ref exchange) => exchange::gen_exchange(exchange)(input),
253 AMQPClass::Queue(ref queue) => queue::gen_queue(queue)(input),
254 AMQPClass::Tx(ref tx) => tx::gen_tx(tx)(input),
255 AMQPClass::Confirm(ref confirm) => confirm::gen_confirm(confirm)(input),
256 }
257}
258
259#[derive(Clone, Debug, PartialEq)]
261pub enum AMQPClass {
262 Basic(basic::AMQPMethod),
264 Connection(connection::AMQPMethod),
266 Channel(channel::AMQPMethod),
268 Access(access::AMQPMethod),
270 Exchange(exchange::AMQPMethod),
272 Queue(queue::AMQPMethod),
274 Tx(tx::AMQPMethod),
276 Confirm(confirm::AMQPMethod),
278}
279
280impl AMQPClass {
281 pub fn get_amqp_class_id(&self) -> Identifier {
283 match self {
284 AMQPClass::Basic(_) => 60,
285 AMQPClass::Connection(_) => 10,
286 AMQPClass::Channel(_) => 20,
287 AMQPClass::Access(_) => 30,
288 AMQPClass::Exchange(_) => 40,
289 AMQPClass::Queue(_) => 50,
290 AMQPClass::Tx(_) => 90,
291 AMQPClass::Confirm(_) => 85,
292 }
293 }
294
295 pub fn get_amqp_method_id(&self) -> Identifier {
297 match self {
298 AMQPClass::Basic(basic::AMQPMethod::Qos(_)) => 10,
299 AMQPClass::Basic(basic::AMQPMethod::QosOk(_)) => 11,
300 AMQPClass::Basic(basic::AMQPMethod::Consume(_)) => 20,
301 AMQPClass::Basic(basic::AMQPMethod::ConsumeOk(_)) => 21,
302 AMQPClass::Basic(basic::AMQPMethod::Cancel(_)) => 30,
303 AMQPClass::Basic(basic::AMQPMethod::CancelOk(_)) => 31,
304 AMQPClass::Basic(basic::AMQPMethod::Publish(_)) => 40,
305 AMQPClass::Basic(basic::AMQPMethod::Return(_)) => 50,
306 AMQPClass::Basic(basic::AMQPMethod::Deliver(_)) => 60,
307 AMQPClass::Basic(basic::AMQPMethod::Get(_)) => 70,
308 AMQPClass::Basic(basic::AMQPMethod::GetOk(_)) => 71,
309 AMQPClass::Basic(basic::AMQPMethod::GetEmpty(_)) => 72,
310 AMQPClass::Basic(basic::AMQPMethod::Ack(_)) => 80,
311 AMQPClass::Basic(basic::AMQPMethod::Reject(_)) => 90,
312 AMQPClass::Basic(basic::AMQPMethod::RecoverAsync(_)) => 100,
313 AMQPClass::Basic(basic::AMQPMethod::Recover(_)) => 110,
314 AMQPClass::Basic(basic::AMQPMethod::RecoverOk(_)) => 111,
315 AMQPClass::Basic(basic::AMQPMethod::Nack(_)) => 120,
316 AMQPClass::Connection(connection::AMQPMethod::Start(_)) => 10,
317 AMQPClass::Connection(connection::AMQPMethod::StartOk(_)) => 11,
318 AMQPClass::Connection(connection::AMQPMethod::Secure(_)) => 20,
319 AMQPClass::Connection(connection::AMQPMethod::SecureOk(_)) => 21,
320 AMQPClass::Connection(connection::AMQPMethod::Tune(_)) => 30,
321 AMQPClass::Connection(connection::AMQPMethod::TuneOk(_)) => 31,
322 AMQPClass::Connection(connection::AMQPMethod::Open(_)) => 40,
323 AMQPClass::Connection(connection::AMQPMethod::OpenOk(_)) => 41,
324 AMQPClass::Connection(connection::AMQPMethod::Close(_)) => 50,
325 AMQPClass::Connection(connection::AMQPMethod::CloseOk(_)) => 51,
326 AMQPClass::Connection(connection::AMQPMethod::Blocked(_)) => 60,
327 AMQPClass::Connection(connection::AMQPMethod::Unblocked(_)) => 61,
328 AMQPClass::Connection(connection::AMQPMethod::UpdateSecret(_)) => 70,
329 AMQPClass::Connection(connection::AMQPMethod::UpdateSecretOk(_)) => 71,
330 AMQPClass::Channel(channel::AMQPMethod::Open(_)) => 10,
331 AMQPClass::Channel(channel::AMQPMethod::OpenOk(_)) => 11,
332 AMQPClass::Channel(channel::AMQPMethod::Flow(_)) => 20,
333 AMQPClass::Channel(channel::AMQPMethod::FlowOk(_)) => 21,
334 AMQPClass::Channel(channel::AMQPMethod::Close(_)) => 40,
335 AMQPClass::Channel(channel::AMQPMethod::CloseOk(_)) => 41,
336 AMQPClass::Access(access::AMQPMethod::Request(_)) => 10,
337 AMQPClass::Access(access::AMQPMethod::RequestOk(_)) => 11,
338 AMQPClass::Exchange(exchange::AMQPMethod::Declare(_)) => 10,
339 AMQPClass::Exchange(exchange::AMQPMethod::DeclareOk(_)) => 11,
340 AMQPClass::Exchange(exchange::AMQPMethod::Delete(_)) => 20,
341 AMQPClass::Exchange(exchange::AMQPMethod::DeleteOk(_)) => 21,
342 AMQPClass::Exchange(exchange::AMQPMethod::Bind(_)) => 30,
343 AMQPClass::Exchange(exchange::AMQPMethod::BindOk(_)) => 31,
344 AMQPClass::Exchange(exchange::AMQPMethod::Unbind(_)) => 40,
345 AMQPClass::Exchange(exchange::AMQPMethod::UnbindOk(_)) => 51,
346 AMQPClass::Queue(queue::AMQPMethod::Declare(_)) => 10,
347 AMQPClass::Queue(queue::AMQPMethod::DeclareOk(_)) => 11,
348 AMQPClass::Queue(queue::AMQPMethod::Bind(_)) => 20,
349 AMQPClass::Queue(queue::AMQPMethod::BindOk(_)) => 21,
350 AMQPClass::Queue(queue::AMQPMethod::Purge(_)) => 30,
351 AMQPClass::Queue(queue::AMQPMethod::PurgeOk(_)) => 31,
352 AMQPClass::Queue(queue::AMQPMethod::Delete(_)) => 40,
353 AMQPClass::Queue(queue::AMQPMethod::DeleteOk(_)) => 41,
354 AMQPClass::Queue(queue::AMQPMethod::Unbind(_)) => 50,
355 AMQPClass::Queue(queue::AMQPMethod::UnbindOk(_)) => 51,
356 AMQPClass::Tx(tx::AMQPMethod::Select(_)) => 10,
357 AMQPClass::Tx(tx::AMQPMethod::SelectOk(_)) => 11,
358 AMQPClass::Tx(tx::AMQPMethod::Commit(_)) => 20,
359 AMQPClass::Tx(tx::AMQPMethod::CommitOk(_)) => 21,
360 AMQPClass::Tx(tx::AMQPMethod::Rollback(_)) => 30,
361 AMQPClass::Tx(tx::AMQPMethod::RollbackOk(_)) => 31,
362 AMQPClass::Confirm(confirm::AMQPMethod::Select(_)) => 10,
363 AMQPClass::Confirm(confirm::AMQPMethod::SelectOk(_)) => 11,
364 }
365 }
366}
367
368pub mod basic {
370 use super::*;
371
372 pub fn parse_basic<I: ParsableInput>(i: I) -> ParserResult<I, basic::AMQPMethod> {
374 context(
375 "parse_basic",
376 map_opt(
377 flat_map(parse_id, |id| {
378 move |i| match id {
379 10 => context("parse_qos", map(map(parse_qos, AMQPMethod::Qos), Some))(i),
380 11 => context(
381 "parse_qos_ok",
382 map(map(parse_qos_ok, AMQPMethod::QosOk), Some),
383 )(i),
384 20 => context(
385 "parse_consume",
386 map(map(parse_consume, AMQPMethod::Consume), Some),
387 )(i),
388 21 => context(
389 "parse_consume_ok",
390 map(map(parse_consume_ok, AMQPMethod::ConsumeOk), Some),
391 )(i),
392 30 => context(
393 "parse_cancel",
394 map(map(parse_cancel, AMQPMethod::Cancel), Some),
395 )(i),
396 31 => context(
397 "parse_cancel_ok",
398 map(map(parse_cancel_ok, AMQPMethod::CancelOk), Some),
399 )(i),
400 40 => context(
401 "parse_publish",
402 map(map(parse_publish, AMQPMethod::Publish), Some),
403 )(i),
404 50 => context(
405 "parse_return",
406 map(map(parse_return, AMQPMethod::Return), Some),
407 )(i),
408 60 => context(
409 "parse_deliver",
410 map(map(parse_deliver, AMQPMethod::Deliver), Some),
411 )(i),
412 70 => context("parse_get", map(map(parse_get, AMQPMethod::Get), Some))(i),
413 71 => context(
414 "parse_get_ok",
415 map(map(parse_get_ok, AMQPMethod::GetOk), Some),
416 )(i),
417 72 => context(
418 "parse_get_empty",
419 map(map(parse_get_empty, AMQPMethod::GetEmpty), Some),
420 )(i),
421 80 => context("parse_ack", map(map(parse_ack, AMQPMethod::Ack), Some))(i),
422 90 => context(
423 "parse_reject",
424 map(map(parse_reject, AMQPMethod::Reject), Some),
425 )(i),
426 100 => context(
427 "parse_recover_async",
428 map(map(parse_recover_async, AMQPMethod::RecoverAsync), Some),
429 )(i),
430 110 => context(
431 "parse_recover",
432 map(map(parse_recover, AMQPMethod::Recover), Some),
433 )(i),
434 111 => context(
435 "parse_recover_ok",
436 map(map(parse_recover_ok, AMQPMethod::RecoverOk), Some),
437 )(i),
438 120 => {
439 context("parse_nack", map(map(parse_nack, AMQPMethod::Nack), Some))(i)
440 }
441 _ => Ok((i, None)),
442 }
443 }),
444 std::convert::identity,
445 ),
446 )(i)
447 }
448
449 pub fn gen_basic<'a, W: Write + BackToTheBuffer + 'a>(
451 method: &'a AMQPMethod,
452 ) -> impl SerializeFn<W> + 'a {
453 cookie_factory::sequence::pair(gen_id(60), move |input| match *method {
454 AMQPMethod::Qos(ref qos) => gen_qos(qos)(input),
455 AMQPMethod::QosOk(ref qos_ok) => gen_qos_ok(qos_ok)(input),
456 AMQPMethod::Consume(ref consume) => gen_consume(consume)(input),
457 AMQPMethod::ConsumeOk(ref consume_ok) => gen_consume_ok(consume_ok)(input),
458 AMQPMethod::Cancel(ref cancel) => gen_cancel(cancel)(input),
459 AMQPMethod::CancelOk(ref cancel_ok) => gen_cancel_ok(cancel_ok)(input),
460 AMQPMethod::Publish(ref publish) => gen_publish(publish)(input),
461 AMQPMethod::Return(ref r#return) => gen_return(r#return)(input),
462 AMQPMethod::Deliver(ref deliver) => gen_deliver(deliver)(input),
463 AMQPMethod::Get(ref get) => gen_get(get)(input),
464 AMQPMethod::GetOk(ref get_ok) => gen_get_ok(get_ok)(input),
465 AMQPMethod::GetEmpty(ref get_empty) => gen_get_empty(get_empty)(input),
466 AMQPMethod::Ack(ref ack) => gen_ack(ack)(input),
467 AMQPMethod::Reject(ref reject) => gen_reject(reject)(input),
468 AMQPMethod::RecoverAsync(ref recover_async) => gen_recover_async(recover_async)(input),
469 AMQPMethod::Recover(ref recover) => gen_recover(recover)(input),
470 AMQPMethod::RecoverOk(ref recover_ok) => gen_recover_ok(recover_ok)(input),
471 AMQPMethod::Nack(ref nack) => gen_nack(nack)(input),
472 })
473 }
474
475 #[derive(Clone, Debug, PartialEq)]
477 pub enum AMQPMethod {
478 Qos(Qos),
480 QosOk(QosOk),
482 Consume(Consume),
484 ConsumeOk(ConsumeOk),
486 Cancel(Cancel),
488 CancelOk(CancelOk),
490 Publish(Publish),
492 Return(Return),
494 Deliver(Deliver),
496 Get(Get),
498 GetOk(GetOk),
500 GetEmpty(GetEmpty),
502 Ack(Ack),
504 Reject(Reject),
506 RecoverAsync(RecoverAsync),
508 Recover(Recover),
510 RecoverOk(RecoverOk),
512 Nack(Nack),
514 }
515
516 #[derive(Clone, Debug, Default, PartialEq)]
518 pub struct Qos {
519 pub prefetch_count: ShortUInt,
521 pub global: Boolean,
523 }
524
525 impl Qos {
526 pub fn get_amqp_class_id(&self) -> Identifier {
528 60
529 }
530
531 pub fn get_amqp_method_id(&self) -> Identifier {
533 10
534 }
535 }
536
537 pub fn parse_qos<I: ParsableInput>(i: I) -> ParserResult<I, Qos> {
539 let (i, _) = parse_long_uint(i)?;
540 let (i, prefetch_count) = parse_short_uint(i)?;
541 let (i, flags) = parse_flags(i, &["global"])?;
542 Ok((
543 i,
544 Qos {
545 prefetch_count,
546 global: flags.get_flag("global").unwrap_or(false),
547 },
548 ))
549 }
550
551 pub fn gen_qos<'a, W: Write + BackToTheBuffer + 'a>(
553 method: &'a Qos,
554 ) -> impl SerializeFn<W> + 'a {
555 move |mut input| {
556 let mut flags = AMQPFlags::default();
557 flags.add_flag("global".to_string(), method.global);
558 input = gen_id(10)(input)?;
559 input = gen_long_uint(0)(input)?;
560 input = gen_short_uint(method.prefetch_count)(input)?;
561 input = gen_flags(&flags)(input)?;
562 Ok(input)
563 }
564 }
565 #[derive(Clone, Debug, Default, PartialEq)]
567 pub struct QosOk {}
568
569 impl QosOk {
570 pub fn get_amqp_class_id(&self) -> Identifier {
572 60
573 }
574
575 pub fn get_amqp_method_id(&self) -> Identifier {
577 11
578 }
579 }
580
581 pub fn parse_qos_ok<I: ParsableInput>(i: I) -> ParserResult<I, QosOk> {
583 Ok((i, QosOk {}))
584 }
585
586 pub fn gen_qos_ok<'a, W: Write + BackToTheBuffer + 'a>(
588 _: &'a QosOk,
589 ) -> impl SerializeFn<W> + 'a {
590 move |mut input| {
591 input = gen_id(11)(input)?;
592 Ok(input)
593 }
594 }
595 #[derive(Clone, Debug, Default, PartialEq)]
597 pub struct Consume {
598 pub queue: ShortString,
600 pub consumer_tag: ShortString,
602 pub no_local: Boolean,
604 pub no_ack: Boolean,
606 pub exclusive: Boolean,
608 pub nowait: Boolean,
610 pub arguments: FieldTable,
612 }
613
614 impl Consume {
615 pub fn get_amqp_class_id(&self) -> Identifier {
617 60
618 }
619
620 pub fn get_amqp_method_id(&self) -> Identifier {
622 20
623 }
624 }
625
626 pub fn parse_consume<I: ParsableInput>(i: I) -> ParserResult<I, Consume> {
628 let (i, _) = parse_short_uint(i)?;
629 let (i, queue) = parse_short_string(i)?;
630 let (i, consumer_tag) = parse_short_string(i)?;
631 let (i, flags) = parse_flags(i, &["no_local", "no_ack", "exclusive", "nowait"])?;
632 let (i, arguments) = parse_field_table(i)?;
633 Ok((
634 i,
635 Consume {
636 queue,
637 consumer_tag,
638 no_local: flags.get_flag("no_local").unwrap_or(false),
639 no_ack: flags.get_flag("no_ack").unwrap_or(false),
640 exclusive: flags.get_flag("exclusive").unwrap_or(false),
641 nowait: flags.get_flag("nowait").unwrap_or(false),
642 arguments,
643 },
644 ))
645 }
646
647 pub fn gen_consume<'a, W: Write + BackToTheBuffer + 'a>(
649 method: &'a Consume,
650 ) -> impl SerializeFn<W> + 'a {
651 move |mut input| {
652 let mut flags = AMQPFlags::default();
653 flags.add_flag("no_local".to_string(), method.no_local);
654 flags.add_flag("no_ack".to_string(), method.no_ack);
655 flags.add_flag("exclusive".to_string(), method.exclusive);
656 flags.add_flag("nowait".to_string(), method.nowait);
657 input = gen_id(20)(input)?;
658 input = gen_short_uint(0)(input)?;
659 input = gen_short_string(method.queue.as_str())(input)?;
660 input = gen_short_string(method.consumer_tag.as_str())(input)?;
661 input = gen_flags(&flags)(input)?;
662 input = gen_field_table(&method.arguments)(input)?;
663 Ok(input)
664 }
665 }
666 #[derive(Clone, Debug, Default, PartialEq)]
668 pub struct ConsumeOk {
669 pub consumer_tag: ShortString,
671 }
672
673 impl ConsumeOk {
674 pub fn get_amqp_class_id(&self) -> Identifier {
676 60
677 }
678
679 pub fn get_amqp_method_id(&self) -> Identifier {
681 21
682 }
683 }
684
685 pub fn parse_consume_ok<I: ParsableInput>(i: I) -> ParserResult<I, ConsumeOk> {
687 let (i, consumer_tag) = parse_short_string(i)?;
688 Ok((i, ConsumeOk { consumer_tag }))
689 }
690
691 pub fn gen_consume_ok<'a, W: Write + BackToTheBuffer + 'a>(
693 method: &'a ConsumeOk,
694 ) -> impl SerializeFn<W> + 'a {
695 move |mut input| {
696 input = gen_id(21)(input)?;
697 input = gen_short_string(method.consumer_tag.as_str())(input)?;
698 Ok(input)
699 }
700 }
701 #[derive(Clone, Debug, Default, PartialEq)]
703 pub struct Cancel {
704 pub consumer_tag: ShortString,
706 pub nowait: Boolean,
708 }
709
710 impl Cancel {
711 pub fn get_amqp_class_id(&self) -> Identifier {
713 60
714 }
715
716 pub fn get_amqp_method_id(&self) -> Identifier {
718 30
719 }
720 }
721
722 pub fn parse_cancel<I: ParsableInput>(i: I) -> ParserResult<I, Cancel> {
724 let (i, consumer_tag) = parse_short_string(i)?;
725 let (i, flags) = parse_flags(i, &["nowait"])?;
726 Ok((
727 i,
728 Cancel {
729 consumer_tag,
730 nowait: flags.get_flag("nowait").unwrap_or(false),
731 },
732 ))
733 }
734
735 pub fn gen_cancel<'a, W: Write + BackToTheBuffer + 'a>(
737 method: &'a Cancel,
738 ) -> impl SerializeFn<W> + 'a {
739 move |mut input| {
740 let mut flags = AMQPFlags::default();
741 flags.add_flag("nowait".to_string(), method.nowait);
742 input = gen_id(30)(input)?;
743 input = gen_short_string(method.consumer_tag.as_str())(input)?;
744 input = gen_flags(&flags)(input)?;
745 Ok(input)
746 }
747 }
748 #[derive(Clone, Debug, Default, PartialEq)]
750 pub struct CancelOk {
751 pub consumer_tag: ShortString,
753 }
754
755 impl CancelOk {
756 pub fn get_amqp_class_id(&self) -> Identifier {
758 60
759 }
760
761 pub fn get_amqp_method_id(&self) -> Identifier {
763 31
764 }
765 }
766
767 pub fn parse_cancel_ok<I: ParsableInput>(i: I) -> ParserResult<I, CancelOk> {
769 let (i, consumer_tag) = parse_short_string(i)?;
770 Ok((i, CancelOk { consumer_tag }))
771 }
772
773 pub fn gen_cancel_ok<'a, W: Write + BackToTheBuffer + 'a>(
775 method: &'a CancelOk,
776 ) -> impl SerializeFn<W> + 'a {
777 move |mut input| {
778 input = gen_id(31)(input)?;
779 input = gen_short_string(method.consumer_tag.as_str())(input)?;
780 Ok(input)
781 }
782 }
783 #[derive(Clone, Debug, Default, PartialEq)]
785 pub struct Publish {
786 pub exchange: ShortString,
788 pub routing_key: ShortString,
790 pub mandatory: Boolean,
792 pub immediate: Boolean,
794 }
795
796 impl Publish {
797 pub fn get_amqp_class_id(&self) -> Identifier {
799 60
800 }
801
802 pub fn get_amqp_method_id(&self) -> Identifier {
804 40
805 }
806 }
807
808 pub fn parse_publish<I: ParsableInput>(i: I) -> ParserResult<I, Publish> {
810 let (i, _) = parse_short_uint(i)?;
811 let (i, exchange) = parse_short_string(i)?;
812 let (i, routing_key) = parse_short_string(i)?;
813 let (i, flags) = parse_flags(i, &["mandatory", "immediate"])?;
814 Ok((
815 i,
816 Publish {
817 exchange,
818 routing_key,
819 mandatory: flags.get_flag("mandatory").unwrap_or(false),
820 immediate: flags.get_flag("immediate").unwrap_or(false),
821 },
822 ))
823 }
824
825 pub fn gen_publish<'a, W: Write + BackToTheBuffer + 'a>(
827 method: &'a Publish,
828 ) -> impl SerializeFn<W> + 'a {
829 move |mut input| {
830 let mut flags = AMQPFlags::default();
831 flags.add_flag("mandatory".to_string(), method.mandatory);
832 flags.add_flag("immediate".to_string(), method.immediate);
833 input = gen_id(40)(input)?;
834 input = gen_short_uint(0)(input)?;
835 input = gen_short_string(method.exchange.as_str())(input)?;
836 input = gen_short_string(method.routing_key.as_str())(input)?;
837 input = gen_flags(&flags)(input)?;
838 Ok(input)
839 }
840 }
841 #[derive(Clone, Debug, Default, PartialEq)]
843 pub struct Return {
844 pub reply_code: ShortUInt,
846 pub reply_text: ShortString,
848 pub exchange: ShortString,
850 pub routing_key: ShortString,
852 }
853
854 impl Return {
855 pub fn get_amqp_class_id(&self) -> Identifier {
857 60
858 }
859
860 pub fn get_amqp_method_id(&self) -> Identifier {
862 50
863 }
864 }
865
866 pub fn parse_return<I: ParsableInput>(i: I) -> ParserResult<I, Return> {
868 let (i, reply_code) = parse_short_uint(i)?;
869 let (i, reply_text) = parse_short_string(i)?;
870 let (i, exchange) = parse_short_string(i)?;
871 let (i, routing_key) = parse_short_string(i)?;
872 Ok((
873 i,
874 Return {
875 reply_code,
876 reply_text,
877 exchange,
878 routing_key,
879 },
880 ))
881 }
882
883 pub fn gen_return<'a, W: Write + BackToTheBuffer + 'a>(
885 method: &'a Return,
886 ) -> impl SerializeFn<W> + 'a {
887 move |mut input| {
888 input = gen_id(50)(input)?;
889 input = gen_short_uint(method.reply_code)(input)?;
890 input = gen_short_string(method.reply_text.as_str())(input)?;
891 input = gen_short_string(method.exchange.as_str())(input)?;
892 input = gen_short_string(method.routing_key.as_str())(input)?;
893 Ok(input)
894 }
895 }
896 #[derive(Clone, Debug, Default, PartialEq)]
898 pub struct Deliver {
899 pub consumer_tag: ShortString,
901 pub delivery_tag: LongLongUInt,
903 pub redelivered: Boolean,
905 pub exchange: ShortString,
907 pub routing_key: ShortString,
909 }
910
911 impl Deliver {
912 pub fn get_amqp_class_id(&self) -> Identifier {
914 60
915 }
916
917 pub fn get_amqp_method_id(&self) -> Identifier {
919 60
920 }
921 }
922
923 pub fn parse_deliver<I: ParsableInput>(i: I) -> ParserResult<I, Deliver> {
925 let (i, consumer_tag) = parse_short_string(i)?;
926 let (i, delivery_tag) = parse_long_long_uint(i)?;
927 let (i, flags) = parse_flags(i, &["redelivered"])?;
928 let (i, exchange) = parse_short_string(i)?;
929 let (i, routing_key) = parse_short_string(i)?;
930 Ok((
931 i,
932 Deliver {
933 consumer_tag,
934 delivery_tag,
935 redelivered: flags.get_flag("redelivered").unwrap_or(false),
936 exchange,
937 routing_key,
938 },
939 ))
940 }
941
942 pub fn gen_deliver<'a, W: Write + BackToTheBuffer + 'a>(
944 method: &'a Deliver,
945 ) -> impl SerializeFn<W> + 'a {
946 move |mut input| {
947 let mut flags = AMQPFlags::default();
948 flags.add_flag("redelivered".to_string(), method.redelivered);
949 input = gen_id(60)(input)?;
950 input = gen_short_string(method.consumer_tag.as_str())(input)?;
951 input = gen_long_long_uint(method.delivery_tag)(input)?;
952 input = gen_flags(&flags)(input)?;
953 input = gen_short_string(method.exchange.as_str())(input)?;
954 input = gen_short_string(method.routing_key.as_str())(input)?;
955 Ok(input)
956 }
957 }
958 #[derive(Clone, Debug, Default, PartialEq)]
960 pub struct Get {
961 pub queue: ShortString,
963 pub no_ack: Boolean,
965 }
966
967 impl Get {
968 pub fn get_amqp_class_id(&self) -> Identifier {
970 60
971 }
972
973 pub fn get_amqp_method_id(&self) -> Identifier {
975 70
976 }
977 }
978
979 pub fn parse_get<I: ParsableInput>(i: I) -> ParserResult<I, Get> {
981 let (i, _) = parse_short_uint(i)?;
982 let (i, queue) = parse_short_string(i)?;
983 let (i, flags) = parse_flags(i, &["no_ack"])?;
984 Ok((
985 i,
986 Get {
987 queue,
988 no_ack: flags.get_flag("no_ack").unwrap_or(false),
989 },
990 ))
991 }
992
993 pub fn gen_get<'a, W: Write + BackToTheBuffer + 'a>(
995 method: &'a Get,
996 ) -> impl SerializeFn<W> + 'a {
997 move |mut input| {
998 let mut flags = AMQPFlags::default();
999 flags.add_flag("no_ack".to_string(), method.no_ack);
1000 input = gen_id(70)(input)?;
1001 input = gen_short_uint(0)(input)?;
1002 input = gen_short_string(method.queue.as_str())(input)?;
1003 input = gen_flags(&flags)(input)?;
1004 Ok(input)
1005 }
1006 }
1007 #[derive(Clone, Debug, Default, PartialEq)]
1009 pub struct GetOk {
1010 pub delivery_tag: LongLongUInt,
1012 pub redelivered: Boolean,
1014 pub exchange: ShortString,
1016 pub routing_key: ShortString,
1018 pub message_count: LongUInt,
1020 }
1021
1022 impl GetOk {
1023 pub fn get_amqp_class_id(&self) -> Identifier {
1025 60
1026 }
1027
1028 pub fn get_amqp_method_id(&self) -> Identifier {
1030 71
1031 }
1032 }
1033
1034 pub fn parse_get_ok<I: ParsableInput>(i: I) -> ParserResult<I, GetOk> {
1036 let (i, delivery_tag) = parse_long_long_uint(i)?;
1037 let (i, flags) = parse_flags(i, &["redelivered"])?;
1038 let (i, exchange) = parse_short_string(i)?;
1039 let (i, routing_key) = parse_short_string(i)?;
1040 let (i, message_count) = parse_long_uint(i)?;
1041 Ok((
1042 i,
1043 GetOk {
1044 delivery_tag,
1045 redelivered: flags.get_flag("redelivered").unwrap_or(false),
1046 exchange,
1047 routing_key,
1048 message_count,
1049 },
1050 ))
1051 }
1052
1053 pub fn gen_get_ok<'a, W: Write + BackToTheBuffer + 'a>(
1055 method: &'a GetOk,
1056 ) -> impl SerializeFn<W> + 'a {
1057 move |mut input| {
1058 let mut flags = AMQPFlags::default();
1059 flags.add_flag("redelivered".to_string(), method.redelivered);
1060 input = gen_id(71)(input)?;
1061 input = gen_long_long_uint(method.delivery_tag)(input)?;
1062 input = gen_flags(&flags)(input)?;
1063 input = gen_short_string(method.exchange.as_str())(input)?;
1064 input = gen_short_string(method.routing_key.as_str())(input)?;
1065 input = gen_long_uint(method.message_count)(input)?;
1066 Ok(input)
1067 }
1068 }
1069 #[derive(Clone, Debug, Default, PartialEq)]
1071 pub struct GetEmpty {}
1072
1073 impl GetEmpty {
1074 pub fn get_amqp_class_id(&self) -> Identifier {
1076 60
1077 }
1078
1079 pub fn get_amqp_method_id(&self) -> Identifier {
1081 72
1082 }
1083 }
1084
1085 pub fn parse_get_empty<I: ParsableInput>(i: I) -> ParserResult<I, GetEmpty> {
1087 let (i, _) = parse_short_string(i)?;
1088 Ok((i, GetEmpty {}))
1089 }
1090
1091 pub fn gen_get_empty<'a, W: Write + BackToTheBuffer + 'a>(
1093 _method: &'a GetEmpty,
1094 ) -> impl SerializeFn<W> + 'a {
1095 move |mut input| {
1096 input = gen_id(72)(input)?;
1097 input = gen_short_string("")(input)?;
1098 Ok(input)
1099 }
1100 }
1101 #[derive(Clone, Debug, Default, PartialEq)]
1103 pub struct Ack {
1104 pub delivery_tag: LongLongUInt,
1106 pub multiple: Boolean,
1108 }
1109
1110 impl Ack {
1111 pub fn get_amqp_class_id(&self) -> Identifier {
1113 60
1114 }
1115
1116 pub fn get_amqp_method_id(&self) -> Identifier {
1118 80
1119 }
1120 }
1121
1122 pub fn parse_ack<I: ParsableInput>(i: I) -> ParserResult<I, Ack> {
1124 let (i, delivery_tag) = parse_long_long_uint(i)?;
1125 let (i, flags) = parse_flags(i, &["multiple"])?;
1126 Ok((
1127 i,
1128 Ack {
1129 delivery_tag,
1130 multiple: flags.get_flag("multiple").unwrap_or(false),
1131 },
1132 ))
1133 }
1134
1135 pub fn gen_ack<'a, W: Write + BackToTheBuffer + 'a>(
1137 method: &'a Ack,
1138 ) -> impl SerializeFn<W> + 'a {
1139 move |mut input| {
1140 let mut flags = AMQPFlags::default();
1141 flags.add_flag("multiple".to_string(), method.multiple);
1142 input = gen_id(80)(input)?;
1143 input = gen_long_long_uint(method.delivery_tag)(input)?;
1144 input = gen_flags(&flags)(input)?;
1145 Ok(input)
1146 }
1147 }
1148 #[derive(Clone, Debug, Default, PartialEq)]
1150 pub struct Reject {
1151 pub delivery_tag: LongLongUInt,
1153 pub requeue: Boolean,
1155 }
1156
1157 impl Reject {
1158 pub fn get_amqp_class_id(&self) -> Identifier {
1160 60
1161 }
1162
1163 pub fn get_amqp_method_id(&self) -> Identifier {
1165 90
1166 }
1167 }
1168
1169 pub fn parse_reject<I: ParsableInput>(i: I) -> ParserResult<I, Reject> {
1171 let (i, delivery_tag) = parse_long_long_uint(i)?;
1172 let (i, flags) = parse_flags(i, &["requeue"])?;
1173 Ok((
1174 i,
1175 Reject {
1176 delivery_tag,
1177 requeue: flags.get_flag("requeue").unwrap_or(false),
1178 },
1179 ))
1180 }
1181
1182 pub fn gen_reject<'a, W: Write + BackToTheBuffer + 'a>(
1184 method: &'a Reject,
1185 ) -> impl SerializeFn<W> + 'a {
1186 move |mut input| {
1187 let mut flags = AMQPFlags::default();
1188 flags.add_flag("requeue".to_string(), method.requeue);
1189 input = gen_id(90)(input)?;
1190 input = gen_long_long_uint(method.delivery_tag)(input)?;
1191 input = gen_flags(&flags)(input)?;
1192 Ok(input)
1193 }
1194 }
1195 #[derive(Clone, Debug, Default, PartialEq)]
1197 pub struct RecoverAsync {
1198 pub requeue: Boolean,
1200 }
1201
1202 impl RecoverAsync {
1203 pub fn get_amqp_class_id(&self) -> Identifier {
1205 60
1206 }
1207
1208 pub fn get_amqp_method_id(&self) -> Identifier {
1210 100
1211 }
1212 }
1213
1214 pub fn parse_recover_async<I: ParsableInput>(i: I) -> ParserResult<I, RecoverAsync> {
1216 let (i, flags) = parse_flags(i, &["requeue"])?;
1217 Ok((
1218 i,
1219 RecoverAsync {
1220 requeue: flags.get_flag("requeue").unwrap_or(false),
1221 },
1222 ))
1223 }
1224
1225 pub fn gen_recover_async<'a, W: Write + BackToTheBuffer + 'a>(
1227 method: &'a RecoverAsync,
1228 ) -> impl SerializeFn<W> + 'a {
1229 move |mut input| {
1230 let mut flags = AMQPFlags::default();
1231 flags.add_flag("requeue".to_string(), method.requeue);
1232 input = gen_id(100)(input)?;
1233 input = gen_flags(&flags)(input)?;
1234 Ok(input)
1235 }
1236 }
1237 #[derive(Clone, Debug, Default, PartialEq)]
1239 pub struct Recover {
1240 pub requeue: Boolean,
1242 }
1243
1244 impl Recover {
1245 pub fn get_amqp_class_id(&self) -> Identifier {
1247 60
1248 }
1249
1250 pub fn get_amqp_method_id(&self) -> Identifier {
1252 110
1253 }
1254 }
1255
1256 pub fn parse_recover<I: ParsableInput>(i: I) -> ParserResult<I, Recover> {
1258 let (i, flags) = parse_flags(i, &["requeue"])?;
1259 Ok((
1260 i,
1261 Recover {
1262 requeue: flags.get_flag("requeue").unwrap_or(false),
1263 },
1264 ))
1265 }
1266
1267 pub fn gen_recover<'a, W: Write + BackToTheBuffer + 'a>(
1269 method: &'a Recover,
1270 ) -> impl SerializeFn<W> + 'a {
1271 move |mut input| {
1272 let mut flags = AMQPFlags::default();
1273 flags.add_flag("requeue".to_string(), method.requeue);
1274 input = gen_id(110)(input)?;
1275 input = gen_flags(&flags)(input)?;
1276 Ok(input)
1277 }
1278 }
1279 #[derive(Clone, Debug, Default, PartialEq)]
1281 pub struct RecoverOk {}
1282
1283 impl RecoverOk {
1284 pub fn get_amqp_class_id(&self) -> Identifier {
1286 60
1287 }
1288
1289 pub fn get_amqp_method_id(&self) -> Identifier {
1291 111
1292 }
1293 }
1294
1295 pub fn parse_recover_ok<I: ParsableInput>(i: I) -> ParserResult<I, RecoverOk> {
1297 Ok((i, RecoverOk {}))
1298 }
1299
1300 pub fn gen_recover_ok<'a, W: Write + BackToTheBuffer + 'a>(
1302 _: &'a RecoverOk,
1303 ) -> impl SerializeFn<W> + 'a {
1304 move |mut input| {
1305 input = gen_id(111)(input)?;
1306 Ok(input)
1307 }
1308 }
1309 #[derive(Clone, Debug, Default, PartialEq)]
1311 pub struct Nack {
1312 pub delivery_tag: LongLongUInt,
1314 pub multiple: Boolean,
1316 pub requeue: Boolean,
1318 }
1319
1320 impl Nack {
1321 pub fn get_amqp_class_id(&self) -> Identifier {
1323 60
1324 }
1325
1326 pub fn get_amqp_method_id(&self) -> Identifier {
1328 120
1329 }
1330 }
1331
1332 pub fn parse_nack<I: ParsableInput>(i: I) -> ParserResult<I, Nack> {
1334 let (i, delivery_tag) = parse_long_long_uint(i)?;
1335 let (i, flags) = parse_flags(i, &["multiple", "requeue"])?;
1336 Ok((
1337 i,
1338 Nack {
1339 delivery_tag,
1340 multiple: flags.get_flag("multiple").unwrap_or(false),
1341 requeue: flags.get_flag("requeue").unwrap_or(false),
1342 },
1343 ))
1344 }
1345
1346 pub fn gen_nack<'a, W: Write + BackToTheBuffer + 'a>(
1348 method: &'a Nack,
1349 ) -> impl SerializeFn<W> + 'a {
1350 move |mut input| {
1351 let mut flags = AMQPFlags::default();
1352 flags.add_flag("multiple".to_string(), method.multiple);
1353 flags.add_flag("requeue".to_string(), method.requeue);
1354 input = gen_id(120)(input)?;
1355 input = gen_long_long_uint(method.delivery_tag)(input)?;
1356 input = gen_flags(&flags)(input)?;
1357 Ok(input)
1358 }
1359 }
1360 #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1362 pub struct AMQPProperties {
1363 content_type: Option<ShortString>,
1364 content_encoding: Option<ShortString>,
1365 headers: Option<FieldTable>,
1366 delivery_mode: Option<ShortShortUInt>,
1367 priority: Option<ShortShortUInt>,
1368 correlation_id: Option<ShortString>,
1369 reply_to: Option<ShortString>,
1370 expiration: Option<ShortString>,
1371 message_id: Option<ShortString>,
1372 timestamp: Option<Timestamp>,
1373 kind: Option<ShortString>,
1374 user_id: Option<ShortString>,
1375 app_id: Option<ShortString>,
1376 cluster_id: Option<ShortString>,
1377 }
1378
1379 impl AMQPProperties {
1380 pub fn with_content_type(mut self, value: ShortString) -> Self {
1382 self.content_type = Some(value);
1383 self
1384 }
1385 pub fn with_content_encoding(mut self, value: ShortString) -> Self {
1387 self.content_encoding = Some(value);
1388 self
1389 }
1390 pub fn with_headers(mut self, value: FieldTable) -> Self {
1392 self.headers = Some(value);
1393 self
1394 }
1395 pub fn with_delivery_mode(mut self, value: ShortShortUInt) -> Self {
1397 self.delivery_mode = Some(value);
1398 self
1399 }
1400 pub fn with_priority(mut self, value: ShortShortUInt) -> Self {
1402 self.priority = Some(value);
1403 self
1404 }
1405 pub fn with_correlation_id(mut self, value: ShortString) -> Self {
1407 self.correlation_id = Some(value);
1408 self
1409 }
1410 pub fn with_reply_to(mut self, value: ShortString) -> Self {
1412 self.reply_to = Some(value);
1413 self
1414 }
1415 pub fn with_expiration(mut self, value: ShortString) -> Self {
1417 self.expiration = Some(value);
1418 self
1419 }
1420 pub fn with_message_id(mut self, value: ShortString) -> Self {
1422 self.message_id = Some(value);
1423 self
1424 }
1425 pub fn with_timestamp(mut self, value: Timestamp) -> Self {
1427 self.timestamp = Some(value);
1428 self
1429 }
1430 pub fn with_type(mut self, value: ShortString) -> Self {
1432 self.kind = Some(value);
1433 self
1434 }
1435 pub fn with_user_id(mut self, value: ShortString) -> Self {
1437 self.user_id = Some(value);
1438 self
1439 }
1440 pub fn with_app_id(mut self, value: ShortString) -> Self {
1442 self.app_id = Some(value);
1443 self
1444 }
1445 pub fn with_cluster_id(mut self, value: ShortString) -> Self {
1447 self.cluster_id = Some(value);
1448 self
1449 }
1450 pub fn content_type(&self) -> &Option<ShortString> {
1452 &self.content_type
1453 }
1454 pub fn content_encoding(&self) -> &Option<ShortString> {
1456 &self.content_encoding
1457 }
1458 pub fn headers(&self) -> &Option<FieldTable> {
1460 &self.headers
1461 }
1462 pub fn delivery_mode(&self) -> &Option<ShortShortUInt> {
1464 &self.delivery_mode
1465 }
1466 pub fn priority(&self) -> &Option<ShortShortUInt> {
1468 &self.priority
1469 }
1470 pub fn correlation_id(&self) -> &Option<ShortString> {
1472 &self.correlation_id
1473 }
1474 pub fn reply_to(&self) -> &Option<ShortString> {
1476 &self.reply_to
1477 }
1478 pub fn expiration(&self) -> &Option<ShortString> {
1480 &self.expiration
1481 }
1482 pub fn message_id(&self) -> &Option<ShortString> {
1484 &self.message_id
1485 }
1486 pub fn timestamp(&self) -> &Option<Timestamp> {
1488 &self.timestamp
1489 }
1490 pub fn kind(&self) -> &Option<ShortString> {
1492 &self.kind
1493 }
1494 pub fn user_id(&self) -> &Option<ShortString> {
1496 &self.user_id
1497 }
1498 pub fn app_id(&self) -> &Option<ShortString> {
1500 &self.app_id
1501 }
1502 pub fn cluster_id(&self) -> &Option<ShortString> {
1504 &self.cluster_id
1505 }
1506 #[allow(clippy::identity_op)]
1508 pub fn bitmask(&self) -> ShortUInt {
1509 (if self.content_type.is_some() {
1510 1 << (15 - 0)
1511 } else {
1512 0
1513 }) + (if self.content_encoding.is_some() {
1514 1 << (15 - 1)
1515 } else {
1516 0
1517 }) + (if self.headers.is_some() {
1518 1 << (15 - 2)
1519 } else {
1520 0
1521 }) + (if self.delivery_mode.is_some() {
1522 1 << (15 - 3)
1523 } else {
1524 0
1525 }) + (if self.priority.is_some() {
1526 1 << (15 - 4)
1527 } else {
1528 0
1529 }) + (if self.correlation_id.is_some() {
1530 1 << (15 - 5)
1531 } else {
1532 0
1533 }) + (if self.reply_to.is_some() {
1534 1 << (15 - 6)
1535 } else {
1536 0
1537 }) + (if self.expiration.is_some() {
1538 1 << (15 - 7)
1539 } else {
1540 0
1541 }) + (if self.message_id.is_some() {
1542 1 << (15 - 8)
1543 } else {
1544 0
1545 }) + (if self.timestamp.is_some() {
1546 1 << (15 - 9)
1547 } else {
1548 0
1549 }) + (if self.kind.is_some() {
1550 1 << (15 - 10)
1551 } else {
1552 0
1553 }) + (if self.user_id.is_some() {
1554 1 << (15 - 11)
1555 } else {
1556 0
1557 }) + (if self.app_id.is_some() {
1558 1 << (15 - 12)
1559 } else {
1560 0
1561 }) + (if self.cluster_id.is_some() {
1562 1 << (15 - 13)
1563 } else {
1564 0
1565 })
1566 }
1567 }
1568
1569 #[allow(clippy::identity_op)]
1571 pub fn parse_properties<I: ParsableInput>(i: I) -> ParserResult<I, AMQPProperties> {
1572 let (i, flags) = parse_short_uint(i)?;
1573 let (i, content_type) = if flags & (1 << (15 - 0)) != 0 {
1574 map(parse_short_string, Some)(i)?
1575 } else {
1576 (i, None)
1577 };
1578 let (i, content_encoding) = if flags & (1 << (15 - 1)) != 0 {
1579 map(parse_short_string, Some)(i)?
1580 } else {
1581 (i, None)
1582 };
1583 let (i, headers) = if flags & (1 << (15 - 2)) != 0 {
1584 map(parse_field_table, Some)(i)?
1585 } else {
1586 (i, None)
1587 };
1588 let (i, delivery_mode) = if flags & (1 << (15 - 3)) != 0 {
1589 map(parse_short_short_uint, Some)(i)?
1590 } else {
1591 (i, None)
1592 };
1593 let (i, priority) = if flags & (1 << (15 - 4)) != 0 {
1594 map(parse_short_short_uint, Some)(i)?
1595 } else {
1596 (i, None)
1597 };
1598 let (i, correlation_id) = if flags & (1 << (15 - 5)) != 0 {
1599 map(parse_short_string, Some)(i)?
1600 } else {
1601 (i, None)
1602 };
1603 let (i, reply_to) = if flags & (1 << (15 - 6)) != 0 {
1604 map(parse_short_string, Some)(i)?
1605 } else {
1606 (i, None)
1607 };
1608 let (i, expiration) = if flags & (1 << (15 - 7)) != 0 {
1609 map(parse_short_string, Some)(i)?
1610 } else {
1611 (i, None)
1612 };
1613 let (i, message_id) = if flags & (1 << (15 - 8)) != 0 {
1614 map(parse_short_string, Some)(i)?
1615 } else {
1616 (i, None)
1617 };
1618 let (i, timestamp) = if flags & (1 << (15 - 9)) != 0 {
1619 map(parse_timestamp, Some)(i)?
1620 } else {
1621 (i, None)
1622 };
1623 let (i, kind) = if flags & (1 << (15 - 10)) != 0 {
1624 map(parse_short_string, Some)(i)?
1625 } else {
1626 (i, None)
1627 };
1628 let (i, user_id) = if flags & (1 << (15 - 11)) != 0 {
1629 map(parse_short_string, Some)(i)?
1630 } else {
1631 (i, None)
1632 };
1633 let (i, app_id) = if flags & (1 << (15 - 12)) != 0 {
1634 map(parse_short_string, Some)(i)?
1635 } else {
1636 (i, None)
1637 };
1638 let (i, cluster_id) = if flags & (1 << (15 - 13)) != 0 {
1639 map(parse_short_string, Some)(i)?
1640 } else {
1641 (i, None)
1642 };
1643 Ok((
1644 i,
1645 AMQPProperties {
1646 content_type,
1647 content_encoding,
1648 headers,
1649 delivery_mode,
1650 priority,
1651 correlation_id,
1652 reply_to,
1653 expiration,
1654 message_id,
1655 timestamp,
1656 kind,
1657 user_id,
1658 app_id,
1659 cluster_id,
1660 },
1661 ))
1662 }
1663
1664 pub fn gen_properties<'a, W: Write + BackToTheBuffer + 'a>(
1666 props: &'a AMQPProperties,
1667 ) -> impl SerializeFn<W> + 'a {
1668 cookie_factory::sequence::pair(gen_short_uint(props.bitmask()), move |mut input| {
1669 if let Some(prop) = props.content_type.as_ref() {
1670 input = gen_short_string(prop.as_str())(input)?;
1671 }
1672 if let Some(prop) = props.content_encoding.as_ref() {
1673 input = gen_short_string(prop.as_str())(input)?;
1674 }
1675 if let Some(prop) = props.headers.as_ref() {
1676 input = gen_field_table(prop)(input)?;
1677 }
1678 if let Some(prop) = props.delivery_mode {
1679 input = gen_short_short_uint(prop)(input)?;
1680 }
1681 if let Some(prop) = props.priority {
1682 input = gen_short_short_uint(prop)(input)?;
1683 }
1684 if let Some(prop) = props.correlation_id.as_ref() {
1685 input = gen_short_string(prop.as_str())(input)?;
1686 }
1687 if let Some(prop) = props.reply_to.as_ref() {
1688 input = gen_short_string(prop.as_str())(input)?;
1689 }
1690 if let Some(prop) = props.expiration.as_ref() {
1691 input = gen_short_string(prop.as_str())(input)?;
1692 }
1693 if let Some(prop) = props.message_id.as_ref() {
1694 input = gen_short_string(prop.as_str())(input)?;
1695 }
1696 if let Some(prop) = props.timestamp {
1697 input = gen_timestamp(prop)(input)?;
1698 }
1699 if let Some(prop) = props.kind.as_ref() {
1700 input = gen_short_string(prop.as_str())(input)?;
1701 }
1702 if let Some(prop) = props.user_id.as_ref() {
1703 input = gen_short_string(prop.as_str())(input)?;
1704 }
1705 if let Some(prop) = props.app_id.as_ref() {
1706 input = gen_short_string(prop.as_str())(input)?;
1707 }
1708 if let Some(prop) = props.cluster_id.as_ref() {
1709 input = gen_short_string(prop.as_str())(input)?;
1710 }
1711 Ok(input)
1712 })
1713 }
1714}
1715pub mod connection {
1717 use super::*;
1718
1719 pub fn parse_connection<I: ParsableInput>(i: I) -> ParserResult<I, connection::AMQPMethod> {
1721 context(
1722 "parse_connection",
1723 map_opt(
1724 flat_map(parse_id, |id| {
1725 move |i| match id {
1726 10 => context(
1727 "parse_start",
1728 map(map(parse_start, AMQPMethod::Start), Some),
1729 )(i),
1730 11 => context(
1731 "parse_start_ok",
1732 map(map(parse_start_ok, AMQPMethod::StartOk), Some),
1733 )(i),
1734 20 => context(
1735 "parse_secure",
1736 map(map(parse_secure, AMQPMethod::Secure), Some),
1737 )(i),
1738 21 => context(
1739 "parse_secure_ok",
1740 map(map(parse_secure_ok, AMQPMethod::SecureOk), Some),
1741 )(i),
1742 30 => {
1743 context("parse_tune", map(map(parse_tune, AMQPMethod::Tune), Some))(i)
1744 }
1745 31 => context(
1746 "parse_tune_ok",
1747 map(map(parse_tune_ok, AMQPMethod::TuneOk), Some),
1748 )(i),
1749 40 => {
1750 context("parse_open", map(map(parse_open, AMQPMethod::Open), Some))(i)
1751 }
1752 41 => context(
1753 "parse_open_ok",
1754 map(map(parse_open_ok, AMQPMethod::OpenOk), Some),
1755 )(i),
1756 50 => context(
1757 "parse_close",
1758 map(map(parse_close, AMQPMethod::Close), Some),
1759 )(i),
1760 51 => context(
1761 "parse_close_ok",
1762 map(map(parse_close_ok, AMQPMethod::CloseOk), Some),
1763 )(i),
1764 60 => context(
1765 "parse_blocked",
1766 map(map(parse_blocked, AMQPMethod::Blocked), Some),
1767 )(i),
1768 61 => context(
1769 "parse_unblocked",
1770 map(map(parse_unblocked, AMQPMethod::Unblocked), Some),
1771 )(i),
1772 70 => context(
1773 "parse_update_secret",
1774 map(map(parse_update_secret, AMQPMethod::UpdateSecret), Some),
1775 )(i),
1776 71 => context(
1777 "parse_update_secret_ok",
1778 map(
1779 map(parse_update_secret_ok, AMQPMethod::UpdateSecretOk),
1780 Some,
1781 ),
1782 )(i),
1783 _ => Ok((i, None)),
1784 }
1785 }),
1786 std::convert::identity,
1787 ),
1788 )(i)
1789 }
1790
1791 pub fn gen_connection<'a, W: Write + BackToTheBuffer + 'a>(
1793 method: &'a AMQPMethod,
1794 ) -> impl SerializeFn<W> + 'a {
1795 cookie_factory::sequence::pair(gen_id(10), move |input| match *method {
1796 AMQPMethod::Start(ref start) => gen_start(start)(input),
1797 AMQPMethod::StartOk(ref start_ok) => gen_start_ok(start_ok)(input),
1798 AMQPMethod::Secure(ref secure) => gen_secure(secure)(input),
1799 AMQPMethod::SecureOk(ref secure_ok) => gen_secure_ok(secure_ok)(input),
1800 AMQPMethod::Tune(ref tune) => gen_tune(tune)(input),
1801 AMQPMethod::TuneOk(ref tune_ok) => gen_tune_ok(tune_ok)(input),
1802 AMQPMethod::Open(ref open) => gen_open(open)(input),
1803 AMQPMethod::OpenOk(ref open_ok) => gen_open_ok(open_ok)(input),
1804 AMQPMethod::Close(ref close) => gen_close(close)(input),
1805 AMQPMethod::CloseOk(ref close_ok) => gen_close_ok(close_ok)(input),
1806 AMQPMethod::Blocked(ref blocked) => gen_blocked(blocked)(input),
1807 AMQPMethod::Unblocked(ref unblocked) => gen_unblocked(unblocked)(input),
1808 AMQPMethod::UpdateSecret(ref update_secret) => gen_update_secret(update_secret)(input),
1809 AMQPMethod::UpdateSecretOk(ref update_secret_ok) => {
1810 gen_update_secret_ok(update_secret_ok)(input)
1811 }
1812 })
1813 }
1814
1815 #[derive(Clone, Debug, PartialEq)]
1817 pub enum AMQPMethod {
1818 Start(Start),
1820 StartOk(StartOk),
1822 Secure(Secure),
1824 SecureOk(SecureOk),
1826 Tune(Tune),
1828 TuneOk(TuneOk),
1830 Open(Open),
1832 OpenOk(OpenOk),
1834 Close(Close),
1836 CloseOk(CloseOk),
1838 Blocked(Blocked),
1840 Unblocked(Unblocked),
1842 UpdateSecret(UpdateSecret),
1844 UpdateSecretOk(UpdateSecretOk),
1846 }
1847
1848 #[derive(Clone, Debug, Default, PartialEq)]
1850 pub struct Start {
1851 pub version_major: ShortShortUInt,
1853 pub version_minor: ShortShortUInt,
1855 pub server_properties: FieldTable,
1857 pub mechanisms: LongString,
1859 pub locales: LongString,
1861 }
1862
1863 impl Start {
1864 pub fn get_amqp_class_id(&self) -> Identifier {
1866 10
1867 }
1868
1869 pub fn get_amqp_method_id(&self) -> Identifier {
1871 10
1872 }
1873 }
1874
1875 pub fn parse_start<I: ParsableInput>(i: I) -> ParserResult<I, Start> {
1877 let (i, version_major) = parse_short_short_uint(i)?;
1878 let (i, version_minor) = parse_short_short_uint(i)?;
1879 let (i, server_properties) = parse_field_table(i)?;
1880 let (i, mechanisms) = parse_long_string(i)?;
1881 let (i, locales) = parse_long_string(i)?;
1882 Ok((
1883 i,
1884 Start {
1885 version_major,
1886 version_minor,
1887 server_properties,
1888 mechanisms,
1889 locales,
1890 },
1891 ))
1892 }
1893
1894 pub fn gen_start<'a, W: Write + BackToTheBuffer + 'a>(
1896 method: &'a Start,
1897 ) -> impl SerializeFn<W> + 'a {
1898 move |mut input| {
1899 input = gen_id(10)(input)?;
1900 input = gen_short_short_uint(method.version_major)(input)?;
1901 input = gen_short_short_uint(method.version_minor)(input)?;
1902 input = gen_field_table(&method.server_properties)(input)?;
1903 input = gen_long_string(method.mechanisms.as_bytes())(input)?;
1904 input = gen_long_string(method.locales.as_bytes())(input)?;
1905 Ok(input)
1906 }
1907 }
1908 #[derive(Clone, Debug, Default, PartialEq)]
1910 pub struct StartOk {
1911 pub client_properties: FieldTable,
1913 pub mechanism: ShortString,
1915 pub response: LongString,
1917 pub locale: ShortString,
1919 }
1920
1921 impl StartOk {
1922 pub fn get_amqp_class_id(&self) -> Identifier {
1924 10
1925 }
1926
1927 pub fn get_amqp_method_id(&self) -> Identifier {
1929 11
1930 }
1931 }
1932
1933 pub fn parse_start_ok<I: ParsableInput>(i: I) -> ParserResult<I, StartOk> {
1935 let (i, client_properties) = parse_field_table(i)?;
1936 let (i, mechanism) = parse_short_string(i)?;
1937 let (i, response) = parse_long_string(i)?;
1938 let (i, locale) = parse_short_string(i)?;
1939 Ok((
1940 i,
1941 StartOk {
1942 client_properties,
1943 mechanism,
1944 response,
1945 locale,
1946 },
1947 ))
1948 }
1949
1950 pub fn gen_start_ok<'a, W: Write + BackToTheBuffer + 'a>(
1952 method: &'a StartOk,
1953 ) -> impl SerializeFn<W> + 'a {
1954 move |mut input| {
1955 input = gen_id(11)(input)?;
1956 input = gen_field_table(&method.client_properties)(input)?;
1957 input = gen_short_string(method.mechanism.as_str())(input)?;
1958 input = gen_long_string(method.response.as_bytes())(input)?;
1959 input = gen_short_string(method.locale.as_str())(input)?;
1960 Ok(input)
1961 }
1962 }
1963 #[derive(Clone, Debug, Default, PartialEq)]
1965 pub struct Secure {
1966 pub challenge: LongString,
1968 }
1969
1970 impl Secure {
1971 pub fn get_amqp_class_id(&self) -> Identifier {
1973 10
1974 }
1975
1976 pub fn get_amqp_method_id(&self) -> Identifier {
1978 20
1979 }
1980 }
1981
1982 pub fn parse_secure<I: ParsableInput>(i: I) -> ParserResult<I, Secure> {
1984 let (i, challenge) = parse_long_string(i)?;
1985 Ok((i, Secure { challenge }))
1986 }
1987
1988 pub fn gen_secure<'a, W: Write + BackToTheBuffer + 'a>(
1990 method: &'a Secure,
1991 ) -> impl SerializeFn<W> + 'a {
1992 move |mut input| {
1993 input = gen_id(20)(input)?;
1994 input = gen_long_string(method.challenge.as_bytes())(input)?;
1995 Ok(input)
1996 }
1997 }
1998 #[derive(Clone, Debug, Default, PartialEq)]
2000 pub struct SecureOk {
2001 pub response: LongString,
2003 }
2004
2005 impl SecureOk {
2006 pub fn get_amqp_class_id(&self) -> Identifier {
2008 10
2009 }
2010
2011 pub fn get_amqp_method_id(&self) -> Identifier {
2013 21
2014 }
2015 }
2016
2017 pub fn parse_secure_ok<I: ParsableInput>(i: I) -> ParserResult<I, SecureOk> {
2019 let (i, response) = parse_long_string(i)?;
2020 Ok((i, SecureOk { response }))
2021 }
2022
2023 pub fn gen_secure_ok<'a, W: Write + BackToTheBuffer + 'a>(
2025 method: &'a SecureOk,
2026 ) -> impl SerializeFn<W> + 'a {
2027 move |mut input| {
2028 input = gen_id(21)(input)?;
2029 input = gen_long_string(method.response.as_bytes())(input)?;
2030 Ok(input)
2031 }
2032 }
2033 #[derive(Clone, Debug, Default, PartialEq)]
2035 pub struct Tune {
2036 pub channel_max: ShortUInt,
2038 pub frame_max: LongUInt,
2040 pub heartbeat: ShortUInt,
2042 }
2043
2044 impl Tune {
2045 pub fn get_amqp_class_id(&self) -> Identifier {
2047 10
2048 }
2049
2050 pub fn get_amqp_method_id(&self) -> Identifier {
2052 30
2053 }
2054 }
2055
2056 pub fn parse_tune<I: ParsableInput>(i: I) -> ParserResult<I, Tune> {
2058 let (i, channel_max) = parse_short_uint(i)?;
2059 let (i, frame_max) = parse_long_uint(i)?;
2060 let (i, heartbeat) = parse_short_uint(i)?;
2061 Ok((
2062 i,
2063 Tune {
2064 channel_max,
2065 frame_max,
2066 heartbeat,
2067 },
2068 ))
2069 }
2070
2071 pub fn gen_tune<'a, W: Write + BackToTheBuffer + 'a>(
2073 method: &'a Tune,
2074 ) -> impl SerializeFn<W> + 'a {
2075 move |mut input| {
2076 input = gen_id(30)(input)?;
2077 input = gen_short_uint(method.channel_max)(input)?;
2078 input = gen_long_uint(method.frame_max)(input)?;
2079 input = gen_short_uint(method.heartbeat)(input)?;
2080 Ok(input)
2081 }
2082 }
2083 #[derive(Clone, Debug, Default, PartialEq)]
2085 pub struct TuneOk {
2086 pub channel_max: ShortUInt,
2088 pub frame_max: LongUInt,
2090 pub heartbeat: ShortUInt,
2092 }
2093
2094 impl TuneOk {
2095 pub fn get_amqp_class_id(&self) -> Identifier {
2097 10
2098 }
2099
2100 pub fn get_amqp_method_id(&self) -> Identifier {
2102 31
2103 }
2104 }
2105
2106 pub fn parse_tune_ok<I: ParsableInput>(i: I) -> ParserResult<I, TuneOk> {
2108 let (i, channel_max) = parse_short_uint(i)?;
2109 let (i, frame_max) = parse_long_uint(i)?;
2110 let (i, heartbeat) = parse_short_uint(i)?;
2111 Ok((
2112 i,
2113 TuneOk {
2114 channel_max,
2115 frame_max,
2116 heartbeat,
2117 },
2118 ))
2119 }
2120
2121 pub fn gen_tune_ok<'a, W: Write + BackToTheBuffer + 'a>(
2123 method: &'a TuneOk,
2124 ) -> impl SerializeFn<W> + 'a {
2125 move |mut input| {
2126 input = gen_id(31)(input)?;
2127 input = gen_short_uint(method.channel_max)(input)?;
2128 input = gen_long_uint(method.frame_max)(input)?;
2129 input = gen_short_uint(method.heartbeat)(input)?;
2130 Ok(input)
2131 }
2132 }
2133 #[derive(Clone, Debug, Default, PartialEq)]
2135 pub struct Open {
2136 pub virtual_host: ShortString,
2138 }
2139
2140 impl Open {
2141 pub fn get_amqp_class_id(&self) -> Identifier {
2143 10
2144 }
2145
2146 pub fn get_amqp_method_id(&self) -> Identifier {
2148 40
2149 }
2150 }
2151
2152 pub fn parse_open<I: ParsableInput>(i: I) -> ParserResult<I, Open> {
2154 let (i, virtual_host) = parse_short_string(i)?;
2155 let (i, _) = parse_short_string(i)?;
2156 let (i, _) = parse_flags(i, &["insist"])?;
2157 Ok((i, Open { virtual_host }))
2158 }
2159
2160 pub fn gen_open<'a, W: Write + BackToTheBuffer + 'a>(
2162 method: &'a Open,
2163 ) -> impl SerializeFn<W> + 'a {
2164 move |mut input| {
2165 let mut flags = AMQPFlags::default();
2166 flags.add_flag("insist".to_string(), false);
2167 input = gen_id(40)(input)?;
2168 input = gen_short_string(method.virtual_host.as_str())(input)?;
2169 input = gen_short_string("")(input)?;
2170 input = gen_flags(&flags)(input)?;
2171 Ok(input)
2172 }
2173 }
2174 #[derive(Clone, Debug, Default, PartialEq)]
2176 pub struct OpenOk {}
2177
2178 impl OpenOk {
2179 pub fn get_amqp_class_id(&self) -> Identifier {
2181 10
2182 }
2183
2184 pub fn get_amqp_method_id(&self) -> Identifier {
2186 41
2187 }
2188 }
2189
2190 pub fn parse_open_ok<I: ParsableInput>(i: I) -> ParserResult<I, OpenOk> {
2192 let (i, _) = parse_short_string(i)?;
2193 Ok((i, OpenOk {}))
2194 }
2195
2196 pub fn gen_open_ok<'a, W: Write + BackToTheBuffer + 'a>(
2198 _method: &'a OpenOk,
2199 ) -> impl SerializeFn<W> + 'a {
2200 move |mut input| {
2201 input = gen_id(41)(input)?;
2202 input = gen_short_string("")(input)?;
2203 Ok(input)
2204 }
2205 }
2206 #[derive(Clone, Debug, Default, PartialEq)]
2208 pub struct Close {
2209 pub reply_code: ShortUInt,
2211 pub reply_text: ShortString,
2213 pub class_id: ShortUInt,
2215 pub method_id: ShortUInt,
2217 }
2218
2219 impl Close {
2220 pub fn get_amqp_class_id(&self) -> Identifier {
2222 10
2223 }
2224
2225 pub fn get_amqp_method_id(&self) -> Identifier {
2227 50
2228 }
2229 }
2230
2231 pub fn parse_close<I: ParsableInput>(i: I) -> ParserResult<I, Close> {
2233 let (i, reply_code) = parse_short_uint(i)?;
2234 let (i, reply_text) = parse_short_string(i)?;
2235 let (i, class_id) = parse_short_uint(i)?;
2236 let (i, method_id) = parse_short_uint(i)?;
2237 Ok((
2238 i,
2239 Close {
2240 reply_code,
2241 reply_text,
2242 class_id,
2243 method_id,
2244 },
2245 ))
2246 }
2247
2248 pub fn gen_close<'a, W: Write + BackToTheBuffer + 'a>(
2250 method: &'a Close,
2251 ) -> impl SerializeFn<W> + 'a {
2252 move |mut input| {
2253 input = gen_id(50)(input)?;
2254 input = gen_short_uint(method.reply_code)(input)?;
2255 input = gen_short_string(method.reply_text.as_str())(input)?;
2256 input = gen_short_uint(method.class_id)(input)?;
2257 input = gen_short_uint(method.method_id)(input)?;
2258 Ok(input)
2259 }
2260 }
2261 #[derive(Clone, Debug, Default, PartialEq)]
2263 pub struct CloseOk {}
2264
2265 impl CloseOk {
2266 pub fn get_amqp_class_id(&self) -> Identifier {
2268 10
2269 }
2270
2271 pub fn get_amqp_method_id(&self) -> Identifier {
2273 51
2274 }
2275 }
2276
2277 pub fn parse_close_ok<I: ParsableInput>(i: I) -> ParserResult<I, CloseOk> {
2279 Ok((i, CloseOk {}))
2280 }
2281
2282 pub fn gen_close_ok<'a, W: Write + BackToTheBuffer + 'a>(
2284 _: &'a CloseOk,
2285 ) -> impl SerializeFn<W> + 'a {
2286 move |mut input| {
2287 input = gen_id(51)(input)?;
2288 Ok(input)
2289 }
2290 }
2291 #[derive(Clone, Debug, Default, PartialEq)]
2293 pub struct Blocked {
2294 pub reason: ShortString,
2296 }
2297
2298 impl Blocked {
2299 pub fn get_amqp_class_id(&self) -> Identifier {
2301 10
2302 }
2303
2304 pub fn get_amqp_method_id(&self) -> Identifier {
2306 60
2307 }
2308 }
2309
2310 pub fn parse_blocked<I: ParsableInput>(i: I) -> ParserResult<I, Blocked> {
2312 let (i, reason) = parse_short_string(i)?;
2313 Ok((i, Blocked { reason }))
2314 }
2315
2316 pub fn gen_blocked<'a, W: Write + BackToTheBuffer + 'a>(
2318 method: &'a Blocked,
2319 ) -> impl SerializeFn<W> + 'a {
2320 move |mut input| {
2321 input = gen_id(60)(input)?;
2322 input = gen_short_string(method.reason.as_str())(input)?;
2323 Ok(input)
2324 }
2325 }
2326 #[derive(Clone, Debug, Default, PartialEq)]
2328 pub struct Unblocked {}
2329
2330 impl Unblocked {
2331 pub fn get_amqp_class_id(&self) -> Identifier {
2333 10
2334 }
2335
2336 pub fn get_amqp_method_id(&self) -> Identifier {
2338 61
2339 }
2340 }
2341
2342 pub fn parse_unblocked<I: ParsableInput>(i: I) -> ParserResult<I, Unblocked> {
2344 Ok((i, Unblocked {}))
2345 }
2346
2347 pub fn gen_unblocked<'a, W: Write + BackToTheBuffer + 'a>(
2349 _: &'a Unblocked,
2350 ) -> impl SerializeFn<W> + 'a {
2351 move |mut input| {
2352 input = gen_id(61)(input)?;
2353 Ok(input)
2354 }
2355 }
2356 #[derive(Clone, Debug, Default, PartialEq)]
2358 pub struct UpdateSecret {
2359 pub new_secret: LongString,
2361 pub reason: ShortString,
2363 }
2364
2365 impl UpdateSecret {
2366 pub fn get_amqp_class_id(&self) -> Identifier {
2368 10
2369 }
2370
2371 pub fn get_amqp_method_id(&self) -> Identifier {
2373 70
2374 }
2375 }
2376
2377 pub fn parse_update_secret<I: ParsableInput>(i: I) -> ParserResult<I, UpdateSecret> {
2379 let (i, new_secret) = parse_long_string(i)?;
2380 let (i, reason) = parse_short_string(i)?;
2381 Ok((i, UpdateSecret { new_secret, reason }))
2382 }
2383
2384 pub fn gen_update_secret<'a, W: Write + BackToTheBuffer + 'a>(
2386 method: &'a UpdateSecret,
2387 ) -> impl SerializeFn<W> + 'a {
2388 move |mut input| {
2389 input = gen_id(70)(input)?;
2390 input = gen_long_string(method.new_secret.as_bytes())(input)?;
2391 input = gen_short_string(method.reason.as_str())(input)?;
2392 Ok(input)
2393 }
2394 }
2395 #[derive(Clone, Debug, Default, PartialEq)]
2397 pub struct UpdateSecretOk {}
2398
2399 impl UpdateSecretOk {
2400 pub fn get_amqp_class_id(&self) -> Identifier {
2402 10
2403 }
2404
2405 pub fn get_amqp_method_id(&self) -> Identifier {
2407 71
2408 }
2409 }
2410
2411 pub fn parse_update_secret_ok<I: ParsableInput>(i: I) -> ParserResult<I, UpdateSecretOk> {
2413 Ok((i, UpdateSecretOk {}))
2414 }
2415
2416 pub fn gen_update_secret_ok<'a, W: Write + BackToTheBuffer + 'a>(
2418 _: &'a UpdateSecretOk,
2419 ) -> impl SerializeFn<W> + 'a {
2420 move |mut input| {
2421 input = gen_id(71)(input)?;
2422 Ok(input)
2423 }
2424 }
2425}
2426pub mod channel {
2428 use super::*;
2429
2430 pub fn parse_channel<I: ParsableInput>(i: I) -> ParserResult<I, channel::AMQPMethod> {
2432 context(
2433 "parse_channel",
2434 map_opt(
2435 flat_map(parse_id, |id| {
2436 move |i| match id {
2437 10 => {
2438 context("parse_open", map(map(parse_open, AMQPMethod::Open), Some))(i)
2439 }
2440 11 => context(
2441 "parse_open_ok",
2442 map(map(parse_open_ok, AMQPMethod::OpenOk), Some),
2443 )(i),
2444 20 => {
2445 context("parse_flow", map(map(parse_flow, AMQPMethod::Flow), Some))(i)
2446 }
2447 21 => context(
2448 "parse_flow_ok",
2449 map(map(parse_flow_ok, AMQPMethod::FlowOk), Some),
2450 )(i),
2451 40 => context(
2452 "parse_close",
2453 map(map(parse_close, AMQPMethod::Close), Some),
2454 )(i),
2455 41 => context(
2456 "parse_close_ok",
2457 map(map(parse_close_ok, AMQPMethod::CloseOk), Some),
2458 )(i),
2459 _ => Ok((i, None)),
2460 }
2461 }),
2462 std::convert::identity,
2463 ),
2464 )(i)
2465 }
2466
2467 pub fn gen_channel<'a, W: Write + BackToTheBuffer + 'a>(
2469 method: &'a AMQPMethod,
2470 ) -> impl SerializeFn<W> + 'a {
2471 cookie_factory::sequence::pair(gen_id(20), move |input| match *method {
2472 AMQPMethod::Open(ref open) => gen_open(open)(input),
2473 AMQPMethod::OpenOk(ref open_ok) => gen_open_ok(open_ok)(input),
2474 AMQPMethod::Flow(ref flow) => gen_flow(flow)(input),
2475 AMQPMethod::FlowOk(ref flow_ok) => gen_flow_ok(flow_ok)(input),
2476 AMQPMethod::Close(ref close) => gen_close(close)(input),
2477 AMQPMethod::CloseOk(ref close_ok) => gen_close_ok(close_ok)(input),
2478 })
2479 }
2480
2481 #[derive(Clone, Debug, PartialEq)]
2483 pub enum AMQPMethod {
2484 Open(Open),
2486 OpenOk(OpenOk),
2488 Flow(Flow),
2490 FlowOk(FlowOk),
2492 Close(Close),
2494 CloseOk(CloseOk),
2496 }
2497
2498 #[derive(Clone, Debug, Default, PartialEq)]
2500 pub struct Open {}
2501
2502 impl Open {
2503 pub fn get_amqp_class_id(&self) -> Identifier {
2505 20
2506 }
2507
2508 pub fn get_amqp_method_id(&self) -> Identifier {
2510 10
2511 }
2512 }
2513
2514 pub fn parse_open<I: ParsableInput>(i: I) -> ParserResult<I, Open> {
2516 let (i, _) = parse_short_string(i)?;
2517 Ok((i, Open {}))
2518 }
2519
2520 pub fn gen_open<'a, W: Write + BackToTheBuffer + 'a>(
2522 _method: &'a Open,
2523 ) -> impl SerializeFn<W> + 'a {
2524 move |mut input| {
2525 input = gen_id(10)(input)?;
2526 input = gen_short_string("")(input)?;
2527 Ok(input)
2528 }
2529 }
2530 #[derive(Clone, Debug, Default, PartialEq)]
2532 pub struct OpenOk {}
2533
2534 impl OpenOk {
2535 pub fn get_amqp_class_id(&self) -> Identifier {
2537 20
2538 }
2539
2540 pub fn get_amqp_method_id(&self) -> Identifier {
2542 11
2543 }
2544 }
2545
2546 pub fn parse_open_ok<I: ParsableInput>(i: I) -> ParserResult<I, OpenOk> {
2548 let (i, _) = parse_long_string(i)?;
2549 Ok((i, OpenOk {}))
2550 }
2551
2552 pub fn gen_open_ok<'a, W: Write + BackToTheBuffer + 'a>(
2554 _method: &'a OpenOk,
2555 ) -> impl SerializeFn<W> + 'a {
2556 move |mut input| {
2557 input = gen_id(11)(input)?;
2558 input = gen_long_string(b"")(input)?;
2559 Ok(input)
2560 }
2561 }
2562 #[derive(Clone, Debug, Default, PartialEq)]
2564 pub struct Flow {
2565 pub active: Boolean,
2567 }
2568
2569 impl Flow {
2570 pub fn get_amqp_class_id(&self) -> Identifier {
2572 20
2573 }
2574
2575 pub fn get_amqp_method_id(&self) -> Identifier {
2577 20
2578 }
2579 }
2580
2581 pub fn parse_flow<I: ParsableInput>(i: I) -> ParserResult<I, Flow> {
2583 let (i, flags) = parse_flags(i, &["active"])?;
2584 Ok((
2585 i,
2586 Flow {
2587 active: flags.get_flag("active").unwrap_or(false),
2588 },
2589 ))
2590 }
2591
2592 pub fn gen_flow<'a, W: Write + BackToTheBuffer + 'a>(
2594 method: &'a Flow,
2595 ) -> impl SerializeFn<W> + 'a {
2596 move |mut input| {
2597 let mut flags = AMQPFlags::default();
2598 flags.add_flag("active".to_string(), method.active);
2599 input = gen_id(20)(input)?;
2600 input = gen_flags(&flags)(input)?;
2601 Ok(input)
2602 }
2603 }
2604 #[derive(Clone, Debug, Default, PartialEq)]
2606 pub struct FlowOk {
2607 pub active: Boolean,
2609 }
2610
2611 impl FlowOk {
2612 pub fn get_amqp_class_id(&self) -> Identifier {
2614 20
2615 }
2616
2617 pub fn get_amqp_method_id(&self) -> Identifier {
2619 21
2620 }
2621 }
2622
2623 pub fn parse_flow_ok<I: ParsableInput>(i: I) -> ParserResult<I, FlowOk> {
2625 let (i, flags) = parse_flags(i, &["active"])?;
2626 Ok((
2627 i,
2628 FlowOk {
2629 active: flags.get_flag("active").unwrap_or(false),
2630 },
2631 ))
2632 }
2633
2634 pub fn gen_flow_ok<'a, W: Write + BackToTheBuffer + 'a>(
2636 method: &'a FlowOk,
2637 ) -> impl SerializeFn<W> + 'a {
2638 move |mut input| {
2639 let mut flags = AMQPFlags::default();
2640 flags.add_flag("active".to_string(), method.active);
2641 input = gen_id(21)(input)?;
2642 input = gen_flags(&flags)(input)?;
2643 Ok(input)
2644 }
2645 }
2646 #[derive(Clone, Debug, Default, PartialEq)]
2648 pub struct Close {
2649 pub reply_code: ShortUInt,
2651 pub reply_text: ShortString,
2653 pub class_id: ShortUInt,
2655 pub method_id: ShortUInt,
2657 }
2658
2659 impl Close {
2660 pub fn get_amqp_class_id(&self) -> Identifier {
2662 20
2663 }
2664
2665 pub fn get_amqp_method_id(&self) -> Identifier {
2667 40
2668 }
2669 }
2670
2671 pub fn parse_close<I: ParsableInput>(i: I) -> ParserResult<I, Close> {
2673 let (i, reply_code) = parse_short_uint(i)?;
2674 let (i, reply_text) = parse_short_string(i)?;
2675 let (i, class_id) = parse_short_uint(i)?;
2676 let (i, method_id) = parse_short_uint(i)?;
2677 Ok((
2678 i,
2679 Close {
2680 reply_code,
2681 reply_text,
2682 class_id,
2683 method_id,
2684 },
2685 ))
2686 }
2687
2688 pub fn gen_close<'a, W: Write + BackToTheBuffer + 'a>(
2690 method: &'a Close,
2691 ) -> impl SerializeFn<W> + 'a {
2692 move |mut input| {
2693 input = gen_id(40)(input)?;
2694 input = gen_short_uint(method.reply_code)(input)?;
2695 input = gen_short_string(method.reply_text.as_str())(input)?;
2696 input = gen_short_uint(method.class_id)(input)?;
2697 input = gen_short_uint(method.method_id)(input)?;
2698 Ok(input)
2699 }
2700 }
2701 #[derive(Clone, Debug, Default, PartialEq)]
2703 pub struct CloseOk {}
2704
2705 impl CloseOk {
2706 pub fn get_amqp_class_id(&self) -> Identifier {
2708 20
2709 }
2710
2711 pub fn get_amqp_method_id(&self) -> Identifier {
2713 41
2714 }
2715 }
2716
2717 pub fn parse_close_ok<I: ParsableInput>(i: I) -> ParserResult<I, CloseOk> {
2719 Ok((i, CloseOk {}))
2720 }
2721
2722 pub fn gen_close_ok<'a, W: Write + BackToTheBuffer + 'a>(
2724 _: &'a CloseOk,
2725 ) -> impl SerializeFn<W> + 'a {
2726 move |mut input| {
2727 input = gen_id(41)(input)?;
2728 Ok(input)
2729 }
2730 }
2731}
2732pub mod access {
2734 use super::*;
2735
2736 pub fn parse_access<I: ParsableInput>(i: I) -> ParserResult<I, access::AMQPMethod> {
2738 context(
2739 "parse_access",
2740 map_opt(
2741 flat_map(parse_id, |id| {
2742 move |i| match id {
2743 10 => context(
2744 "parse_request",
2745 map(map(parse_request, AMQPMethod::Request), Some),
2746 )(i),
2747 11 => context(
2748 "parse_request_ok",
2749 map(map(parse_request_ok, AMQPMethod::RequestOk), Some),
2750 )(i),
2751 _ => Ok((i, None)),
2752 }
2753 }),
2754 std::convert::identity,
2755 ),
2756 )(i)
2757 }
2758
2759 pub fn gen_access<'a, W: Write + BackToTheBuffer + 'a>(
2761 method: &'a AMQPMethod,
2762 ) -> impl SerializeFn<W> + 'a {
2763 cookie_factory::sequence::pair(gen_id(30), move |input| match *method {
2764 AMQPMethod::Request(ref request) => gen_request(request)(input),
2765 AMQPMethod::RequestOk(ref request_ok) => gen_request_ok(request_ok)(input),
2766 })
2767 }
2768
2769 #[derive(Clone, Debug, PartialEq)]
2771 pub enum AMQPMethod {
2772 Request(Request),
2774 RequestOk(RequestOk),
2776 }
2777
2778 #[derive(Clone, Debug, Default, PartialEq)]
2780 pub struct Request {
2781 pub realm: ShortString,
2783 pub exclusive: Boolean,
2785 pub passive: Boolean,
2787 pub active: Boolean,
2789 pub write: Boolean,
2791 pub read: Boolean,
2793 }
2794
2795 impl Request {
2796 pub fn get_amqp_class_id(&self) -> Identifier {
2798 30
2799 }
2800
2801 pub fn get_amqp_method_id(&self) -> Identifier {
2803 10
2804 }
2805 }
2806
2807 pub fn parse_request<I: ParsableInput>(i: I) -> ParserResult<I, Request> {
2809 let (i, realm) = parse_short_string(i)?;
2810 let (i, flags) = parse_flags(i, &["exclusive", "passive", "active", "write", "read"])?;
2811 Ok((
2812 i,
2813 Request {
2814 realm,
2815 exclusive: flags.get_flag("exclusive").unwrap_or(false),
2816 passive: flags.get_flag("passive").unwrap_or(false),
2817 active: flags.get_flag("active").unwrap_or(false),
2818 write: flags.get_flag("write").unwrap_or(false),
2819 read: flags.get_flag("read").unwrap_or(false),
2820 },
2821 ))
2822 }
2823
2824 pub fn gen_request<'a, W: Write + BackToTheBuffer + 'a>(
2826 method: &'a Request,
2827 ) -> impl SerializeFn<W> + 'a {
2828 move |mut input| {
2829 let mut flags = AMQPFlags::default();
2830 flags.add_flag("exclusive".to_string(), method.exclusive);
2831 flags.add_flag("passive".to_string(), method.passive);
2832 flags.add_flag("active".to_string(), method.active);
2833 flags.add_flag("write".to_string(), method.write);
2834 flags.add_flag("read".to_string(), method.read);
2835 input = gen_id(10)(input)?;
2836 input = gen_short_string(method.realm.as_str())(input)?;
2837 input = gen_flags(&flags)(input)?;
2838 Ok(input)
2839 }
2840 }
2841 #[derive(Clone, Debug, Default, PartialEq)]
2843 pub struct RequestOk {}
2844
2845 impl RequestOk {
2846 pub fn get_amqp_class_id(&self) -> Identifier {
2848 30
2849 }
2850
2851 pub fn get_amqp_method_id(&self) -> Identifier {
2853 11
2854 }
2855 }
2856
2857 pub fn parse_request_ok<I: ParsableInput>(i: I) -> ParserResult<I, RequestOk> {
2859 let (i, _) = parse_short_uint(i)?;
2860 Ok((i, RequestOk {}))
2861 }
2862
2863 pub fn gen_request_ok<'a, W: Write + BackToTheBuffer + 'a>(
2865 _method: &'a RequestOk,
2866 ) -> impl SerializeFn<W> + 'a {
2867 move |mut input| {
2868 input = gen_id(11)(input)?;
2869 input = gen_short_uint(1)(input)?;
2870 Ok(input)
2871 }
2872 }
2873}
2874pub mod exchange {
2876 use super::*;
2877
2878 pub fn parse_exchange<I: ParsableInput>(i: I) -> ParserResult<I, exchange::AMQPMethod> {
2880 context(
2881 "parse_exchange",
2882 map_opt(
2883 flat_map(parse_id, |id| {
2884 move |i| match id {
2885 10 => context(
2886 "parse_declare",
2887 map(map(parse_declare, AMQPMethod::Declare), Some),
2888 )(i),
2889 11 => context(
2890 "parse_declare_ok",
2891 map(map(parse_declare_ok, AMQPMethod::DeclareOk), Some),
2892 )(i),
2893 20 => context(
2894 "parse_delete",
2895 map(map(parse_delete, AMQPMethod::Delete), Some),
2896 )(i),
2897 21 => context(
2898 "parse_delete_ok",
2899 map(map(parse_delete_ok, AMQPMethod::DeleteOk), Some),
2900 )(i),
2901 30 => {
2902 context("parse_bind", map(map(parse_bind, AMQPMethod::Bind), Some))(i)
2903 }
2904 31 => context(
2905 "parse_bind_ok",
2906 map(map(parse_bind_ok, AMQPMethod::BindOk), Some),
2907 )(i),
2908 40 => context(
2909 "parse_unbind",
2910 map(map(parse_unbind, AMQPMethod::Unbind), Some),
2911 )(i),
2912 51 => context(
2913 "parse_unbind_ok",
2914 map(map(parse_unbind_ok, AMQPMethod::UnbindOk), Some),
2915 )(i),
2916 _ => Ok((i, None)),
2917 }
2918 }),
2919 std::convert::identity,
2920 ),
2921 )(i)
2922 }
2923
2924 pub fn gen_exchange<'a, W: Write + BackToTheBuffer + 'a>(
2926 method: &'a AMQPMethod,
2927 ) -> impl SerializeFn<W> + 'a {
2928 cookie_factory::sequence::pair(gen_id(40), move |input| match *method {
2929 AMQPMethod::Declare(ref declare) => gen_declare(declare)(input),
2930 AMQPMethod::DeclareOk(ref declare_ok) => gen_declare_ok(declare_ok)(input),
2931 AMQPMethod::Delete(ref delete) => gen_delete(delete)(input),
2932 AMQPMethod::DeleteOk(ref delete_ok) => gen_delete_ok(delete_ok)(input),
2933 AMQPMethod::Bind(ref bind) => gen_bind(bind)(input),
2934 AMQPMethod::BindOk(ref bind_ok) => gen_bind_ok(bind_ok)(input),
2935 AMQPMethod::Unbind(ref unbind) => gen_unbind(unbind)(input),
2936 AMQPMethod::UnbindOk(ref unbind_ok) => gen_unbind_ok(unbind_ok)(input),
2937 })
2938 }
2939
2940 #[derive(Clone, Debug, PartialEq)]
2942 pub enum AMQPMethod {
2943 Declare(Declare),
2945 DeclareOk(DeclareOk),
2947 Delete(Delete),
2949 DeleteOk(DeleteOk),
2951 Bind(Bind),
2953 BindOk(BindOk),
2955 Unbind(Unbind),
2957 UnbindOk(UnbindOk),
2959 }
2960
2961 #[derive(Clone, Debug, Default, PartialEq)]
2963 pub struct Declare {
2964 pub exchange: ShortString,
2966 pub kind: ShortString,
2968 pub passive: Boolean,
2970 pub durable: Boolean,
2972 pub auto_delete: Boolean,
2974 pub internal: Boolean,
2976 pub nowait: Boolean,
2978 pub arguments: FieldTable,
2980 }
2981
2982 impl Declare {
2983 pub fn get_amqp_class_id(&self) -> Identifier {
2985 40
2986 }
2987
2988 pub fn get_amqp_method_id(&self) -> Identifier {
2990 10
2991 }
2992 }
2993
2994 pub fn parse_declare<I: ParsableInput>(i: I) -> ParserResult<I, Declare> {
2996 let (i, _) = parse_short_uint(i)?;
2997 let (i, exchange) = parse_short_string(i)?;
2998 let (i, kind) = parse_short_string(i)?;
2999 let (i, flags) = parse_flags(
3000 i,
3001 &["passive", "durable", "auto_delete", "internal", "nowait"],
3002 )?;
3003 let (i, arguments) = parse_field_table(i)?;
3004 Ok((
3005 i,
3006 Declare {
3007 exchange,
3008 kind,
3009 passive: flags.get_flag("passive").unwrap_or(false),
3010 durable: flags.get_flag("durable").unwrap_or(false),
3011 auto_delete: flags.get_flag("auto_delete").unwrap_or(false),
3012 internal: flags.get_flag("internal").unwrap_or(false),
3013 nowait: flags.get_flag("nowait").unwrap_or(false),
3014 arguments,
3015 },
3016 ))
3017 }
3018
3019 pub fn gen_declare<'a, W: Write + BackToTheBuffer + 'a>(
3021 method: &'a Declare,
3022 ) -> impl SerializeFn<W> + 'a {
3023 move |mut input| {
3024 let mut flags = AMQPFlags::default();
3025 flags.add_flag("passive".to_string(), method.passive);
3026 flags.add_flag("durable".to_string(), method.durable);
3027 flags.add_flag("auto_delete".to_string(), method.auto_delete);
3028 flags.add_flag("internal".to_string(), method.internal);
3029 flags.add_flag("nowait".to_string(), method.nowait);
3030 input = gen_id(10)(input)?;
3031 input = gen_short_uint(0)(input)?;
3032 input = gen_short_string(method.exchange.as_str())(input)?;
3033 input = gen_short_string(method.kind.as_str())(input)?;
3034 input = gen_flags(&flags)(input)?;
3035 input = gen_field_table(&method.arguments)(input)?;
3036 Ok(input)
3037 }
3038 }
3039 #[derive(Clone, Debug, Default, PartialEq)]
3041 pub struct DeclareOk {}
3042
3043 impl DeclareOk {
3044 pub fn get_amqp_class_id(&self) -> Identifier {
3046 40
3047 }
3048
3049 pub fn get_amqp_method_id(&self) -> Identifier {
3051 11
3052 }
3053 }
3054
3055 pub fn parse_declare_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeclareOk> {
3057 Ok((i, DeclareOk {}))
3058 }
3059
3060 pub fn gen_declare_ok<'a, W: Write + BackToTheBuffer + 'a>(
3062 _: &'a DeclareOk,
3063 ) -> impl SerializeFn<W> + 'a {
3064 move |mut input| {
3065 input = gen_id(11)(input)?;
3066 Ok(input)
3067 }
3068 }
3069 #[derive(Clone, Debug, Default, PartialEq)]
3071 pub struct Delete {
3072 pub exchange: ShortString,
3074 pub if_unused: Boolean,
3076 pub nowait: Boolean,
3078 }
3079
3080 impl Delete {
3081 pub fn get_amqp_class_id(&self) -> Identifier {
3083 40
3084 }
3085
3086 pub fn get_amqp_method_id(&self) -> Identifier {
3088 20
3089 }
3090 }
3091
3092 pub fn parse_delete<I: ParsableInput>(i: I) -> ParserResult<I, Delete> {
3094 let (i, _) = parse_short_uint(i)?;
3095 let (i, exchange) = parse_short_string(i)?;
3096 let (i, flags) = parse_flags(i, &["if_unused", "nowait"])?;
3097 Ok((
3098 i,
3099 Delete {
3100 exchange,
3101 if_unused: flags.get_flag("if_unused").unwrap_or(false),
3102 nowait: flags.get_flag("nowait").unwrap_or(false),
3103 },
3104 ))
3105 }
3106
3107 pub fn gen_delete<'a, W: Write + BackToTheBuffer + 'a>(
3109 method: &'a Delete,
3110 ) -> impl SerializeFn<W> + 'a {
3111 move |mut input| {
3112 let mut flags = AMQPFlags::default();
3113 flags.add_flag("if_unused".to_string(), method.if_unused);
3114 flags.add_flag("nowait".to_string(), method.nowait);
3115 input = gen_id(20)(input)?;
3116 input = gen_short_uint(0)(input)?;
3117 input = gen_short_string(method.exchange.as_str())(input)?;
3118 input = gen_flags(&flags)(input)?;
3119 Ok(input)
3120 }
3121 }
3122 #[derive(Clone, Debug, Default, PartialEq)]
3124 pub struct DeleteOk {}
3125
3126 impl DeleteOk {
3127 pub fn get_amqp_class_id(&self) -> Identifier {
3129 40
3130 }
3131
3132 pub fn get_amqp_method_id(&self) -> Identifier {
3134 21
3135 }
3136 }
3137
3138 pub fn parse_delete_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeleteOk> {
3140 Ok((i, DeleteOk {}))
3141 }
3142
3143 pub fn gen_delete_ok<'a, W: Write + BackToTheBuffer + 'a>(
3145 _: &'a DeleteOk,
3146 ) -> impl SerializeFn<W> + 'a {
3147 move |mut input| {
3148 input = gen_id(21)(input)?;
3149 Ok(input)
3150 }
3151 }
3152 #[derive(Clone, Debug, Default, PartialEq)]
3154 pub struct Bind {
3155 pub destination: ShortString,
3157 pub source: ShortString,
3159 pub routing_key: ShortString,
3161 pub nowait: Boolean,
3163 pub arguments: FieldTable,
3165 }
3166
3167 impl Bind {
3168 pub fn get_amqp_class_id(&self) -> Identifier {
3170 40
3171 }
3172
3173 pub fn get_amqp_method_id(&self) -> Identifier {
3175 30
3176 }
3177 }
3178
3179 pub fn parse_bind<I: ParsableInput>(i: I) -> ParserResult<I, Bind> {
3181 let (i, _) = parse_short_uint(i)?;
3182 let (i, destination) = parse_short_string(i)?;
3183 let (i, source) = parse_short_string(i)?;
3184 let (i, routing_key) = parse_short_string(i)?;
3185 let (i, flags) = parse_flags(i, &["nowait"])?;
3186 let (i, arguments) = parse_field_table(i)?;
3187 Ok((
3188 i,
3189 Bind {
3190 destination,
3191 source,
3192 routing_key,
3193 nowait: flags.get_flag("nowait").unwrap_or(false),
3194 arguments,
3195 },
3196 ))
3197 }
3198
3199 pub fn gen_bind<'a, W: Write + BackToTheBuffer + 'a>(
3201 method: &'a Bind,
3202 ) -> impl SerializeFn<W> + 'a {
3203 move |mut input| {
3204 let mut flags = AMQPFlags::default();
3205 flags.add_flag("nowait".to_string(), method.nowait);
3206 input = gen_id(30)(input)?;
3207 input = gen_short_uint(0)(input)?;
3208 input = gen_short_string(method.destination.as_str())(input)?;
3209 input = gen_short_string(method.source.as_str())(input)?;
3210 input = gen_short_string(method.routing_key.as_str())(input)?;
3211 input = gen_flags(&flags)(input)?;
3212 input = gen_field_table(&method.arguments)(input)?;
3213 Ok(input)
3214 }
3215 }
3216 #[derive(Clone, Debug, Default, PartialEq)]
3218 pub struct BindOk {}
3219
3220 impl BindOk {
3221 pub fn get_amqp_class_id(&self) -> Identifier {
3223 40
3224 }
3225
3226 pub fn get_amqp_method_id(&self) -> Identifier {
3228 31
3229 }
3230 }
3231
3232 pub fn parse_bind_ok<I: ParsableInput>(i: I) -> ParserResult<I, BindOk> {
3234 Ok((i, BindOk {}))
3235 }
3236
3237 pub fn gen_bind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3239 _: &'a BindOk,
3240 ) -> impl SerializeFn<W> + 'a {
3241 move |mut input| {
3242 input = gen_id(31)(input)?;
3243 Ok(input)
3244 }
3245 }
3246 #[derive(Clone, Debug, Default, PartialEq)]
3248 pub struct Unbind {
3249 pub destination: ShortString,
3251 pub source: ShortString,
3253 pub routing_key: ShortString,
3255 pub nowait: Boolean,
3257 pub arguments: FieldTable,
3259 }
3260
3261 impl Unbind {
3262 pub fn get_amqp_class_id(&self) -> Identifier {
3264 40
3265 }
3266
3267 pub fn get_amqp_method_id(&self) -> Identifier {
3269 40
3270 }
3271 }
3272
3273 pub fn parse_unbind<I: ParsableInput>(i: I) -> ParserResult<I, Unbind> {
3275 let (i, _) = parse_short_uint(i)?;
3276 let (i, destination) = parse_short_string(i)?;
3277 let (i, source) = parse_short_string(i)?;
3278 let (i, routing_key) = parse_short_string(i)?;
3279 let (i, flags) = parse_flags(i, &["nowait"])?;
3280 let (i, arguments) = parse_field_table(i)?;
3281 Ok((
3282 i,
3283 Unbind {
3284 destination,
3285 source,
3286 routing_key,
3287 nowait: flags.get_flag("nowait").unwrap_or(false),
3288 arguments,
3289 },
3290 ))
3291 }
3292
3293 pub fn gen_unbind<'a, W: Write + BackToTheBuffer + 'a>(
3295 method: &'a Unbind,
3296 ) -> impl SerializeFn<W> + 'a {
3297 move |mut input| {
3298 let mut flags = AMQPFlags::default();
3299 flags.add_flag("nowait".to_string(), method.nowait);
3300 input = gen_id(40)(input)?;
3301 input = gen_short_uint(0)(input)?;
3302 input = gen_short_string(method.destination.as_str())(input)?;
3303 input = gen_short_string(method.source.as_str())(input)?;
3304 input = gen_short_string(method.routing_key.as_str())(input)?;
3305 input = gen_flags(&flags)(input)?;
3306 input = gen_field_table(&method.arguments)(input)?;
3307 Ok(input)
3308 }
3309 }
3310 #[derive(Clone, Debug, Default, PartialEq)]
3312 pub struct UnbindOk {}
3313
3314 impl UnbindOk {
3315 pub fn get_amqp_class_id(&self) -> Identifier {
3317 40
3318 }
3319
3320 pub fn get_amqp_method_id(&self) -> Identifier {
3322 51
3323 }
3324 }
3325
3326 pub fn parse_unbind_ok<I: ParsableInput>(i: I) -> ParserResult<I, UnbindOk> {
3328 Ok((i, UnbindOk {}))
3329 }
3330
3331 pub fn gen_unbind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3333 _: &'a UnbindOk,
3334 ) -> impl SerializeFn<W> + 'a {
3335 move |mut input| {
3336 input = gen_id(51)(input)?;
3337 Ok(input)
3338 }
3339 }
3340}
3341pub mod queue {
3343 use super::*;
3344
3345 pub fn parse_queue<I: ParsableInput>(i: I) -> ParserResult<I, queue::AMQPMethod> {
3347 context(
3348 "parse_queue",
3349 map_opt(
3350 flat_map(parse_id, |id| {
3351 move |i| match id {
3352 10 => context(
3353 "parse_declare",
3354 map(map(parse_declare, AMQPMethod::Declare), Some),
3355 )(i),
3356 11 => context(
3357 "parse_declare_ok",
3358 map(map(parse_declare_ok, AMQPMethod::DeclareOk), Some),
3359 )(i),
3360 20 => {
3361 context("parse_bind", map(map(parse_bind, AMQPMethod::Bind), Some))(i)
3362 }
3363 21 => context(
3364 "parse_bind_ok",
3365 map(map(parse_bind_ok, AMQPMethod::BindOk), Some),
3366 )(i),
3367 30 => context(
3368 "parse_purge",
3369 map(map(parse_purge, AMQPMethod::Purge), Some),
3370 )(i),
3371 31 => context(
3372 "parse_purge_ok",
3373 map(map(parse_purge_ok, AMQPMethod::PurgeOk), Some),
3374 )(i),
3375 40 => context(
3376 "parse_delete",
3377 map(map(parse_delete, AMQPMethod::Delete), Some),
3378 )(i),
3379 41 => context(
3380 "parse_delete_ok",
3381 map(map(parse_delete_ok, AMQPMethod::DeleteOk), Some),
3382 )(i),
3383 50 => context(
3384 "parse_unbind",
3385 map(map(parse_unbind, AMQPMethod::Unbind), Some),
3386 )(i),
3387 51 => context(
3388 "parse_unbind_ok",
3389 map(map(parse_unbind_ok, AMQPMethod::UnbindOk), Some),
3390 )(i),
3391 _ => Ok((i, None)),
3392 }
3393 }),
3394 std::convert::identity,
3395 ),
3396 )(i)
3397 }
3398
3399 pub fn gen_queue<'a, W: Write + BackToTheBuffer + 'a>(
3401 method: &'a AMQPMethod,
3402 ) -> impl SerializeFn<W> + 'a {
3403 cookie_factory::sequence::pair(gen_id(50), move |input| match *method {
3404 AMQPMethod::Declare(ref declare) => gen_declare(declare)(input),
3405 AMQPMethod::DeclareOk(ref declare_ok) => gen_declare_ok(declare_ok)(input),
3406 AMQPMethod::Bind(ref bind) => gen_bind(bind)(input),
3407 AMQPMethod::BindOk(ref bind_ok) => gen_bind_ok(bind_ok)(input),
3408 AMQPMethod::Purge(ref purge) => gen_purge(purge)(input),
3409 AMQPMethod::PurgeOk(ref purge_ok) => gen_purge_ok(purge_ok)(input),
3410 AMQPMethod::Delete(ref delete) => gen_delete(delete)(input),
3411 AMQPMethod::DeleteOk(ref delete_ok) => gen_delete_ok(delete_ok)(input),
3412 AMQPMethod::Unbind(ref unbind) => gen_unbind(unbind)(input),
3413 AMQPMethod::UnbindOk(ref unbind_ok) => gen_unbind_ok(unbind_ok)(input),
3414 })
3415 }
3416
3417 #[derive(Clone, Debug, PartialEq)]
3419 pub enum AMQPMethod {
3420 Declare(Declare),
3422 DeclareOk(DeclareOk),
3424 Bind(Bind),
3426 BindOk(BindOk),
3428 Purge(Purge),
3430 PurgeOk(PurgeOk),
3432 Delete(Delete),
3434 DeleteOk(DeleteOk),
3436 Unbind(Unbind),
3438 UnbindOk(UnbindOk),
3440 }
3441
3442 #[derive(Clone, Debug, Default, PartialEq)]
3444 pub struct Declare {
3445 pub queue: ShortString,
3447 pub passive: Boolean,
3449 pub durable: Boolean,
3451 pub exclusive: Boolean,
3453 pub auto_delete: Boolean,
3455 pub nowait: Boolean,
3457 pub arguments: FieldTable,
3459 }
3460
3461 impl Declare {
3462 pub fn get_amqp_class_id(&self) -> Identifier {
3464 50
3465 }
3466
3467 pub fn get_amqp_method_id(&self) -> Identifier {
3469 10
3470 }
3471 }
3472
3473 pub fn parse_declare<I: ParsableInput>(i: I) -> ParserResult<I, Declare> {
3475 let (i, _) = parse_short_uint(i)?;
3476 let (i, queue) = parse_short_string(i)?;
3477 let (i, flags) = parse_flags(
3478 i,
3479 &["passive", "durable", "exclusive", "auto_delete", "nowait"],
3480 )?;
3481 let (i, arguments) = parse_field_table(i)?;
3482 Ok((
3483 i,
3484 Declare {
3485 queue,
3486 passive: flags.get_flag("passive").unwrap_or(false),
3487 durable: flags.get_flag("durable").unwrap_or(false),
3488 exclusive: flags.get_flag("exclusive").unwrap_or(false),
3489 auto_delete: flags.get_flag("auto_delete").unwrap_or(false),
3490 nowait: flags.get_flag("nowait").unwrap_or(false),
3491 arguments,
3492 },
3493 ))
3494 }
3495
3496 pub fn gen_declare<'a, W: Write + BackToTheBuffer + 'a>(
3498 method: &'a Declare,
3499 ) -> impl SerializeFn<W> + 'a {
3500 move |mut input| {
3501 let mut flags = AMQPFlags::default();
3502 flags.add_flag("passive".to_string(), method.passive);
3503 flags.add_flag("durable".to_string(), method.durable);
3504 flags.add_flag("exclusive".to_string(), method.exclusive);
3505 flags.add_flag("auto_delete".to_string(), method.auto_delete);
3506 flags.add_flag("nowait".to_string(), method.nowait);
3507 input = gen_id(10)(input)?;
3508 input = gen_short_uint(0)(input)?;
3509 input = gen_short_string(method.queue.as_str())(input)?;
3510 input = gen_flags(&flags)(input)?;
3511 input = gen_field_table(&method.arguments)(input)?;
3512 Ok(input)
3513 }
3514 }
3515 #[derive(Clone, Debug, Default, PartialEq)]
3517 pub struct DeclareOk {
3518 pub queue: ShortString,
3520 pub message_count: LongUInt,
3522 pub consumer_count: LongUInt,
3524 }
3525
3526 impl DeclareOk {
3527 pub fn get_amqp_class_id(&self) -> Identifier {
3529 50
3530 }
3531
3532 pub fn get_amqp_method_id(&self) -> Identifier {
3534 11
3535 }
3536 }
3537
3538 pub fn parse_declare_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeclareOk> {
3540 let (i, queue) = parse_short_string(i)?;
3541 let (i, message_count) = parse_long_uint(i)?;
3542 let (i, consumer_count) = parse_long_uint(i)?;
3543 Ok((
3544 i,
3545 DeclareOk {
3546 queue,
3547 message_count,
3548 consumer_count,
3549 },
3550 ))
3551 }
3552
3553 pub fn gen_declare_ok<'a, W: Write + BackToTheBuffer + 'a>(
3555 method: &'a DeclareOk,
3556 ) -> impl SerializeFn<W> + 'a {
3557 move |mut input| {
3558 input = gen_id(11)(input)?;
3559 input = gen_short_string(method.queue.as_str())(input)?;
3560 input = gen_long_uint(method.message_count)(input)?;
3561 input = gen_long_uint(method.consumer_count)(input)?;
3562 Ok(input)
3563 }
3564 }
3565 #[derive(Clone, Debug, Default, PartialEq)]
3567 pub struct Bind {
3568 pub queue: ShortString,
3570 pub exchange: ShortString,
3572 pub routing_key: ShortString,
3574 pub nowait: Boolean,
3576 pub arguments: FieldTable,
3578 }
3579
3580 impl Bind {
3581 pub fn get_amqp_class_id(&self) -> Identifier {
3583 50
3584 }
3585
3586 pub fn get_amqp_method_id(&self) -> Identifier {
3588 20
3589 }
3590 }
3591
3592 pub fn parse_bind<I: ParsableInput>(i: I) -> ParserResult<I, Bind> {
3594 let (i, _) = parse_short_uint(i)?;
3595 let (i, queue) = parse_short_string(i)?;
3596 let (i, exchange) = parse_short_string(i)?;
3597 let (i, routing_key) = parse_short_string(i)?;
3598 let (i, flags) = parse_flags(i, &["nowait"])?;
3599 let (i, arguments) = parse_field_table(i)?;
3600 Ok((
3601 i,
3602 Bind {
3603 queue,
3604 exchange,
3605 routing_key,
3606 nowait: flags.get_flag("nowait").unwrap_or(false),
3607 arguments,
3608 },
3609 ))
3610 }
3611
3612 pub fn gen_bind<'a, W: Write + BackToTheBuffer + 'a>(
3614 method: &'a Bind,
3615 ) -> impl SerializeFn<W> + 'a {
3616 move |mut input| {
3617 let mut flags = AMQPFlags::default();
3618 flags.add_flag("nowait".to_string(), method.nowait);
3619 input = gen_id(20)(input)?;
3620 input = gen_short_uint(0)(input)?;
3621 input = gen_short_string(method.queue.as_str())(input)?;
3622 input = gen_short_string(method.exchange.as_str())(input)?;
3623 input = gen_short_string(method.routing_key.as_str())(input)?;
3624 input = gen_flags(&flags)(input)?;
3625 input = gen_field_table(&method.arguments)(input)?;
3626 Ok(input)
3627 }
3628 }
3629 #[derive(Clone, Debug, Default, PartialEq)]
3631 pub struct BindOk {}
3632
3633 impl BindOk {
3634 pub fn get_amqp_class_id(&self) -> Identifier {
3636 50
3637 }
3638
3639 pub fn get_amqp_method_id(&self) -> Identifier {
3641 21
3642 }
3643 }
3644
3645 pub fn parse_bind_ok<I: ParsableInput>(i: I) -> ParserResult<I, BindOk> {
3647 Ok((i, BindOk {}))
3648 }
3649
3650 pub fn gen_bind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3652 _: &'a BindOk,
3653 ) -> impl SerializeFn<W> + 'a {
3654 move |mut input| {
3655 input = gen_id(21)(input)?;
3656 Ok(input)
3657 }
3658 }
3659 #[derive(Clone, Debug, Default, PartialEq)]
3661 pub struct Purge {
3662 pub queue: ShortString,
3664 pub nowait: Boolean,
3666 }
3667
3668 impl Purge {
3669 pub fn get_amqp_class_id(&self) -> Identifier {
3671 50
3672 }
3673
3674 pub fn get_amqp_method_id(&self) -> Identifier {
3676 30
3677 }
3678 }
3679
3680 pub fn parse_purge<I: ParsableInput>(i: I) -> ParserResult<I, Purge> {
3682 let (i, _) = parse_short_uint(i)?;
3683 let (i, queue) = parse_short_string(i)?;
3684 let (i, flags) = parse_flags(i, &["nowait"])?;
3685 Ok((
3686 i,
3687 Purge {
3688 queue,
3689 nowait: flags.get_flag("nowait").unwrap_or(false),
3690 },
3691 ))
3692 }
3693
3694 pub fn gen_purge<'a, W: Write + BackToTheBuffer + 'a>(
3696 method: &'a Purge,
3697 ) -> impl SerializeFn<W> + 'a {
3698 move |mut input| {
3699 let mut flags = AMQPFlags::default();
3700 flags.add_flag("nowait".to_string(), method.nowait);
3701 input = gen_id(30)(input)?;
3702 input = gen_short_uint(0)(input)?;
3703 input = gen_short_string(method.queue.as_str())(input)?;
3704 input = gen_flags(&flags)(input)?;
3705 Ok(input)
3706 }
3707 }
3708 #[derive(Clone, Debug, Default, PartialEq)]
3710 pub struct PurgeOk {
3711 pub message_count: LongUInt,
3713 }
3714
3715 impl PurgeOk {
3716 pub fn get_amqp_class_id(&self) -> Identifier {
3718 50
3719 }
3720
3721 pub fn get_amqp_method_id(&self) -> Identifier {
3723 31
3724 }
3725 }
3726
3727 pub fn parse_purge_ok<I: ParsableInput>(i: I) -> ParserResult<I, PurgeOk> {
3729 let (i, message_count) = parse_long_uint(i)?;
3730 Ok((i, PurgeOk { message_count }))
3731 }
3732
3733 pub fn gen_purge_ok<'a, W: Write + BackToTheBuffer + 'a>(
3735 method: &'a PurgeOk,
3736 ) -> impl SerializeFn<W> + 'a {
3737 move |mut input| {
3738 input = gen_id(31)(input)?;
3739 input = gen_long_uint(method.message_count)(input)?;
3740 Ok(input)
3741 }
3742 }
3743 #[derive(Clone, Debug, Default, PartialEq)]
3745 pub struct Delete {
3746 pub queue: ShortString,
3748 pub if_unused: Boolean,
3750 pub if_empty: Boolean,
3752 pub nowait: Boolean,
3754 }
3755
3756 impl Delete {
3757 pub fn get_amqp_class_id(&self) -> Identifier {
3759 50
3760 }
3761
3762 pub fn get_amqp_method_id(&self) -> Identifier {
3764 40
3765 }
3766 }
3767
3768 pub fn parse_delete<I: ParsableInput>(i: I) -> ParserResult<I, Delete> {
3770 let (i, _) = parse_short_uint(i)?;
3771 let (i, queue) = parse_short_string(i)?;
3772 let (i, flags) = parse_flags(i, &["if_unused", "if_empty", "nowait"])?;
3773 Ok((
3774 i,
3775 Delete {
3776 queue,
3777 if_unused: flags.get_flag("if_unused").unwrap_or(false),
3778 if_empty: flags.get_flag("if_empty").unwrap_or(false),
3779 nowait: flags.get_flag("nowait").unwrap_or(false),
3780 },
3781 ))
3782 }
3783
3784 pub fn gen_delete<'a, W: Write + BackToTheBuffer + 'a>(
3786 method: &'a Delete,
3787 ) -> impl SerializeFn<W> + 'a {
3788 move |mut input| {
3789 let mut flags = AMQPFlags::default();
3790 flags.add_flag("if_unused".to_string(), method.if_unused);
3791 flags.add_flag("if_empty".to_string(), method.if_empty);
3792 flags.add_flag("nowait".to_string(), method.nowait);
3793 input = gen_id(40)(input)?;
3794 input = gen_short_uint(0)(input)?;
3795 input = gen_short_string(method.queue.as_str())(input)?;
3796 input = gen_flags(&flags)(input)?;
3797 Ok(input)
3798 }
3799 }
3800 #[derive(Clone, Debug, Default, PartialEq)]
3802 pub struct DeleteOk {
3803 pub message_count: LongUInt,
3805 }
3806
3807 impl DeleteOk {
3808 pub fn get_amqp_class_id(&self) -> Identifier {
3810 50
3811 }
3812
3813 pub fn get_amqp_method_id(&self) -> Identifier {
3815 41
3816 }
3817 }
3818
3819 pub fn parse_delete_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeleteOk> {
3821 let (i, message_count) = parse_long_uint(i)?;
3822 Ok((i, DeleteOk { message_count }))
3823 }
3824
3825 pub fn gen_delete_ok<'a, W: Write + BackToTheBuffer + 'a>(
3827 method: &'a DeleteOk,
3828 ) -> impl SerializeFn<W> + 'a {
3829 move |mut input| {
3830 input = gen_id(41)(input)?;
3831 input = gen_long_uint(method.message_count)(input)?;
3832 Ok(input)
3833 }
3834 }
3835 #[derive(Clone, Debug, Default, PartialEq)]
3837 pub struct Unbind {
3838 pub queue: ShortString,
3840 pub exchange: ShortString,
3842 pub routing_key: ShortString,
3844 pub arguments: FieldTable,
3846 }
3847
3848 impl Unbind {
3849 pub fn get_amqp_class_id(&self) -> Identifier {
3851 50
3852 }
3853
3854 pub fn get_amqp_method_id(&self) -> Identifier {
3856 50
3857 }
3858 }
3859
3860 pub fn parse_unbind<I: ParsableInput>(i: I) -> ParserResult<I, Unbind> {
3862 let (i, _) = parse_short_uint(i)?;
3863 let (i, queue) = parse_short_string(i)?;
3864 let (i, exchange) = parse_short_string(i)?;
3865 let (i, routing_key) = parse_short_string(i)?;
3866 let (i, arguments) = parse_field_table(i)?;
3867 Ok((
3868 i,
3869 Unbind {
3870 queue,
3871 exchange,
3872 routing_key,
3873 arguments,
3874 },
3875 ))
3876 }
3877
3878 pub fn gen_unbind<'a, W: Write + BackToTheBuffer + 'a>(
3880 method: &'a Unbind,
3881 ) -> impl SerializeFn<W> + 'a {
3882 move |mut input| {
3883 input = gen_id(50)(input)?;
3884 input = gen_short_uint(0)(input)?;
3885 input = gen_short_string(method.queue.as_str())(input)?;
3886 input = gen_short_string(method.exchange.as_str())(input)?;
3887 input = gen_short_string(method.routing_key.as_str())(input)?;
3888 input = gen_field_table(&method.arguments)(input)?;
3889 Ok(input)
3890 }
3891 }
3892 #[derive(Clone, Debug, Default, PartialEq)]
3894 pub struct UnbindOk {}
3895
3896 impl UnbindOk {
3897 pub fn get_amqp_class_id(&self) -> Identifier {
3899 50
3900 }
3901
3902 pub fn get_amqp_method_id(&self) -> Identifier {
3904 51
3905 }
3906 }
3907
3908 pub fn parse_unbind_ok<I: ParsableInput>(i: I) -> ParserResult<I, UnbindOk> {
3910 Ok((i, UnbindOk {}))
3911 }
3912
3913 pub fn gen_unbind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3915 _: &'a UnbindOk,
3916 ) -> impl SerializeFn<W> + 'a {
3917 move |mut input| {
3918 input = gen_id(51)(input)?;
3919 Ok(input)
3920 }
3921 }
3922}
3923pub mod tx {
3925 use super::*;
3926
3927 pub fn parse_tx<I: ParsableInput>(i: I) -> ParserResult<I, tx::AMQPMethod> {
3929 context(
3930 "parse_tx",
3931 map_opt(
3932 flat_map(parse_id, |id| {
3933 move |i| match id {
3934 10 => context(
3935 "parse_select",
3936 map(map(parse_select, AMQPMethod::Select), Some),
3937 )(i),
3938 11 => context(
3939 "parse_select_ok",
3940 map(map(parse_select_ok, AMQPMethod::SelectOk), Some),
3941 )(i),
3942 20 => context(
3943 "parse_commit",
3944 map(map(parse_commit, AMQPMethod::Commit), Some),
3945 )(i),
3946 21 => context(
3947 "parse_commit_ok",
3948 map(map(parse_commit_ok, AMQPMethod::CommitOk), Some),
3949 )(i),
3950 30 => context(
3951 "parse_rollback",
3952 map(map(parse_rollback, AMQPMethod::Rollback), Some),
3953 )(i),
3954 31 => context(
3955 "parse_rollback_ok",
3956 map(map(parse_rollback_ok, AMQPMethod::RollbackOk), Some),
3957 )(i),
3958 _ => Ok((i, None)),
3959 }
3960 }),
3961 std::convert::identity,
3962 ),
3963 )(i)
3964 }
3965
3966 pub fn gen_tx<'a, W: Write + BackToTheBuffer + 'a>(
3968 method: &'a AMQPMethod,
3969 ) -> impl SerializeFn<W> + 'a {
3970 cookie_factory::sequence::pair(gen_id(90), move |input| match *method {
3971 AMQPMethod::Select(ref select) => gen_select(select)(input),
3972 AMQPMethod::SelectOk(ref select_ok) => gen_select_ok(select_ok)(input),
3973 AMQPMethod::Commit(ref commit) => gen_commit(commit)(input),
3974 AMQPMethod::CommitOk(ref commit_ok) => gen_commit_ok(commit_ok)(input),
3975 AMQPMethod::Rollback(ref rollback) => gen_rollback(rollback)(input),
3976 AMQPMethod::RollbackOk(ref rollback_ok) => gen_rollback_ok(rollback_ok)(input),
3977 })
3978 }
3979
3980 #[derive(Clone, Debug, PartialEq)]
3982 pub enum AMQPMethod {
3983 Select(Select),
3985 SelectOk(SelectOk),
3987 Commit(Commit),
3989 CommitOk(CommitOk),
3991 Rollback(Rollback),
3993 RollbackOk(RollbackOk),
3995 }
3996
3997 #[derive(Clone, Debug, Default, PartialEq)]
3999 pub struct Select {}
4000
4001 impl Select {
4002 pub fn get_amqp_class_id(&self) -> Identifier {
4004 90
4005 }
4006
4007 pub fn get_amqp_method_id(&self) -> Identifier {
4009 10
4010 }
4011 }
4012
4013 pub fn parse_select<I: ParsableInput>(i: I) -> ParserResult<I, Select> {
4015 Ok((i, Select {}))
4016 }
4017
4018 pub fn gen_select<'a, W: Write + BackToTheBuffer + 'a>(
4020 _: &'a Select,
4021 ) -> impl SerializeFn<W> + 'a {
4022 move |mut input| {
4023 input = gen_id(10)(input)?;
4024 Ok(input)
4025 }
4026 }
4027 #[derive(Clone, Debug, Default, PartialEq)]
4029 pub struct SelectOk {}
4030
4031 impl SelectOk {
4032 pub fn get_amqp_class_id(&self) -> Identifier {
4034 90
4035 }
4036
4037 pub fn get_amqp_method_id(&self) -> Identifier {
4039 11
4040 }
4041 }
4042
4043 pub fn parse_select_ok<I: ParsableInput>(i: I) -> ParserResult<I, SelectOk> {
4045 Ok((i, SelectOk {}))
4046 }
4047
4048 pub fn gen_select_ok<'a, W: Write + BackToTheBuffer + 'a>(
4050 _: &'a SelectOk,
4051 ) -> impl SerializeFn<W> + 'a {
4052 move |mut input| {
4053 input = gen_id(11)(input)?;
4054 Ok(input)
4055 }
4056 }
4057 #[derive(Clone, Debug, Default, PartialEq)]
4059 pub struct Commit {}
4060
4061 impl Commit {
4062 pub fn get_amqp_class_id(&self) -> Identifier {
4064 90
4065 }
4066
4067 pub fn get_amqp_method_id(&self) -> Identifier {
4069 20
4070 }
4071 }
4072
4073 pub fn parse_commit<I: ParsableInput>(i: I) -> ParserResult<I, Commit> {
4075 Ok((i, Commit {}))
4076 }
4077
4078 pub fn gen_commit<'a, W: Write + BackToTheBuffer + 'a>(
4080 _: &'a Commit,
4081 ) -> impl SerializeFn<W> + 'a {
4082 move |mut input| {
4083 input = gen_id(20)(input)?;
4084 Ok(input)
4085 }
4086 }
4087 #[derive(Clone, Debug, Default, PartialEq)]
4089 pub struct CommitOk {}
4090
4091 impl CommitOk {
4092 pub fn get_amqp_class_id(&self) -> Identifier {
4094 90
4095 }
4096
4097 pub fn get_amqp_method_id(&self) -> Identifier {
4099 21
4100 }
4101 }
4102
4103 pub fn parse_commit_ok<I: ParsableInput>(i: I) -> ParserResult<I, CommitOk> {
4105 Ok((i, CommitOk {}))
4106 }
4107
4108 pub fn gen_commit_ok<'a, W: Write + BackToTheBuffer + 'a>(
4110 _: &'a CommitOk,
4111 ) -> impl SerializeFn<W> + 'a {
4112 move |mut input| {
4113 input = gen_id(21)(input)?;
4114 Ok(input)
4115 }
4116 }
4117 #[derive(Clone, Debug, Default, PartialEq)]
4119 pub struct Rollback {}
4120
4121 impl Rollback {
4122 pub fn get_amqp_class_id(&self) -> Identifier {
4124 90
4125 }
4126
4127 pub fn get_amqp_method_id(&self) -> Identifier {
4129 30
4130 }
4131 }
4132
4133 pub fn parse_rollback<I: ParsableInput>(i: I) -> ParserResult<I, Rollback> {
4135 Ok((i, Rollback {}))
4136 }
4137
4138 pub fn gen_rollback<'a, W: Write + BackToTheBuffer + 'a>(
4140 _: &'a Rollback,
4141 ) -> impl SerializeFn<W> + 'a {
4142 move |mut input| {
4143 input = gen_id(30)(input)?;
4144 Ok(input)
4145 }
4146 }
4147 #[derive(Clone, Debug, Default, PartialEq)]
4149 pub struct RollbackOk {}
4150
4151 impl RollbackOk {
4152 pub fn get_amqp_class_id(&self) -> Identifier {
4154 90
4155 }
4156
4157 pub fn get_amqp_method_id(&self) -> Identifier {
4159 31
4160 }
4161 }
4162
4163 pub fn parse_rollback_ok<I: ParsableInput>(i: I) -> ParserResult<I, RollbackOk> {
4165 Ok((i, RollbackOk {}))
4166 }
4167
4168 pub fn gen_rollback_ok<'a, W: Write + BackToTheBuffer + 'a>(
4170 _: &'a RollbackOk,
4171 ) -> impl SerializeFn<W> + 'a {
4172 move |mut input| {
4173 input = gen_id(31)(input)?;
4174 Ok(input)
4175 }
4176 }
4177}
4178pub mod confirm {
4180 use super::*;
4181
4182 pub fn parse_confirm<I: ParsableInput>(i: I) -> ParserResult<I, confirm::AMQPMethod> {
4184 context(
4185 "parse_confirm",
4186 map_opt(
4187 flat_map(parse_id, |id| {
4188 move |i| match id {
4189 10 => context(
4190 "parse_select",
4191 map(map(parse_select, AMQPMethod::Select), Some),
4192 )(i),
4193 11 => context(
4194 "parse_select_ok",
4195 map(map(parse_select_ok, AMQPMethod::SelectOk), Some),
4196 )(i),
4197 _ => Ok((i, None)),
4198 }
4199 }),
4200 std::convert::identity,
4201 ),
4202 )(i)
4203 }
4204
4205 pub fn gen_confirm<'a, W: Write + BackToTheBuffer + 'a>(
4207 method: &'a AMQPMethod,
4208 ) -> impl SerializeFn<W> + 'a {
4209 cookie_factory::sequence::pair(gen_id(85), move |input| match *method {
4210 AMQPMethod::Select(ref select) => gen_select(select)(input),
4211 AMQPMethod::SelectOk(ref select_ok) => gen_select_ok(select_ok)(input),
4212 })
4213 }
4214
4215 #[derive(Clone, Debug, PartialEq)]
4217 pub enum AMQPMethod {
4218 Select(Select),
4220 SelectOk(SelectOk),
4222 }
4223
4224 #[derive(Clone, Debug, Default, PartialEq)]
4226 pub struct Select {
4227 pub nowait: Boolean,
4229 }
4230
4231 impl Select {
4232 pub fn get_amqp_class_id(&self) -> Identifier {
4234 85
4235 }
4236
4237 pub fn get_amqp_method_id(&self) -> Identifier {
4239 10
4240 }
4241 }
4242
4243 pub fn parse_select<I: ParsableInput>(i: I) -> ParserResult<I, Select> {
4245 let (i, flags) = parse_flags(i, &["nowait"])?;
4246 Ok((
4247 i,
4248 Select {
4249 nowait: flags.get_flag("nowait").unwrap_or(false),
4250 },
4251 ))
4252 }
4253
4254 pub fn gen_select<'a, W: Write + BackToTheBuffer + 'a>(
4256 method: &'a Select,
4257 ) -> impl SerializeFn<W> + 'a {
4258 move |mut input| {
4259 let mut flags = AMQPFlags::default();
4260 flags.add_flag("nowait".to_string(), method.nowait);
4261 input = gen_id(10)(input)?;
4262 input = gen_flags(&flags)(input)?;
4263 Ok(input)
4264 }
4265 }
4266 #[derive(Clone, Debug, Default, PartialEq)]
4268 pub struct SelectOk {}
4269
4270 impl SelectOk {
4271 pub fn get_amqp_class_id(&self) -> Identifier {
4273 85
4274 }
4275
4276 pub fn get_amqp_method_id(&self) -> Identifier {
4278 11
4279 }
4280 }
4281
4282 pub fn parse_select_ok<I: ParsableInput>(i: I) -> ParserResult<I, SelectOk> {
4284 Ok((i, SelectOk {}))
4285 }
4286
4287 pub fn gen_select_ok<'a, W: Write + BackToTheBuffer + 'a>(
4289 _: &'a SelectOk,
4290 ) -> impl SerializeFn<W> + 'a {
4291 move |mut input| {
4292 input = gen_id(11)(input)?;
4293 Ok(input)
4294 }
4295 }
4296}