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).parse(i),
228 10 => map(map(parse_connection, AMQPClass::Connection), Some).parse(i),
229 20 => map(map(parse_channel, AMQPClass::Channel), Some).parse(i),
230 30 => map(map(parse_access, AMQPClass::Access), Some).parse(i),
231 40 => map(map(parse_exchange, AMQPClass::Exchange), Some).parse(i),
232 50 => map(map(parse_queue, AMQPClass::Queue), Some).parse(i),
233 90 => map(map(parse_tx, AMQPClass::Tx), Some).parse(i),
234 85 => map(map(parse_confirm, AMQPClass::Confirm), Some).parse(i),
235 _ => Ok((i, None)),
236 }
237 }),
238 std::convert::identity,
239 ),
240 )
241 .parse(i)
242}
243
244pub fn gen_class<'a, W: Write + BackToTheBuffer + 'a>(
246 class: &'a AMQPClass,
247) -> impl SerializeFn<W> + 'a {
248 move |input| match *class {
249 AMQPClass::Basic(ref basic) => basic::gen_basic(basic)(input),
250 AMQPClass::Connection(ref connection) => connection::gen_connection(connection)(input),
251 AMQPClass::Channel(ref channel) => channel::gen_channel(channel)(input),
252 AMQPClass::Access(ref access) => access::gen_access(access)(input),
253 AMQPClass::Exchange(ref exchange) => exchange::gen_exchange(exchange)(input),
254 AMQPClass::Queue(ref queue) => queue::gen_queue(queue)(input),
255 AMQPClass::Tx(ref tx) => tx::gen_tx(tx)(input),
256 AMQPClass::Confirm(ref confirm) => confirm::gen_confirm(confirm)(input),
257 }
258}
259
260#[derive(Clone, Debug, PartialEq)]
262pub enum AMQPClass {
263 Basic(basic::AMQPMethod),
265 Connection(connection::AMQPMethod),
267 Channel(channel::AMQPMethod),
269 Access(access::AMQPMethod),
271 Exchange(exchange::AMQPMethod),
273 Queue(queue::AMQPMethod),
275 Tx(tx::AMQPMethod),
277 Confirm(confirm::AMQPMethod),
279}
280
281impl AMQPClass {
282 pub fn get_amqp_class_id(&self) -> Identifier {
284 match self {
285 AMQPClass::Basic(_) => 60,
286 AMQPClass::Connection(_) => 10,
287 AMQPClass::Channel(_) => 20,
288 AMQPClass::Access(_) => 30,
289 AMQPClass::Exchange(_) => 40,
290 AMQPClass::Queue(_) => 50,
291 AMQPClass::Tx(_) => 90,
292 AMQPClass::Confirm(_) => 85,
293 }
294 }
295
296 pub fn get_amqp_method_id(&self) -> Identifier {
298 match self {
299 AMQPClass::Basic(basic::AMQPMethod::Qos(_)) => 10,
300 AMQPClass::Basic(basic::AMQPMethod::QosOk(_)) => 11,
301 AMQPClass::Basic(basic::AMQPMethod::Consume(_)) => 20,
302 AMQPClass::Basic(basic::AMQPMethod::ConsumeOk(_)) => 21,
303 AMQPClass::Basic(basic::AMQPMethod::Cancel(_)) => 30,
304 AMQPClass::Basic(basic::AMQPMethod::CancelOk(_)) => 31,
305 AMQPClass::Basic(basic::AMQPMethod::Publish(_)) => 40,
306 AMQPClass::Basic(basic::AMQPMethod::Return(_)) => 50,
307 AMQPClass::Basic(basic::AMQPMethod::Deliver(_)) => 60,
308 AMQPClass::Basic(basic::AMQPMethod::Get(_)) => 70,
309 AMQPClass::Basic(basic::AMQPMethod::GetOk(_)) => 71,
310 AMQPClass::Basic(basic::AMQPMethod::GetEmpty(_)) => 72,
311 AMQPClass::Basic(basic::AMQPMethod::Ack(_)) => 80,
312 AMQPClass::Basic(basic::AMQPMethod::Reject(_)) => 90,
313 AMQPClass::Basic(basic::AMQPMethod::RecoverAsync(_)) => 100,
314 AMQPClass::Basic(basic::AMQPMethod::Recover(_)) => 110,
315 AMQPClass::Basic(basic::AMQPMethod::RecoverOk(_)) => 111,
316 AMQPClass::Basic(basic::AMQPMethod::Nack(_)) => 120,
317 AMQPClass::Connection(connection::AMQPMethod::Start(_)) => 10,
318 AMQPClass::Connection(connection::AMQPMethod::StartOk(_)) => 11,
319 AMQPClass::Connection(connection::AMQPMethod::Secure(_)) => 20,
320 AMQPClass::Connection(connection::AMQPMethod::SecureOk(_)) => 21,
321 AMQPClass::Connection(connection::AMQPMethod::Tune(_)) => 30,
322 AMQPClass::Connection(connection::AMQPMethod::TuneOk(_)) => 31,
323 AMQPClass::Connection(connection::AMQPMethod::Open(_)) => 40,
324 AMQPClass::Connection(connection::AMQPMethod::OpenOk(_)) => 41,
325 AMQPClass::Connection(connection::AMQPMethod::Close(_)) => 50,
326 AMQPClass::Connection(connection::AMQPMethod::CloseOk(_)) => 51,
327 AMQPClass::Connection(connection::AMQPMethod::Blocked(_)) => 60,
328 AMQPClass::Connection(connection::AMQPMethod::Unblocked(_)) => 61,
329 AMQPClass::Connection(connection::AMQPMethod::UpdateSecret(_)) => 70,
330 AMQPClass::Connection(connection::AMQPMethod::UpdateSecretOk(_)) => 71,
331 AMQPClass::Channel(channel::AMQPMethod::Open(_)) => 10,
332 AMQPClass::Channel(channel::AMQPMethod::OpenOk(_)) => 11,
333 AMQPClass::Channel(channel::AMQPMethod::Flow(_)) => 20,
334 AMQPClass::Channel(channel::AMQPMethod::FlowOk(_)) => 21,
335 AMQPClass::Channel(channel::AMQPMethod::Close(_)) => 40,
336 AMQPClass::Channel(channel::AMQPMethod::CloseOk(_)) => 41,
337 AMQPClass::Access(access::AMQPMethod::Request(_)) => 10,
338 AMQPClass::Access(access::AMQPMethod::RequestOk(_)) => 11,
339 AMQPClass::Exchange(exchange::AMQPMethod::Declare(_)) => 10,
340 AMQPClass::Exchange(exchange::AMQPMethod::DeclareOk(_)) => 11,
341 AMQPClass::Exchange(exchange::AMQPMethod::Delete(_)) => 20,
342 AMQPClass::Exchange(exchange::AMQPMethod::DeleteOk(_)) => 21,
343 AMQPClass::Exchange(exchange::AMQPMethod::Bind(_)) => 30,
344 AMQPClass::Exchange(exchange::AMQPMethod::BindOk(_)) => 31,
345 AMQPClass::Exchange(exchange::AMQPMethod::Unbind(_)) => 40,
346 AMQPClass::Exchange(exchange::AMQPMethod::UnbindOk(_)) => 51,
347 AMQPClass::Queue(queue::AMQPMethod::Declare(_)) => 10,
348 AMQPClass::Queue(queue::AMQPMethod::DeclareOk(_)) => 11,
349 AMQPClass::Queue(queue::AMQPMethod::Bind(_)) => 20,
350 AMQPClass::Queue(queue::AMQPMethod::BindOk(_)) => 21,
351 AMQPClass::Queue(queue::AMQPMethod::Purge(_)) => 30,
352 AMQPClass::Queue(queue::AMQPMethod::PurgeOk(_)) => 31,
353 AMQPClass::Queue(queue::AMQPMethod::Delete(_)) => 40,
354 AMQPClass::Queue(queue::AMQPMethod::DeleteOk(_)) => 41,
355 AMQPClass::Queue(queue::AMQPMethod::Unbind(_)) => 50,
356 AMQPClass::Queue(queue::AMQPMethod::UnbindOk(_)) => 51,
357 AMQPClass::Tx(tx::AMQPMethod::Select(_)) => 10,
358 AMQPClass::Tx(tx::AMQPMethod::SelectOk(_)) => 11,
359 AMQPClass::Tx(tx::AMQPMethod::Commit(_)) => 20,
360 AMQPClass::Tx(tx::AMQPMethod::CommitOk(_)) => 21,
361 AMQPClass::Tx(tx::AMQPMethod::Rollback(_)) => 30,
362 AMQPClass::Tx(tx::AMQPMethod::RollbackOk(_)) => 31,
363 AMQPClass::Confirm(confirm::AMQPMethod::Select(_)) => 10,
364 AMQPClass::Confirm(confirm::AMQPMethod::SelectOk(_)) => 11,
365 }
366 }
367}
368
369pub mod basic {
371 use super::*;
372
373 pub fn parse_basic<I: ParsableInput>(i: I) -> ParserResult<I, basic::AMQPMethod> {
375 context(
376 "parse_basic",
377 map_opt(
378 flat_map(parse_id, |id| {
379 move |i| match id {
380 10 => context("parse_qos", map(map(parse_qos, AMQPMethod::Qos), Some))
381 .parse(i),
382 11 => context(
383 "parse_qos_ok",
384 map(map(parse_qos_ok, AMQPMethod::QosOk), Some),
385 )
386 .parse(i),
387 20 => context(
388 "parse_consume",
389 map(map(parse_consume, AMQPMethod::Consume), Some),
390 )
391 .parse(i),
392 21 => context(
393 "parse_consume_ok",
394 map(map(parse_consume_ok, AMQPMethod::ConsumeOk), Some),
395 )
396 .parse(i),
397 30 => context(
398 "parse_cancel",
399 map(map(parse_cancel, AMQPMethod::Cancel), Some),
400 )
401 .parse(i),
402 31 => context(
403 "parse_cancel_ok",
404 map(map(parse_cancel_ok, AMQPMethod::CancelOk), Some),
405 )
406 .parse(i),
407 40 => context(
408 "parse_publish",
409 map(map(parse_publish, AMQPMethod::Publish), Some),
410 )
411 .parse(i),
412 50 => context(
413 "parse_return",
414 map(map(parse_return, AMQPMethod::Return), Some),
415 )
416 .parse(i),
417 60 => context(
418 "parse_deliver",
419 map(map(parse_deliver, AMQPMethod::Deliver), Some),
420 )
421 .parse(i),
422 70 => context("parse_get", map(map(parse_get, AMQPMethod::Get), Some))
423 .parse(i),
424 71 => context(
425 "parse_get_ok",
426 map(map(parse_get_ok, AMQPMethod::GetOk), Some),
427 )
428 .parse(i),
429 72 => context(
430 "parse_get_empty",
431 map(map(parse_get_empty, AMQPMethod::GetEmpty), Some),
432 )
433 .parse(i),
434 80 => context("parse_ack", map(map(parse_ack, AMQPMethod::Ack), Some))
435 .parse(i),
436 90 => context(
437 "parse_reject",
438 map(map(parse_reject, AMQPMethod::Reject), Some),
439 )
440 .parse(i),
441 100 => context(
442 "parse_recover_async",
443 map(map(parse_recover_async, AMQPMethod::RecoverAsync), Some),
444 )
445 .parse(i),
446 110 => context(
447 "parse_recover",
448 map(map(parse_recover, AMQPMethod::Recover), Some),
449 )
450 .parse(i),
451 111 => context(
452 "parse_recover_ok",
453 map(map(parse_recover_ok, AMQPMethod::RecoverOk), Some),
454 )
455 .parse(i),
456 120 => context("parse_nack", map(map(parse_nack, AMQPMethod::Nack), Some))
457 .parse(i),
458 _ => Ok((i, None)),
459 }
460 }),
461 std::convert::identity,
462 ),
463 )
464 .parse(i)
465 }
466
467 pub fn gen_basic<'a, W: Write + BackToTheBuffer + 'a>(
469 method: &'a AMQPMethod,
470 ) -> impl SerializeFn<W> + 'a {
471 cookie_factory::sequence::pair(gen_id(60), move |input| match *method {
472 AMQPMethod::Qos(ref qos) => gen_qos(qos)(input),
473 AMQPMethod::QosOk(ref qos_ok) => gen_qos_ok(qos_ok)(input),
474 AMQPMethod::Consume(ref consume) => gen_consume(consume)(input),
475 AMQPMethod::ConsumeOk(ref consume_ok) => gen_consume_ok(consume_ok)(input),
476 AMQPMethod::Cancel(ref cancel) => gen_cancel(cancel)(input),
477 AMQPMethod::CancelOk(ref cancel_ok) => gen_cancel_ok(cancel_ok)(input),
478 AMQPMethod::Publish(ref publish) => gen_publish(publish)(input),
479 AMQPMethod::Return(ref r#return) => gen_return(r#return)(input),
480 AMQPMethod::Deliver(ref deliver) => gen_deliver(deliver)(input),
481 AMQPMethod::Get(ref get) => gen_get(get)(input),
482 AMQPMethod::GetOk(ref get_ok) => gen_get_ok(get_ok)(input),
483 AMQPMethod::GetEmpty(ref get_empty) => gen_get_empty(get_empty)(input),
484 AMQPMethod::Ack(ref ack) => gen_ack(ack)(input),
485 AMQPMethod::Reject(ref reject) => gen_reject(reject)(input),
486 AMQPMethod::RecoverAsync(ref recover_async) => gen_recover_async(recover_async)(input),
487 AMQPMethod::Recover(ref recover) => gen_recover(recover)(input),
488 AMQPMethod::RecoverOk(ref recover_ok) => gen_recover_ok(recover_ok)(input),
489 AMQPMethod::Nack(ref nack) => gen_nack(nack)(input),
490 })
491 }
492
493 #[derive(Clone, Debug, PartialEq)]
495 pub enum AMQPMethod {
496 Qos(Qos),
498 QosOk(QosOk),
500 Consume(Consume),
502 ConsumeOk(ConsumeOk),
504 Cancel(Cancel),
506 CancelOk(CancelOk),
508 Publish(Publish),
510 Return(Return),
512 Deliver(Deliver),
514 Get(Get),
516 GetOk(GetOk),
518 GetEmpty(GetEmpty),
520 Ack(Ack),
522 Reject(Reject),
524 RecoverAsync(RecoverAsync),
526 Recover(Recover),
528 RecoverOk(RecoverOk),
530 Nack(Nack),
532 }
533
534 #[derive(Clone, Debug, Default, PartialEq)]
536 pub struct Qos {
537 pub prefetch_count: ShortUInt,
539 pub global: Boolean,
541 }
542
543 impl Qos {
544 pub fn get_amqp_class_id(&self) -> Identifier {
546 60
547 }
548
549 pub fn get_amqp_method_id(&self) -> Identifier {
551 10
552 }
553 }
554
555 pub fn parse_qos<I: ParsableInput>(i: I) -> ParserResult<I, Qos> {
557 let (i, _) = parse_long_uint.parse(i)?;
558 let (i, prefetch_count) = parse_short_uint.parse(i)?;
559 let (i, flags) = parse_flags(i, &["global"])?;
560 Ok((
561 i,
562 Qos {
563 prefetch_count,
564 global: flags.get_flag("global").unwrap_or(false),
565 },
566 ))
567 }
568
569 pub fn gen_qos<'a, W: Write + BackToTheBuffer + 'a>(
571 method: &'a Qos,
572 ) -> impl SerializeFn<W> + 'a {
573 move |mut input| {
574 let mut flags = AMQPFlags::default();
575 flags.add_flag("global".to_string(), method.global);
576 input = gen_id(10)(input)?;
577 input = gen_long_uint(0)(input)?;
578 input = gen_short_uint(method.prefetch_count)(input)?;
579 input = gen_flags(&flags)(input)?;
580 Ok(input)
581 }
582 }
583 #[derive(Clone, Debug, Default, PartialEq)]
585 pub struct QosOk {}
586
587 impl QosOk {
588 pub fn get_amqp_class_id(&self) -> Identifier {
590 60
591 }
592
593 pub fn get_amqp_method_id(&self) -> Identifier {
595 11
596 }
597 }
598
599 pub fn parse_qos_ok<I: ParsableInput>(i: I) -> ParserResult<I, QosOk> {
601 Ok((i, QosOk {}))
602 }
603
604 pub fn gen_qos_ok<'a, W: Write + BackToTheBuffer + 'a>(
606 _: &'a QosOk,
607 ) -> impl SerializeFn<W> + 'a {
608 move |mut input| {
609 input = gen_id(11)(input)?;
610 Ok(input)
611 }
612 }
613 #[derive(Clone, Debug, Default, PartialEq)]
615 pub struct Consume {
616 pub queue: ShortString,
618 pub consumer_tag: ShortString,
620 pub no_local: Boolean,
622 pub no_ack: Boolean,
624 pub exclusive: Boolean,
626 pub nowait: Boolean,
628 pub arguments: FieldTable,
630 }
631
632 impl Consume {
633 pub fn get_amqp_class_id(&self) -> Identifier {
635 60
636 }
637
638 pub fn get_amqp_method_id(&self) -> Identifier {
640 20
641 }
642 }
643
644 pub fn parse_consume<I: ParsableInput>(i: I) -> ParserResult<I, Consume> {
646 let (i, _) = parse_short_uint.parse(i)?;
647 let (i, queue) = parse_short_string.parse(i)?;
648 let (i, consumer_tag) = parse_short_string.parse(i)?;
649 let (i, flags) = parse_flags(i, &["no_local", "no_ack", "exclusive", "nowait"])?;
650 let (i, arguments) = parse_field_table.parse(i)?;
651 Ok((
652 i,
653 Consume {
654 queue,
655 consumer_tag,
656 no_local: flags.get_flag("no_local").unwrap_or(false),
657 no_ack: flags.get_flag("no_ack").unwrap_or(false),
658 exclusive: flags.get_flag("exclusive").unwrap_or(false),
659 nowait: flags.get_flag("nowait").unwrap_or(false),
660 arguments,
661 },
662 ))
663 }
664
665 pub fn gen_consume<'a, W: Write + BackToTheBuffer + 'a>(
667 method: &'a Consume,
668 ) -> impl SerializeFn<W> + 'a {
669 move |mut input| {
670 let mut flags = AMQPFlags::default();
671 flags.add_flag("no_local".to_string(), method.no_local);
672 flags.add_flag("no_ack".to_string(), method.no_ack);
673 flags.add_flag("exclusive".to_string(), method.exclusive);
674 flags.add_flag("nowait".to_string(), method.nowait);
675 input = gen_id(20)(input)?;
676 input = gen_short_uint(0)(input)?;
677 input = gen_short_string(method.queue.as_str())(input)?;
678 input = gen_short_string(method.consumer_tag.as_str())(input)?;
679 input = gen_flags(&flags)(input)?;
680 input = gen_field_table(&method.arguments)(input)?;
681 Ok(input)
682 }
683 }
684 #[derive(Clone, Debug, Default, PartialEq)]
686 pub struct ConsumeOk {
687 pub consumer_tag: ShortString,
689 }
690
691 impl ConsumeOk {
692 pub fn get_amqp_class_id(&self) -> Identifier {
694 60
695 }
696
697 pub fn get_amqp_method_id(&self) -> Identifier {
699 21
700 }
701 }
702
703 pub fn parse_consume_ok<I: ParsableInput>(i: I) -> ParserResult<I, ConsumeOk> {
705 let (i, consumer_tag) = parse_short_string.parse(i)?;
706 Ok((i, ConsumeOk { consumer_tag }))
707 }
708
709 pub fn gen_consume_ok<'a, W: Write + BackToTheBuffer + 'a>(
711 method: &'a ConsumeOk,
712 ) -> impl SerializeFn<W> + 'a {
713 move |mut input| {
714 input = gen_id(21)(input)?;
715 input = gen_short_string(method.consumer_tag.as_str())(input)?;
716 Ok(input)
717 }
718 }
719 #[derive(Clone, Debug, Default, PartialEq)]
721 pub struct Cancel {
722 pub consumer_tag: ShortString,
724 pub nowait: Boolean,
726 }
727
728 impl Cancel {
729 pub fn get_amqp_class_id(&self) -> Identifier {
731 60
732 }
733
734 pub fn get_amqp_method_id(&self) -> Identifier {
736 30
737 }
738 }
739
740 pub fn parse_cancel<I: ParsableInput>(i: I) -> ParserResult<I, Cancel> {
742 let (i, consumer_tag) = parse_short_string.parse(i)?;
743 let (i, flags) = parse_flags(i, &["nowait"])?;
744 Ok((
745 i,
746 Cancel {
747 consumer_tag,
748 nowait: flags.get_flag("nowait").unwrap_or(false),
749 },
750 ))
751 }
752
753 pub fn gen_cancel<'a, W: Write + BackToTheBuffer + 'a>(
755 method: &'a Cancel,
756 ) -> impl SerializeFn<W> + 'a {
757 move |mut input| {
758 let mut flags = AMQPFlags::default();
759 flags.add_flag("nowait".to_string(), method.nowait);
760 input = gen_id(30)(input)?;
761 input = gen_short_string(method.consumer_tag.as_str())(input)?;
762 input = gen_flags(&flags)(input)?;
763 Ok(input)
764 }
765 }
766 #[derive(Clone, Debug, Default, PartialEq)]
768 pub struct CancelOk {
769 pub consumer_tag: ShortString,
771 }
772
773 impl CancelOk {
774 pub fn get_amqp_class_id(&self) -> Identifier {
776 60
777 }
778
779 pub fn get_amqp_method_id(&self) -> Identifier {
781 31
782 }
783 }
784
785 pub fn parse_cancel_ok<I: ParsableInput>(i: I) -> ParserResult<I, CancelOk> {
787 let (i, consumer_tag) = parse_short_string.parse(i)?;
788 Ok((i, CancelOk { consumer_tag }))
789 }
790
791 pub fn gen_cancel_ok<'a, W: Write + BackToTheBuffer + 'a>(
793 method: &'a CancelOk,
794 ) -> impl SerializeFn<W> + 'a {
795 move |mut input| {
796 input = gen_id(31)(input)?;
797 input = gen_short_string(method.consumer_tag.as_str())(input)?;
798 Ok(input)
799 }
800 }
801 #[derive(Clone, Debug, Default, PartialEq)]
803 pub struct Publish {
804 pub exchange: ShortString,
806 pub routing_key: ShortString,
808 pub mandatory: Boolean,
810 pub immediate: Boolean,
812 }
813
814 impl Publish {
815 pub fn get_amqp_class_id(&self) -> Identifier {
817 60
818 }
819
820 pub fn get_amqp_method_id(&self) -> Identifier {
822 40
823 }
824 }
825
826 pub fn parse_publish<I: ParsableInput>(i: I) -> ParserResult<I, Publish> {
828 let (i, _) = parse_short_uint.parse(i)?;
829 let (i, exchange) = parse_short_string.parse(i)?;
830 let (i, routing_key) = parse_short_string.parse(i)?;
831 let (i, flags) = parse_flags(i, &["mandatory", "immediate"])?;
832 Ok((
833 i,
834 Publish {
835 exchange,
836 routing_key,
837 mandatory: flags.get_flag("mandatory").unwrap_or(false),
838 immediate: flags.get_flag("immediate").unwrap_or(false),
839 },
840 ))
841 }
842
843 pub fn gen_publish<'a, W: Write + BackToTheBuffer + 'a>(
845 method: &'a Publish,
846 ) -> impl SerializeFn<W> + 'a {
847 move |mut input| {
848 let mut flags = AMQPFlags::default();
849 flags.add_flag("mandatory".to_string(), method.mandatory);
850 flags.add_flag("immediate".to_string(), method.immediate);
851 input = gen_id(40)(input)?;
852 input = gen_short_uint(0)(input)?;
853 input = gen_short_string(method.exchange.as_str())(input)?;
854 input = gen_short_string(method.routing_key.as_str())(input)?;
855 input = gen_flags(&flags)(input)?;
856 Ok(input)
857 }
858 }
859 #[derive(Clone, Debug, Default, PartialEq)]
861 pub struct Return {
862 pub reply_code: ShortUInt,
864 pub reply_text: ShortString,
866 pub exchange: ShortString,
868 pub routing_key: ShortString,
870 }
871
872 impl Return {
873 pub fn get_amqp_class_id(&self) -> Identifier {
875 60
876 }
877
878 pub fn get_amqp_method_id(&self) -> Identifier {
880 50
881 }
882 }
883
884 pub fn parse_return<I: ParsableInput>(i: I) -> ParserResult<I, Return> {
886 let (i, reply_code) = parse_short_uint.parse(i)?;
887 let (i, reply_text) = parse_short_string.parse(i)?;
888 let (i, exchange) = parse_short_string.parse(i)?;
889 let (i, routing_key) = parse_short_string.parse(i)?;
890 Ok((
891 i,
892 Return {
893 reply_code,
894 reply_text,
895 exchange,
896 routing_key,
897 },
898 ))
899 }
900
901 pub fn gen_return<'a, W: Write + BackToTheBuffer + 'a>(
903 method: &'a Return,
904 ) -> impl SerializeFn<W> + 'a {
905 move |mut input| {
906 input = gen_id(50)(input)?;
907 input = gen_short_uint(method.reply_code)(input)?;
908 input = gen_short_string(method.reply_text.as_str())(input)?;
909 input = gen_short_string(method.exchange.as_str())(input)?;
910 input = gen_short_string(method.routing_key.as_str())(input)?;
911 Ok(input)
912 }
913 }
914 #[derive(Clone, Debug, Default, PartialEq)]
916 pub struct Deliver {
917 pub consumer_tag: ShortString,
919 pub delivery_tag: LongLongUInt,
921 pub redelivered: Boolean,
923 pub exchange: ShortString,
925 pub routing_key: ShortString,
927 }
928
929 impl Deliver {
930 pub fn get_amqp_class_id(&self) -> Identifier {
932 60
933 }
934
935 pub fn get_amqp_method_id(&self) -> Identifier {
937 60
938 }
939 }
940
941 pub fn parse_deliver<I: ParsableInput>(i: I) -> ParserResult<I, Deliver> {
943 let (i, consumer_tag) = parse_short_string.parse(i)?;
944 let (i, delivery_tag) = parse_long_long_uint.parse(i)?;
945 let (i, flags) = parse_flags(i, &["redelivered"])?;
946 let (i, exchange) = parse_short_string.parse(i)?;
947 let (i, routing_key) = parse_short_string.parse(i)?;
948 Ok((
949 i,
950 Deliver {
951 consumer_tag,
952 delivery_tag,
953 redelivered: flags.get_flag("redelivered").unwrap_or(false),
954 exchange,
955 routing_key,
956 },
957 ))
958 }
959
960 pub fn gen_deliver<'a, W: Write + BackToTheBuffer + 'a>(
962 method: &'a Deliver,
963 ) -> impl SerializeFn<W> + 'a {
964 move |mut input| {
965 let mut flags = AMQPFlags::default();
966 flags.add_flag("redelivered".to_string(), method.redelivered);
967 input = gen_id(60)(input)?;
968 input = gen_short_string(method.consumer_tag.as_str())(input)?;
969 input = gen_long_long_uint(method.delivery_tag)(input)?;
970 input = gen_flags(&flags)(input)?;
971 input = gen_short_string(method.exchange.as_str())(input)?;
972 input = gen_short_string(method.routing_key.as_str())(input)?;
973 Ok(input)
974 }
975 }
976 #[derive(Clone, Debug, Default, PartialEq)]
978 pub struct Get {
979 pub queue: ShortString,
981 pub no_ack: Boolean,
983 }
984
985 impl Get {
986 pub fn get_amqp_class_id(&self) -> Identifier {
988 60
989 }
990
991 pub fn get_amqp_method_id(&self) -> Identifier {
993 70
994 }
995 }
996
997 pub fn parse_get<I: ParsableInput>(i: I) -> ParserResult<I, Get> {
999 let (i, _) = parse_short_uint.parse(i)?;
1000 let (i, queue) = parse_short_string.parse(i)?;
1001 let (i, flags) = parse_flags(i, &["no_ack"])?;
1002 Ok((
1003 i,
1004 Get {
1005 queue,
1006 no_ack: flags.get_flag("no_ack").unwrap_or(false),
1007 },
1008 ))
1009 }
1010
1011 pub fn gen_get<'a, W: Write + BackToTheBuffer + 'a>(
1013 method: &'a Get,
1014 ) -> impl SerializeFn<W> + 'a {
1015 move |mut input| {
1016 let mut flags = AMQPFlags::default();
1017 flags.add_flag("no_ack".to_string(), method.no_ack);
1018 input = gen_id(70)(input)?;
1019 input = gen_short_uint(0)(input)?;
1020 input = gen_short_string(method.queue.as_str())(input)?;
1021 input = gen_flags(&flags)(input)?;
1022 Ok(input)
1023 }
1024 }
1025 #[derive(Clone, Debug, Default, PartialEq)]
1027 pub struct GetOk {
1028 pub delivery_tag: LongLongUInt,
1030 pub redelivered: Boolean,
1032 pub exchange: ShortString,
1034 pub routing_key: ShortString,
1036 pub message_count: LongUInt,
1038 }
1039
1040 impl GetOk {
1041 pub fn get_amqp_class_id(&self) -> Identifier {
1043 60
1044 }
1045
1046 pub fn get_amqp_method_id(&self) -> Identifier {
1048 71
1049 }
1050 }
1051
1052 pub fn parse_get_ok<I: ParsableInput>(i: I) -> ParserResult<I, GetOk> {
1054 let (i, delivery_tag) = parse_long_long_uint.parse(i)?;
1055 let (i, flags) = parse_flags(i, &["redelivered"])?;
1056 let (i, exchange) = parse_short_string.parse(i)?;
1057 let (i, routing_key) = parse_short_string.parse(i)?;
1058 let (i, message_count) = parse_long_uint.parse(i)?;
1059 Ok((
1060 i,
1061 GetOk {
1062 delivery_tag,
1063 redelivered: flags.get_flag("redelivered").unwrap_or(false),
1064 exchange,
1065 routing_key,
1066 message_count,
1067 },
1068 ))
1069 }
1070
1071 pub fn gen_get_ok<'a, W: Write + BackToTheBuffer + 'a>(
1073 method: &'a GetOk,
1074 ) -> impl SerializeFn<W> + 'a {
1075 move |mut input| {
1076 let mut flags = AMQPFlags::default();
1077 flags.add_flag("redelivered".to_string(), method.redelivered);
1078 input = gen_id(71)(input)?;
1079 input = gen_long_long_uint(method.delivery_tag)(input)?;
1080 input = gen_flags(&flags)(input)?;
1081 input = gen_short_string(method.exchange.as_str())(input)?;
1082 input = gen_short_string(method.routing_key.as_str())(input)?;
1083 input = gen_long_uint(method.message_count)(input)?;
1084 Ok(input)
1085 }
1086 }
1087 #[derive(Clone, Debug, Default, PartialEq)]
1089 pub struct GetEmpty {}
1090
1091 impl GetEmpty {
1092 pub fn get_amqp_class_id(&self) -> Identifier {
1094 60
1095 }
1096
1097 pub fn get_amqp_method_id(&self) -> Identifier {
1099 72
1100 }
1101 }
1102
1103 pub fn parse_get_empty<I: ParsableInput>(i: I) -> ParserResult<I, GetEmpty> {
1105 let (i, _) = parse_short_string.parse(i)?;
1106 Ok((i, GetEmpty {}))
1107 }
1108
1109 pub fn gen_get_empty<'a, W: Write + BackToTheBuffer + 'a>(
1111 _method: &'a GetEmpty,
1112 ) -> impl SerializeFn<W> + 'a {
1113 move |mut input| {
1114 input = gen_id(72)(input)?;
1115 input = gen_short_string("")(input)?;
1116 Ok(input)
1117 }
1118 }
1119 #[derive(Clone, Debug, Default, PartialEq)]
1121 pub struct Ack {
1122 pub delivery_tag: LongLongUInt,
1124 pub multiple: Boolean,
1126 }
1127
1128 impl Ack {
1129 pub fn get_amqp_class_id(&self) -> Identifier {
1131 60
1132 }
1133
1134 pub fn get_amqp_method_id(&self) -> Identifier {
1136 80
1137 }
1138 }
1139
1140 pub fn parse_ack<I: ParsableInput>(i: I) -> ParserResult<I, Ack> {
1142 let (i, delivery_tag) = parse_long_long_uint.parse(i)?;
1143 let (i, flags) = parse_flags(i, &["multiple"])?;
1144 Ok((
1145 i,
1146 Ack {
1147 delivery_tag,
1148 multiple: flags.get_flag("multiple").unwrap_or(false),
1149 },
1150 ))
1151 }
1152
1153 pub fn gen_ack<'a, W: Write + BackToTheBuffer + 'a>(
1155 method: &'a Ack,
1156 ) -> impl SerializeFn<W> + 'a {
1157 move |mut input| {
1158 let mut flags = AMQPFlags::default();
1159 flags.add_flag("multiple".to_string(), method.multiple);
1160 input = gen_id(80)(input)?;
1161 input = gen_long_long_uint(method.delivery_tag)(input)?;
1162 input = gen_flags(&flags)(input)?;
1163 Ok(input)
1164 }
1165 }
1166 #[derive(Clone, Debug, Default, PartialEq)]
1168 pub struct Reject {
1169 pub delivery_tag: LongLongUInt,
1171 pub requeue: Boolean,
1173 }
1174
1175 impl Reject {
1176 pub fn get_amqp_class_id(&self) -> Identifier {
1178 60
1179 }
1180
1181 pub fn get_amqp_method_id(&self) -> Identifier {
1183 90
1184 }
1185 }
1186
1187 pub fn parse_reject<I: ParsableInput>(i: I) -> ParserResult<I, Reject> {
1189 let (i, delivery_tag) = parse_long_long_uint.parse(i)?;
1190 let (i, flags) = parse_flags(i, &["requeue"])?;
1191 Ok((
1192 i,
1193 Reject {
1194 delivery_tag,
1195 requeue: flags.get_flag("requeue").unwrap_or(false),
1196 },
1197 ))
1198 }
1199
1200 pub fn gen_reject<'a, W: Write + BackToTheBuffer + 'a>(
1202 method: &'a Reject,
1203 ) -> impl SerializeFn<W> + 'a {
1204 move |mut input| {
1205 let mut flags = AMQPFlags::default();
1206 flags.add_flag("requeue".to_string(), method.requeue);
1207 input = gen_id(90)(input)?;
1208 input = gen_long_long_uint(method.delivery_tag)(input)?;
1209 input = gen_flags(&flags)(input)?;
1210 Ok(input)
1211 }
1212 }
1213 #[derive(Clone, Debug, Default, PartialEq)]
1215 pub struct RecoverAsync {
1216 pub requeue: Boolean,
1218 }
1219
1220 impl RecoverAsync {
1221 pub fn get_amqp_class_id(&self) -> Identifier {
1223 60
1224 }
1225
1226 pub fn get_amqp_method_id(&self) -> Identifier {
1228 100
1229 }
1230 }
1231
1232 pub fn parse_recover_async<I: ParsableInput>(i: I) -> ParserResult<I, RecoverAsync> {
1234 let (i, flags) = parse_flags(i, &["requeue"])?;
1235 Ok((
1236 i,
1237 RecoverAsync {
1238 requeue: flags.get_flag("requeue").unwrap_or(false),
1239 },
1240 ))
1241 }
1242
1243 pub fn gen_recover_async<'a, W: Write + BackToTheBuffer + 'a>(
1245 method: &'a RecoverAsync,
1246 ) -> impl SerializeFn<W> + 'a {
1247 move |mut input| {
1248 let mut flags = AMQPFlags::default();
1249 flags.add_flag("requeue".to_string(), method.requeue);
1250 input = gen_id(100)(input)?;
1251 input = gen_flags(&flags)(input)?;
1252 Ok(input)
1253 }
1254 }
1255 #[derive(Clone, Debug, Default, PartialEq)]
1257 pub struct Recover {
1258 pub requeue: Boolean,
1260 }
1261
1262 impl Recover {
1263 pub fn get_amqp_class_id(&self) -> Identifier {
1265 60
1266 }
1267
1268 pub fn get_amqp_method_id(&self) -> Identifier {
1270 110
1271 }
1272 }
1273
1274 pub fn parse_recover<I: ParsableInput>(i: I) -> ParserResult<I, Recover> {
1276 let (i, flags) = parse_flags(i, &["requeue"])?;
1277 Ok((
1278 i,
1279 Recover {
1280 requeue: flags.get_flag("requeue").unwrap_or(false),
1281 },
1282 ))
1283 }
1284
1285 pub fn gen_recover<'a, W: Write + BackToTheBuffer + 'a>(
1287 method: &'a Recover,
1288 ) -> impl SerializeFn<W> + 'a {
1289 move |mut input| {
1290 let mut flags = AMQPFlags::default();
1291 flags.add_flag("requeue".to_string(), method.requeue);
1292 input = gen_id(110)(input)?;
1293 input = gen_flags(&flags)(input)?;
1294 Ok(input)
1295 }
1296 }
1297 #[derive(Clone, Debug, Default, PartialEq)]
1299 pub struct RecoverOk {}
1300
1301 impl RecoverOk {
1302 pub fn get_amqp_class_id(&self) -> Identifier {
1304 60
1305 }
1306
1307 pub fn get_amqp_method_id(&self) -> Identifier {
1309 111
1310 }
1311 }
1312
1313 pub fn parse_recover_ok<I: ParsableInput>(i: I) -> ParserResult<I, RecoverOk> {
1315 Ok((i, RecoverOk {}))
1316 }
1317
1318 pub fn gen_recover_ok<'a, W: Write + BackToTheBuffer + 'a>(
1320 _: &'a RecoverOk,
1321 ) -> impl SerializeFn<W> + 'a {
1322 move |mut input| {
1323 input = gen_id(111)(input)?;
1324 Ok(input)
1325 }
1326 }
1327 #[derive(Clone, Debug, Default, PartialEq)]
1329 pub struct Nack {
1330 pub delivery_tag: LongLongUInt,
1332 pub multiple: Boolean,
1334 pub requeue: Boolean,
1336 }
1337
1338 impl Nack {
1339 pub fn get_amqp_class_id(&self) -> Identifier {
1341 60
1342 }
1343
1344 pub fn get_amqp_method_id(&self) -> Identifier {
1346 120
1347 }
1348 }
1349
1350 pub fn parse_nack<I: ParsableInput>(i: I) -> ParserResult<I, Nack> {
1352 let (i, delivery_tag) = parse_long_long_uint.parse(i)?;
1353 let (i, flags) = parse_flags(i, &["multiple", "requeue"])?;
1354 Ok((
1355 i,
1356 Nack {
1357 delivery_tag,
1358 multiple: flags.get_flag("multiple").unwrap_or(false),
1359 requeue: flags.get_flag("requeue").unwrap_or(false),
1360 },
1361 ))
1362 }
1363
1364 pub fn gen_nack<'a, W: Write + BackToTheBuffer + 'a>(
1366 method: &'a Nack,
1367 ) -> impl SerializeFn<W> + 'a {
1368 move |mut input| {
1369 let mut flags = AMQPFlags::default();
1370 flags.add_flag("multiple".to_string(), method.multiple);
1371 flags.add_flag("requeue".to_string(), method.requeue);
1372 input = gen_id(120)(input)?;
1373 input = gen_long_long_uint(method.delivery_tag)(input)?;
1374 input = gen_flags(&flags)(input)?;
1375 Ok(input)
1376 }
1377 }
1378 #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1380 pub struct AMQPProperties {
1381 content_type: Option<ShortString>,
1382 content_encoding: Option<ShortString>,
1383 headers: Option<FieldTable>,
1384 delivery_mode: Option<ShortShortUInt>,
1385 priority: Option<ShortShortUInt>,
1386 correlation_id: Option<ShortString>,
1387 reply_to: Option<ShortString>,
1388 expiration: Option<ShortString>,
1389 message_id: Option<ShortString>,
1390 timestamp: Option<Timestamp>,
1391 kind: Option<ShortString>,
1392 user_id: Option<ShortString>,
1393 app_id: Option<ShortString>,
1394 cluster_id: Option<ShortString>,
1395 }
1396
1397 impl AMQPProperties {
1398 pub fn with_content_type(mut self, value: ShortString) -> Self {
1400 self.content_type = Some(value);
1401 self
1402 }
1403 pub fn with_content_encoding(mut self, value: ShortString) -> Self {
1405 self.content_encoding = Some(value);
1406 self
1407 }
1408 pub fn with_headers(mut self, value: FieldTable) -> Self {
1410 self.headers = Some(value);
1411 self
1412 }
1413 pub fn with_delivery_mode(mut self, value: ShortShortUInt) -> Self {
1415 self.delivery_mode = Some(value);
1416 self
1417 }
1418 pub fn with_priority(mut self, value: ShortShortUInt) -> Self {
1420 self.priority = Some(value);
1421 self
1422 }
1423 pub fn with_correlation_id(mut self, value: ShortString) -> Self {
1425 self.correlation_id = Some(value);
1426 self
1427 }
1428 pub fn with_reply_to(mut self, value: ShortString) -> Self {
1430 self.reply_to = Some(value);
1431 self
1432 }
1433 pub fn with_expiration(mut self, value: ShortString) -> Self {
1435 self.expiration = Some(value);
1436 self
1437 }
1438 pub fn with_message_id(mut self, value: ShortString) -> Self {
1440 self.message_id = Some(value);
1441 self
1442 }
1443 pub fn with_timestamp(mut self, value: Timestamp) -> Self {
1445 self.timestamp = Some(value);
1446 self
1447 }
1448 pub fn with_type(mut self, value: ShortString) -> Self {
1450 self.kind = Some(value);
1451 self
1452 }
1453 pub fn with_user_id(mut self, value: ShortString) -> Self {
1455 self.user_id = Some(value);
1456 self
1457 }
1458 pub fn with_app_id(mut self, value: ShortString) -> Self {
1460 self.app_id = Some(value);
1461 self
1462 }
1463 pub fn with_cluster_id(mut self, value: ShortString) -> Self {
1465 self.cluster_id = Some(value);
1466 self
1467 }
1468 pub fn content_type(&self) -> &Option<ShortString> {
1470 &self.content_type
1471 }
1472 pub fn content_encoding(&self) -> &Option<ShortString> {
1474 &self.content_encoding
1475 }
1476 pub fn headers(&self) -> &Option<FieldTable> {
1478 &self.headers
1479 }
1480 pub fn delivery_mode(&self) -> &Option<ShortShortUInt> {
1482 &self.delivery_mode
1483 }
1484 pub fn priority(&self) -> &Option<ShortShortUInt> {
1486 &self.priority
1487 }
1488 pub fn correlation_id(&self) -> &Option<ShortString> {
1490 &self.correlation_id
1491 }
1492 pub fn reply_to(&self) -> &Option<ShortString> {
1494 &self.reply_to
1495 }
1496 pub fn expiration(&self) -> &Option<ShortString> {
1498 &self.expiration
1499 }
1500 pub fn message_id(&self) -> &Option<ShortString> {
1502 &self.message_id
1503 }
1504 pub fn timestamp(&self) -> &Option<Timestamp> {
1506 &self.timestamp
1507 }
1508 pub fn kind(&self) -> &Option<ShortString> {
1510 &self.kind
1511 }
1512 pub fn user_id(&self) -> &Option<ShortString> {
1514 &self.user_id
1515 }
1516 pub fn app_id(&self) -> &Option<ShortString> {
1518 &self.app_id
1519 }
1520 pub fn cluster_id(&self) -> &Option<ShortString> {
1522 &self.cluster_id
1523 }
1524 #[allow(clippy::identity_op)]
1526 pub fn bitmask(&self) -> ShortUInt {
1527 (if self.content_type.is_some() {
1528 1 << (15 - 0)
1529 } else {
1530 0
1531 }) + (if self.content_encoding.is_some() {
1532 1 << (15 - 1)
1533 } else {
1534 0
1535 }) + (if self.headers.is_some() {
1536 1 << (15 - 2)
1537 } else {
1538 0
1539 }) + (if self.delivery_mode.is_some() {
1540 1 << (15 - 3)
1541 } else {
1542 0
1543 }) + (if self.priority.is_some() {
1544 1 << (15 - 4)
1545 } else {
1546 0
1547 }) + (if self.correlation_id.is_some() {
1548 1 << (15 - 5)
1549 } else {
1550 0
1551 }) + (if self.reply_to.is_some() {
1552 1 << (15 - 6)
1553 } else {
1554 0
1555 }) + (if self.expiration.is_some() {
1556 1 << (15 - 7)
1557 } else {
1558 0
1559 }) + (if self.message_id.is_some() {
1560 1 << (15 - 8)
1561 } else {
1562 0
1563 }) + (if self.timestamp.is_some() {
1564 1 << (15 - 9)
1565 } else {
1566 0
1567 }) + (if self.kind.is_some() {
1568 1 << (15 - 10)
1569 } else {
1570 0
1571 }) + (if self.user_id.is_some() {
1572 1 << (15 - 11)
1573 } else {
1574 0
1575 }) + (if self.app_id.is_some() {
1576 1 << (15 - 12)
1577 } else {
1578 0
1579 }) + (if self.cluster_id.is_some() {
1580 1 << (15 - 13)
1581 } else {
1582 0
1583 })
1584 }
1585 }
1586
1587 #[allow(clippy::identity_op)]
1589 pub fn parse_properties<I: ParsableInput>(i: I) -> ParserResult<I, AMQPProperties> {
1590 let (i, flags) = parse_short_uint(i)?;
1591 let (i, content_type) = if flags & (1 << (15 - 0)) != 0 {
1592 map(parse_short_string, Some).parse(i)?
1593 } else {
1594 (i, None)
1595 };
1596 let (i, content_encoding) = if flags & (1 << (15 - 1)) != 0 {
1597 map(parse_short_string, Some).parse(i)?
1598 } else {
1599 (i, None)
1600 };
1601 let (i, headers) = if flags & (1 << (15 - 2)) != 0 {
1602 map(parse_field_table, Some).parse(i)?
1603 } else {
1604 (i, None)
1605 };
1606 let (i, delivery_mode) = if flags & (1 << (15 - 3)) != 0 {
1607 map(parse_short_short_uint, Some).parse(i)?
1608 } else {
1609 (i, None)
1610 };
1611 let (i, priority) = if flags & (1 << (15 - 4)) != 0 {
1612 map(parse_short_short_uint, Some).parse(i)?
1613 } else {
1614 (i, None)
1615 };
1616 let (i, correlation_id) = if flags & (1 << (15 - 5)) != 0 {
1617 map(parse_short_string, Some).parse(i)?
1618 } else {
1619 (i, None)
1620 };
1621 let (i, reply_to) = if flags & (1 << (15 - 6)) != 0 {
1622 map(parse_short_string, Some).parse(i)?
1623 } else {
1624 (i, None)
1625 };
1626 let (i, expiration) = if flags & (1 << (15 - 7)) != 0 {
1627 map(parse_short_string, Some).parse(i)?
1628 } else {
1629 (i, None)
1630 };
1631 let (i, message_id) = if flags & (1 << (15 - 8)) != 0 {
1632 map(parse_short_string, Some).parse(i)?
1633 } else {
1634 (i, None)
1635 };
1636 let (i, timestamp) = if flags & (1 << (15 - 9)) != 0 {
1637 map(parse_timestamp, Some).parse(i)?
1638 } else {
1639 (i, None)
1640 };
1641 let (i, kind) = if flags & (1 << (15 - 10)) != 0 {
1642 map(parse_short_string, Some).parse(i)?
1643 } else {
1644 (i, None)
1645 };
1646 let (i, user_id) = if flags & (1 << (15 - 11)) != 0 {
1647 map(parse_short_string, Some).parse(i)?
1648 } else {
1649 (i, None)
1650 };
1651 let (i, app_id) = if flags & (1 << (15 - 12)) != 0 {
1652 map(parse_short_string, Some).parse(i)?
1653 } else {
1654 (i, None)
1655 };
1656 let (i, cluster_id) = if flags & (1 << (15 - 13)) != 0 {
1657 map(parse_short_string, Some).parse(i)?
1658 } else {
1659 (i, None)
1660 };
1661 Ok((
1662 i,
1663 AMQPProperties {
1664 content_type,
1665 content_encoding,
1666 headers,
1667 delivery_mode,
1668 priority,
1669 correlation_id,
1670 reply_to,
1671 expiration,
1672 message_id,
1673 timestamp,
1674 kind,
1675 user_id,
1676 app_id,
1677 cluster_id,
1678 },
1679 ))
1680 }
1681
1682 pub fn gen_properties<'a, W: Write + BackToTheBuffer + 'a>(
1684 props: &'a AMQPProperties,
1685 ) -> impl SerializeFn<W> + 'a {
1686 cookie_factory::sequence::pair(gen_short_uint(props.bitmask()), move |mut input| {
1687 if let Some(prop) = props.content_type.as_ref() {
1688 input = gen_short_string(prop.as_str())(input)?;
1689 }
1690 if let Some(prop) = props.content_encoding.as_ref() {
1691 input = gen_short_string(prop.as_str())(input)?;
1692 }
1693 if let Some(prop) = props.headers.as_ref() {
1694 input = gen_field_table(prop)(input)?;
1695 }
1696 if let Some(prop) = props.delivery_mode {
1697 input = gen_short_short_uint(prop)(input)?;
1698 }
1699 if let Some(prop) = props.priority {
1700 input = gen_short_short_uint(prop)(input)?;
1701 }
1702 if let Some(prop) = props.correlation_id.as_ref() {
1703 input = gen_short_string(prop.as_str())(input)?;
1704 }
1705 if let Some(prop) = props.reply_to.as_ref() {
1706 input = gen_short_string(prop.as_str())(input)?;
1707 }
1708 if let Some(prop) = props.expiration.as_ref() {
1709 input = gen_short_string(prop.as_str())(input)?;
1710 }
1711 if let Some(prop) = props.message_id.as_ref() {
1712 input = gen_short_string(prop.as_str())(input)?;
1713 }
1714 if let Some(prop) = props.timestamp {
1715 input = gen_timestamp(prop)(input)?;
1716 }
1717 if let Some(prop) = props.kind.as_ref() {
1718 input = gen_short_string(prop.as_str())(input)?;
1719 }
1720 if let Some(prop) = props.user_id.as_ref() {
1721 input = gen_short_string(prop.as_str())(input)?;
1722 }
1723 if let Some(prop) = props.app_id.as_ref() {
1724 input = gen_short_string(prop.as_str())(input)?;
1725 }
1726 if let Some(prop) = props.cluster_id.as_ref() {
1727 input = gen_short_string(prop.as_str())(input)?;
1728 }
1729 Ok(input)
1730 })
1731 }
1732}
1733pub mod connection {
1735 use super::*;
1736
1737 pub fn parse_connection<I: ParsableInput>(i: I) -> ParserResult<I, connection::AMQPMethod> {
1739 context(
1740 "parse_connection",
1741 map_opt(
1742 flat_map(parse_id, |id| {
1743 move |i| match id {
1744 10 => context(
1745 "parse_start",
1746 map(map(parse_start, AMQPMethod::Start), Some),
1747 )
1748 .parse(i),
1749 11 => context(
1750 "parse_start_ok",
1751 map(map(parse_start_ok, AMQPMethod::StartOk), Some),
1752 )
1753 .parse(i),
1754 20 => context(
1755 "parse_secure",
1756 map(map(parse_secure, AMQPMethod::Secure), Some),
1757 )
1758 .parse(i),
1759 21 => context(
1760 "parse_secure_ok",
1761 map(map(parse_secure_ok, AMQPMethod::SecureOk), Some),
1762 )
1763 .parse(i),
1764 30 => context("parse_tune", map(map(parse_tune, AMQPMethod::Tune), Some))
1765 .parse(i),
1766 31 => context(
1767 "parse_tune_ok",
1768 map(map(parse_tune_ok, AMQPMethod::TuneOk), Some),
1769 )
1770 .parse(i),
1771 40 => context("parse_open", map(map(parse_open, AMQPMethod::Open), Some))
1772 .parse(i),
1773 41 => context(
1774 "parse_open_ok",
1775 map(map(parse_open_ok, AMQPMethod::OpenOk), Some),
1776 )
1777 .parse(i),
1778 50 => context(
1779 "parse_close",
1780 map(map(parse_close, AMQPMethod::Close), Some),
1781 )
1782 .parse(i),
1783 51 => context(
1784 "parse_close_ok",
1785 map(map(parse_close_ok, AMQPMethod::CloseOk), Some),
1786 )
1787 .parse(i),
1788 60 => context(
1789 "parse_blocked",
1790 map(map(parse_blocked, AMQPMethod::Blocked), Some),
1791 )
1792 .parse(i),
1793 61 => context(
1794 "parse_unblocked",
1795 map(map(parse_unblocked, AMQPMethod::Unblocked), Some),
1796 )
1797 .parse(i),
1798 70 => context(
1799 "parse_update_secret",
1800 map(map(parse_update_secret, AMQPMethod::UpdateSecret), Some),
1801 )
1802 .parse(i),
1803 71 => context(
1804 "parse_update_secret_ok",
1805 map(
1806 map(parse_update_secret_ok, AMQPMethod::UpdateSecretOk),
1807 Some,
1808 ),
1809 )
1810 .parse(i),
1811 _ => Ok((i, None)),
1812 }
1813 }),
1814 std::convert::identity,
1815 ),
1816 )
1817 .parse(i)
1818 }
1819
1820 pub fn gen_connection<'a, W: Write + BackToTheBuffer + 'a>(
1822 method: &'a AMQPMethod,
1823 ) -> impl SerializeFn<W> + 'a {
1824 cookie_factory::sequence::pair(gen_id(10), move |input| match *method {
1825 AMQPMethod::Start(ref start) => gen_start(start)(input),
1826 AMQPMethod::StartOk(ref start_ok) => gen_start_ok(start_ok)(input),
1827 AMQPMethod::Secure(ref secure) => gen_secure(secure)(input),
1828 AMQPMethod::SecureOk(ref secure_ok) => gen_secure_ok(secure_ok)(input),
1829 AMQPMethod::Tune(ref tune) => gen_tune(tune)(input),
1830 AMQPMethod::TuneOk(ref tune_ok) => gen_tune_ok(tune_ok)(input),
1831 AMQPMethod::Open(ref open) => gen_open(open)(input),
1832 AMQPMethod::OpenOk(ref open_ok) => gen_open_ok(open_ok)(input),
1833 AMQPMethod::Close(ref close) => gen_close(close)(input),
1834 AMQPMethod::CloseOk(ref close_ok) => gen_close_ok(close_ok)(input),
1835 AMQPMethod::Blocked(ref blocked) => gen_blocked(blocked)(input),
1836 AMQPMethod::Unblocked(ref unblocked) => gen_unblocked(unblocked)(input),
1837 AMQPMethod::UpdateSecret(ref update_secret) => gen_update_secret(update_secret)(input),
1838 AMQPMethod::UpdateSecretOk(ref update_secret_ok) => {
1839 gen_update_secret_ok(update_secret_ok)(input)
1840 }
1841 })
1842 }
1843
1844 #[derive(Clone, Debug, PartialEq)]
1846 pub enum AMQPMethod {
1847 Start(Start),
1849 StartOk(StartOk),
1851 Secure(Secure),
1853 SecureOk(SecureOk),
1855 Tune(Tune),
1857 TuneOk(TuneOk),
1859 Open(Open),
1861 OpenOk(OpenOk),
1863 Close(Close),
1865 CloseOk(CloseOk),
1867 Blocked(Blocked),
1869 Unblocked(Unblocked),
1871 UpdateSecret(UpdateSecret),
1873 UpdateSecretOk(UpdateSecretOk),
1875 }
1876
1877 #[derive(Clone, Debug, Default, PartialEq)]
1879 pub struct Start {
1880 pub version_major: ShortShortUInt,
1882 pub version_minor: ShortShortUInt,
1884 pub server_properties: FieldTable,
1886 pub mechanisms: LongString,
1888 pub locales: LongString,
1890 }
1891
1892 impl Start {
1893 pub fn get_amqp_class_id(&self) -> Identifier {
1895 10
1896 }
1897
1898 pub fn get_amqp_method_id(&self) -> Identifier {
1900 10
1901 }
1902 }
1903
1904 pub fn parse_start<I: ParsableInput>(i: I) -> ParserResult<I, Start> {
1906 let (i, version_major) = parse_short_short_uint.parse(i)?;
1907 let (i, version_minor) = parse_short_short_uint.parse(i)?;
1908 let (i, server_properties) = parse_field_table.parse(i)?;
1909 let (i, mechanisms) = parse_long_string.parse(i)?;
1910 let (i, locales) = parse_long_string.parse(i)?;
1911 Ok((
1912 i,
1913 Start {
1914 version_major,
1915 version_minor,
1916 server_properties,
1917 mechanisms,
1918 locales,
1919 },
1920 ))
1921 }
1922
1923 pub fn gen_start<'a, W: Write + BackToTheBuffer + 'a>(
1925 method: &'a Start,
1926 ) -> impl SerializeFn<W> + 'a {
1927 move |mut input| {
1928 input = gen_id(10)(input)?;
1929 input = gen_short_short_uint(method.version_major)(input)?;
1930 input = gen_short_short_uint(method.version_minor)(input)?;
1931 input = gen_field_table(&method.server_properties)(input)?;
1932 input = gen_long_string(method.mechanisms.as_bytes())(input)?;
1933 input = gen_long_string(method.locales.as_bytes())(input)?;
1934 Ok(input)
1935 }
1936 }
1937 #[derive(Clone, Debug, Default, PartialEq)]
1939 pub struct StartOk {
1940 pub client_properties: FieldTable,
1942 pub mechanism: ShortString,
1944 pub response: LongString,
1946 pub locale: ShortString,
1948 }
1949
1950 impl StartOk {
1951 pub fn get_amqp_class_id(&self) -> Identifier {
1953 10
1954 }
1955
1956 pub fn get_amqp_method_id(&self) -> Identifier {
1958 11
1959 }
1960 }
1961
1962 pub fn parse_start_ok<I: ParsableInput>(i: I) -> ParserResult<I, StartOk> {
1964 let (i, client_properties) = parse_field_table.parse(i)?;
1965 let (i, mechanism) = parse_short_string.parse(i)?;
1966 let (i, response) = parse_long_string.parse(i)?;
1967 let (i, locale) = parse_short_string.parse(i)?;
1968 Ok((
1969 i,
1970 StartOk {
1971 client_properties,
1972 mechanism,
1973 response,
1974 locale,
1975 },
1976 ))
1977 }
1978
1979 pub fn gen_start_ok<'a, W: Write + BackToTheBuffer + 'a>(
1981 method: &'a StartOk,
1982 ) -> impl SerializeFn<W> + 'a {
1983 move |mut input| {
1984 input = gen_id(11)(input)?;
1985 input = gen_field_table(&method.client_properties)(input)?;
1986 input = gen_short_string(method.mechanism.as_str())(input)?;
1987 input = gen_long_string(method.response.as_bytes())(input)?;
1988 input = gen_short_string(method.locale.as_str())(input)?;
1989 Ok(input)
1990 }
1991 }
1992 #[derive(Clone, Debug, Default, PartialEq)]
1994 pub struct Secure {
1995 pub challenge: LongString,
1997 }
1998
1999 impl Secure {
2000 pub fn get_amqp_class_id(&self) -> Identifier {
2002 10
2003 }
2004
2005 pub fn get_amqp_method_id(&self) -> Identifier {
2007 20
2008 }
2009 }
2010
2011 pub fn parse_secure<I: ParsableInput>(i: I) -> ParserResult<I, Secure> {
2013 let (i, challenge) = parse_long_string.parse(i)?;
2014 Ok((i, Secure { challenge }))
2015 }
2016
2017 pub fn gen_secure<'a, W: Write + BackToTheBuffer + 'a>(
2019 method: &'a Secure,
2020 ) -> impl SerializeFn<W> + 'a {
2021 move |mut input| {
2022 input = gen_id(20)(input)?;
2023 input = gen_long_string(method.challenge.as_bytes())(input)?;
2024 Ok(input)
2025 }
2026 }
2027 #[derive(Clone, Debug, Default, PartialEq)]
2029 pub struct SecureOk {
2030 pub response: LongString,
2032 }
2033
2034 impl SecureOk {
2035 pub fn get_amqp_class_id(&self) -> Identifier {
2037 10
2038 }
2039
2040 pub fn get_amqp_method_id(&self) -> Identifier {
2042 21
2043 }
2044 }
2045
2046 pub fn parse_secure_ok<I: ParsableInput>(i: I) -> ParserResult<I, SecureOk> {
2048 let (i, response) = parse_long_string.parse(i)?;
2049 Ok((i, SecureOk { response }))
2050 }
2051
2052 pub fn gen_secure_ok<'a, W: Write + BackToTheBuffer + 'a>(
2054 method: &'a SecureOk,
2055 ) -> impl SerializeFn<W> + 'a {
2056 move |mut input| {
2057 input = gen_id(21)(input)?;
2058 input = gen_long_string(method.response.as_bytes())(input)?;
2059 Ok(input)
2060 }
2061 }
2062 #[derive(Clone, Debug, Default, PartialEq)]
2064 pub struct Tune {
2065 pub channel_max: ShortUInt,
2067 pub frame_max: LongUInt,
2069 pub heartbeat: ShortUInt,
2071 }
2072
2073 impl Tune {
2074 pub fn get_amqp_class_id(&self) -> Identifier {
2076 10
2077 }
2078
2079 pub fn get_amqp_method_id(&self) -> Identifier {
2081 30
2082 }
2083 }
2084
2085 pub fn parse_tune<I: ParsableInput>(i: I) -> ParserResult<I, Tune> {
2087 let (i, channel_max) = parse_short_uint.parse(i)?;
2088 let (i, frame_max) = parse_long_uint.parse(i)?;
2089 let (i, heartbeat) = parse_short_uint.parse(i)?;
2090 Ok((
2091 i,
2092 Tune {
2093 channel_max,
2094 frame_max,
2095 heartbeat,
2096 },
2097 ))
2098 }
2099
2100 pub fn gen_tune<'a, W: Write + BackToTheBuffer + 'a>(
2102 method: &'a Tune,
2103 ) -> impl SerializeFn<W> + 'a {
2104 move |mut input| {
2105 input = gen_id(30)(input)?;
2106 input = gen_short_uint(method.channel_max)(input)?;
2107 input = gen_long_uint(method.frame_max)(input)?;
2108 input = gen_short_uint(method.heartbeat)(input)?;
2109 Ok(input)
2110 }
2111 }
2112 #[derive(Clone, Debug, Default, PartialEq)]
2114 pub struct TuneOk {
2115 pub channel_max: ShortUInt,
2117 pub frame_max: LongUInt,
2119 pub heartbeat: ShortUInt,
2121 }
2122
2123 impl TuneOk {
2124 pub fn get_amqp_class_id(&self) -> Identifier {
2126 10
2127 }
2128
2129 pub fn get_amqp_method_id(&self) -> Identifier {
2131 31
2132 }
2133 }
2134
2135 pub fn parse_tune_ok<I: ParsableInput>(i: I) -> ParserResult<I, TuneOk> {
2137 let (i, channel_max) = parse_short_uint.parse(i)?;
2138 let (i, frame_max) = parse_long_uint.parse(i)?;
2139 let (i, heartbeat) = parse_short_uint.parse(i)?;
2140 Ok((
2141 i,
2142 TuneOk {
2143 channel_max,
2144 frame_max,
2145 heartbeat,
2146 },
2147 ))
2148 }
2149
2150 pub fn gen_tune_ok<'a, W: Write + BackToTheBuffer + 'a>(
2152 method: &'a TuneOk,
2153 ) -> impl SerializeFn<W> + 'a {
2154 move |mut input| {
2155 input = gen_id(31)(input)?;
2156 input = gen_short_uint(method.channel_max)(input)?;
2157 input = gen_long_uint(method.frame_max)(input)?;
2158 input = gen_short_uint(method.heartbeat)(input)?;
2159 Ok(input)
2160 }
2161 }
2162 #[derive(Clone, Debug, Default, PartialEq)]
2164 pub struct Open {
2165 pub virtual_host: ShortString,
2167 }
2168
2169 impl Open {
2170 pub fn get_amqp_class_id(&self) -> Identifier {
2172 10
2173 }
2174
2175 pub fn get_amqp_method_id(&self) -> Identifier {
2177 40
2178 }
2179 }
2180
2181 pub fn parse_open<I: ParsableInput>(i: I) -> ParserResult<I, Open> {
2183 let (i, virtual_host) = parse_short_string.parse(i)?;
2184 let (i, _) = parse_short_string.parse(i)?;
2185 let (i, _) = parse_flags(i, &["insist"])?;
2186 Ok((i, Open { virtual_host }))
2187 }
2188
2189 pub fn gen_open<'a, W: Write + BackToTheBuffer + 'a>(
2191 method: &'a Open,
2192 ) -> impl SerializeFn<W> + 'a {
2193 move |mut input| {
2194 let mut flags = AMQPFlags::default();
2195 flags.add_flag("insist".to_string(), false);
2196 input = gen_id(40)(input)?;
2197 input = gen_short_string(method.virtual_host.as_str())(input)?;
2198 input = gen_short_string("")(input)?;
2199 input = gen_flags(&flags)(input)?;
2200 Ok(input)
2201 }
2202 }
2203 #[derive(Clone, Debug, Default, PartialEq)]
2205 pub struct OpenOk {}
2206
2207 impl OpenOk {
2208 pub fn get_amqp_class_id(&self) -> Identifier {
2210 10
2211 }
2212
2213 pub fn get_amqp_method_id(&self) -> Identifier {
2215 41
2216 }
2217 }
2218
2219 pub fn parse_open_ok<I: ParsableInput>(i: I) -> ParserResult<I, OpenOk> {
2221 let (i, _) = parse_short_string.parse(i)?;
2222 Ok((i, OpenOk {}))
2223 }
2224
2225 pub fn gen_open_ok<'a, W: Write + BackToTheBuffer + 'a>(
2227 _method: &'a OpenOk,
2228 ) -> impl SerializeFn<W> + 'a {
2229 move |mut input| {
2230 input = gen_id(41)(input)?;
2231 input = gen_short_string("")(input)?;
2232 Ok(input)
2233 }
2234 }
2235 #[derive(Clone, Debug, Default, PartialEq)]
2237 pub struct Close {
2238 pub reply_code: ShortUInt,
2240 pub reply_text: ShortString,
2242 pub class_id: ShortUInt,
2244 pub method_id: ShortUInt,
2246 }
2247
2248 impl Close {
2249 pub fn get_amqp_class_id(&self) -> Identifier {
2251 10
2252 }
2253
2254 pub fn get_amqp_method_id(&self) -> Identifier {
2256 50
2257 }
2258 }
2259
2260 pub fn parse_close<I: ParsableInput>(i: I) -> ParserResult<I, Close> {
2262 let (i, reply_code) = parse_short_uint.parse(i)?;
2263 let (i, reply_text) = parse_short_string.parse(i)?;
2264 let (i, class_id) = parse_short_uint.parse(i)?;
2265 let (i, method_id) = parse_short_uint.parse(i)?;
2266 Ok((
2267 i,
2268 Close {
2269 reply_code,
2270 reply_text,
2271 class_id,
2272 method_id,
2273 },
2274 ))
2275 }
2276
2277 pub fn gen_close<'a, W: Write + BackToTheBuffer + 'a>(
2279 method: &'a Close,
2280 ) -> impl SerializeFn<W> + 'a {
2281 move |mut input| {
2282 input = gen_id(50)(input)?;
2283 input = gen_short_uint(method.reply_code)(input)?;
2284 input = gen_short_string(method.reply_text.as_str())(input)?;
2285 input = gen_short_uint(method.class_id)(input)?;
2286 input = gen_short_uint(method.method_id)(input)?;
2287 Ok(input)
2288 }
2289 }
2290 #[derive(Clone, Debug, Default, PartialEq)]
2292 pub struct CloseOk {}
2293
2294 impl CloseOk {
2295 pub fn get_amqp_class_id(&self) -> Identifier {
2297 10
2298 }
2299
2300 pub fn get_amqp_method_id(&self) -> Identifier {
2302 51
2303 }
2304 }
2305
2306 pub fn parse_close_ok<I: ParsableInput>(i: I) -> ParserResult<I, CloseOk> {
2308 Ok((i, CloseOk {}))
2309 }
2310
2311 pub fn gen_close_ok<'a, W: Write + BackToTheBuffer + 'a>(
2313 _: &'a CloseOk,
2314 ) -> impl SerializeFn<W> + 'a {
2315 move |mut input| {
2316 input = gen_id(51)(input)?;
2317 Ok(input)
2318 }
2319 }
2320 #[derive(Clone, Debug, Default, PartialEq)]
2322 pub struct Blocked {
2323 pub reason: ShortString,
2325 }
2326
2327 impl Blocked {
2328 pub fn get_amqp_class_id(&self) -> Identifier {
2330 10
2331 }
2332
2333 pub fn get_amqp_method_id(&self) -> Identifier {
2335 60
2336 }
2337 }
2338
2339 pub fn parse_blocked<I: ParsableInput>(i: I) -> ParserResult<I, Blocked> {
2341 let (i, reason) = parse_short_string.parse(i)?;
2342 Ok((i, Blocked { reason }))
2343 }
2344
2345 pub fn gen_blocked<'a, W: Write + BackToTheBuffer + 'a>(
2347 method: &'a Blocked,
2348 ) -> impl SerializeFn<W> + 'a {
2349 move |mut input| {
2350 input = gen_id(60)(input)?;
2351 input = gen_short_string(method.reason.as_str())(input)?;
2352 Ok(input)
2353 }
2354 }
2355 #[derive(Clone, Debug, Default, PartialEq)]
2357 pub struct Unblocked {}
2358
2359 impl Unblocked {
2360 pub fn get_amqp_class_id(&self) -> Identifier {
2362 10
2363 }
2364
2365 pub fn get_amqp_method_id(&self) -> Identifier {
2367 61
2368 }
2369 }
2370
2371 pub fn parse_unblocked<I: ParsableInput>(i: I) -> ParserResult<I, Unblocked> {
2373 Ok((i, Unblocked {}))
2374 }
2375
2376 pub fn gen_unblocked<'a, W: Write + BackToTheBuffer + 'a>(
2378 _: &'a Unblocked,
2379 ) -> impl SerializeFn<W> + 'a {
2380 move |mut input| {
2381 input = gen_id(61)(input)?;
2382 Ok(input)
2383 }
2384 }
2385 #[derive(Clone, Debug, Default, PartialEq)]
2387 pub struct UpdateSecret {
2388 pub new_secret: LongString,
2390 pub reason: ShortString,
2392 }
2393
2394 impl UpdateSecret {
2395 pub fn get_amqp_class_id(&self) -> Identifier {
2397 10
2398 }
2399
2400 pub fn get_amqp_method_id(&self) -> Identifier {
2402 70
2403 }
2404 }
2405
2406 pub fn parse_update_secret<I: ParsableInput>(i: I) -> ParserResult<I, UpdateSecret> {
2408 let (i, new_secret) = parse_long_string.parse(i)?;
2409 let (i, reason) = parse_short_string.parse(i)?;
2410 Ok((i, UpdateSecret { new_secret, reason }))
2411 }
2412
2413 pub fn gen_update_secret<'a, W: Write + BackToTheBuffer + 'a>(
2415 method: &'a UpdateSecret,
2416 ) -> impl SerializeFn<W> + 'a {
2417 move |mut input| {
2418 input = gen_id(70)(input)?;
2419 input = gen_long_string(method.new_secret.as_bytes())(input)?;
2420 input = gen_short_string(method.reason.as_str())(input)?;
2421 Ok(input)
2422 }
2423 }
2424 #[derive(Clone, Debug, Default, PartialEq)]
2426 pub struct UpdateSecretOk {}
2427
2428 impl UpdateSecretOk {
2429 pub fn get_amqp_class_id(&self) -> Identifier {
2431 10
2432 }
2433
2434 pub fn get_amqp_method_id(&self) -> Identifier {
2436 71
2437 }
2438 }
2439
2440 pub fn parse_update_secret_ok<I: ParsableInput>(i: I) -> ParserResult<I, UpdateSecretOk> {
2442 Ok((i, UpdateSecretOk {}))
2443 }
2444
2445 pub fn gen_update_secret_ok<'a, W: Write + BackToTheBuffer + 'a>(
2447 _: &'a UpdateSecretOk,
2448 ) -> impl SerializeFn<W> + 'a {
2449 move |mut input| {
2450 input = gen_id(71)(input)?;
2451 Ok(input)
2452 }
2453 }
2454}
2455pub mod channel {
2457 use super::*;
2458
2459 pub fn parse_channel<I: ParsableInput>(i: I) -> ParserResult<I, channel::AMQPMethod> {
2461 context(
2462 "parse_channel",
2463 map_opt(
2464 flat_map(parse_id, |id| {
2465 move |i| match id {
2466 10 => context("parse_open", map(map(parse_open, AMQPMethod::Open), Some))
2467 .parse(i),
2468 11 => context(
2469 "parse_open_ok",
2470 map(map(parse_open_ok, AMQPMethod::OpenOk), Some),
2471 )
2472 .parse(i),
2473 20 => context("parse_flow", map(map(parse_flow, AMQPMethod::Flow), Some))
2474 .parse(i),
2475 21 => context(
2476 "parse_flow_ok",
2477 map(map(parse_flow_ok, AMQPMethod::FlowOk), Some),
2478 )
2479 .parse(i),
2480 40 => context(
2481 "parse_close",
2482 map(map(parse_close, AMQPMethod::Close), Some),
2483 )
2484 .parse(i),
2485 41 => context(
2486 "parse_close_ok",
2487 map(map(parse_close_ok, AMQPMethod::CloseOk), Some),
2488 )
2489 .parse(i),
2490 _ => Ok((i, None)),
2491 }
2492 }),
2493 std::convert::identity,
2494 ),
2495 )
2496 .parse(i)
2497 }
2498
2499 pub fn gen_channel<'a, W: Write + BackToTheBuffer + 'a>(
2501 method: &'a AMQPMethod,
2502 ) -> impl SerializeFn<W> + 'a {
2503 cookie_factory::sequence::pair(gen_id(20), move |input| match *method {
2504 AMQPMethod::Open(ref open) => gen_open(open)(input),
2505 AMQPMethod::OpenOk(ref open_ok) => gen_open_ok(open_ok)(input),
2506 AMQPMethod::Flow(ref flow) => gen_flow(flow)(input),
2507 AMQPMethod::FlowOk(ref flow_ok) => gen_flow_ok(flow_ok)(input),
2508 AMQPMethod::Close(ref close) => gen_close(close)(input),
2509 AMQPMethod::CloseOk(ref close_ok) => gen_close_ok(close_ok)(input),
2510 })
2511 }
2512
2513 #[derive(Clone, Debug, PartialEq)]
2515 pub enum AMQPMethod {
2516 Open(Open),
2518 OpenOk(OpenOk),
2520 Flow(Flow),
2522 FlowOk(FlowOk),
2524 Close(Close),
2526 CloseOk(CloseOk),
2528 }
2529
2530 #[derive(Clone, Debug, Default, PartialEq)]
2532 pub struct Open {}
2533
2534 impl Open {
2535 pub fn get_amqp_class_id(&self) -> Identifier {
2537 20
2538 }
2539
2540 pub fn get_amqp_method_id(&self) -> Identifier {
2542 10
2543 }
2544 }
2545
2546 pub fn parse_open<I: ParsableInput>(i: I) -> ParserResult<I, Open> {
2548 let (i, _) = parse_short_string.parse(i)?;
2549 Ok((i, Open {}))
2550 }
2551
2552 pub fn gen_open<'a, W: Write + BackToTheBuffer + 'a>(
2554 _method: &'a Open,
2555 ) -> impl SerializeFn<W> + 'a {
2556 move |mut input| {
2557 input = gen_id(10)(input)?;
2558 input = gen_short_string("")(input)?;
2559 Ok(input)
2560 }
2561 }
2562 #[derive(Clone, Debug, Default, PartialEq)]
2564 pub struct OpenOk {}
2565
2566 impl OpenOk {
2567 pub fn get_amqp_class_id(&self) -> Identifier {
2569 20
2570 }
2571
2572 pub fn get_amqp_method_id(&self) -> Identifier {
2574 11
2575 }
2576 }
2577
2578 pub fn parse_open_ok<I: ParsableInput>(i: I) -> ParserResult<I, OpenOk> {
2580 let (i, _) = parse_long_string.parse(i)?;
2581 Ok((i, OpenOk {}))
2582 }
2583
2584 pub fn gen_open_ok<'a, W: Write + BackToTheBuffer + 'a>(
2586 _method: &'a OpenOk,
2587 ) -> impl SerializeFn<W> + 'a {
2588 move |mut input| {
2589 input = gen_id(11)(input)?;
2590 input = gen_long_string(b"")(input)?;
2591 Ok(input)
2592 }
2593 }
2594 #[derive(Clone, Debug, Default, PartialEq)]
2596 pub struct Flow {
2597 pub active: Boolean,
2599 }
2600
2601 impl Flow {
2602 pub fn get_amqp_class_id(&self) -> Identifier {
2604 20
2605 }
2606
2607 pub fn get_amqp_method_id(&self) -> Identifier {
2609 20
2610 }
2611 }
2612
2613 pub fn parse_flow<I: ParsableInput>(i: I) -> ParserResult<I, Flow> {
2615 let (i, flags) = parse_flags(i, &["active"])?;
2616 Ok((
2617 i,
2618 Flow {
2619 active: flags.get_flag("active").unwrap_or(false),
2620 },
2621 ))
2622 }
2623
2624 pub fn gen_flow<'a, W: Write + BackToTheBuffer + 'a>(
2626 method: &'a Flow,
2627 ) -> impl SerializeFn<W> + 'a {
2628 move |mut input| {
2629 let mut flags = AMQPFlags::default();
2630 flags.add_flag("active".to_string(), method.active);
2631 input = gen_id(20)(input)?;
2632 input = gen_flags(&flags)(input)?;
2633 Ok(input)
2634 }
2635 }
2636 #[derive(Clone, Debug, Default, PartialEq)]
2638 pub struct FlowOk {
2639 pub active: Boolean,
2641 }
2642
2643 impl FlowOk {
2644 pub fn get_amqp_class_id(&self) -> Identifier {
2646 20
2647 }
2648
2649 pub fn get_amqp_method_id(&self) -> Identifier {
2651 21
2652 }
2653 }
2654
2655 pub fn parse_flow_ok<I: ParsableInput>(i: I) -> ParserResult<I, FlowOk> {
2657 let (i, flags) = parse_flags(i, &["active"])?;
2658 Ok((
2659 i,
2660 FlowOk {
2661 active: flags.get_flag("active").unwrap_or(false),
2662 },
2663 ))
2664 }
2665
2666 pub fn gen_flow_ok<'a, W: Write + BackToTheBuffer + 'a>(
2668 method: &'a FlowOk,
2669 ) -> impl SerializeFn<W> + 'a {
2670 move |mut input| {
2671 let mut flags = AMQPFlags::default();
2672 flags.add_flag("active".to_string(), method.active);
2673 input = gen_id(21)(input)?;
2674 input = gen_flags(&flags)(input)?;
2675 Ok(input)
2676 }
2677 }
2678 #[derive(Clone, Debug, Default, PartialEq)]
2680 pub struct Close {
2681 pub reply_code: ShortUInt,
2683 pub reply_text: ShortString,
2685 pub class_id: ShortUInt,
2687 pub method_id: ShortUInt,
2689 }
2690
2691 impl Close {
2692 pub fn get_amqp_class_id(&self) -> Identifier {
2694 20
2695 }
2696
2697 pub fn get_amqp_method_id(&self) -> Identifier {
2699 40
2700 }
2701 }
2702
2703 pub fn parse_close<I: ParsableInput>(i: I) -> ParserResult<I, Close> {
2705 let (i, reply_code) = parse_short_uint.parse(i)?;
2706 let (i, reply_text) = parse_short_string.parse(i)?;
2707 let (i, class_id) = parse_short_uint.parse(i)?;
2708 let (i, method_id) = parse_short_uint.parse(i)?;
2709 Ok((
2710 i,
2711 Close {
2712 reply_code,
2713 reply_text,
2714 class_id,
2715 method_id,
2716 },
2717 ))
2718 }
2719
2720 pub fn gen_close<'a, W: Write + BackToTheBuffer + 'a>(
2722 method: &'a Close,
2723 ) -> impl SerializeFn<W> + 'a {
2724 move |mut input| {
2725 input = gen_id(40)(input)?;
2726 input = gen_short_uint(method.reply_code)(input)?;
2727 input = gen_short_string(method.reply_text.as_str())(input)?;
2728 input = gen_short_uint(method.class_id)(input)?;
2729 input = gen_short_uint(method.method_id)(input)?;
2730 Ok(input)
2731 }
2732 }
2733 #[derive(Clone, Debug, Default, PartialEq)]
2735 pub struct CloseOk {}
2736
2737 impl CloseOk {
2738 pub fn get_amqp_class_id(&self) -> Identifier {
2740 20
2741 }
2742
2743 pub fn get_amqp_method_id(&self) -> Identifier {
2745 41
2746 }
2747 }
2748
2749 pub fn parse_close_ok<I: ParsableInput>(i: I) -> ParserResult<I, CloseOk> {
2751 Ok((i, CloseOk {}))
2752 }
2753
2754 pub fn gen_close_ok<'a, W: Write + BackToTheBuffer + 'a>(
2756 _: &'a CloseOk,
2757 ) -> impl SerializeFn<W> + 'a {
2758 move |mut input| {
2759 input = gen_id(41)(input)?;
2760 Ok(input)
2761 }
2762 }
2763}
2764pub mod access {
2766 use super::*;
2767
2768 pub fn parse_access<I: ParsableInput>(i: I) -> ParserResult<I, access::AMQPMethod> {
2770 context(
2771 "parse_access",
2772 map_opt(
2773 flat_map(parse_id, |id| {
2774 move |i| match id {
2775 10 => context(
2776 "parse_request",
2777 map(map(parse_request, AMQPMethod::Request), Some),
2778 )
2779 .parse(i),
2780 11 => context(
2781 "parse_request_ok",
2782 map(map(parse_request_ok, AMQPMethod::RequestOk), Some),
2783 )
2784 .parse(i),
2785 _ => Ok((i, None)),
2786 }
2787 }),
2788 std::convert::identity,
2789 ),
2790 )
2791 .parse(i)
2792 }
2793
2794 pub fn gen_access<'a, W: Write + BackToTheBuffer + 'a>(
2796 method: &'a AMQPMethod,
2797 ) -> impl SerializeFn<W> + 'a {
2798 cookie_factory::sequence::pair(gen_id(30), move |input| match *method {
2799 AMQPMethod::Request(ref request) => gen_request(request)(input),
2800 AMQPMethod::RequestOk(ref request_ok) => gen_request_ok(request_ok)(input),
2801 })
2802 }
2803
2804 #[derive(Clone, Debug, PartialEq)]
2806 pub enum AMQPMethod {
2807 Request(Request),
2809 RequestOk(RequestOk),
2811 }
2812
2813 #[derive(Clone, Debug, Default, PartialEq)]
2815 pub struct Request {
2816 pub realm: ShortString,
2818 pub exclusive: Boolean,
2820 pub passive: Boolean,
2822 pub active: Boolean,
2824 pub write: Boolean,
2826 pub read: Boolean,
2828 }
2829
2830 impl Request {
2831 pub fn get_amqp_class_id(&self) -> Identifier {
2833 30
2834 }
2835
2836 pub fn get_amqp_method_id(&self) -> Identifier {
2838 10
2839 }
2840 }
2841
2842 pub fn parse_request<I: ParsableInput>(i: I) -> ParserResult<I, Request> {
2844 let (i, realm) = parse_short_string.parse(i)?;
2845 let (i, flags) = parse_flags(i, &["exclusive", "passive", "active", "write", "read"])?;
2846 Ok((
2847 i,
2848 Request {
2849 realm,
2850 exclusive: flags.get_flag("exclusive").unwrap_or(false),
2851 passive: flags.get_flag("passive").unwrap_or(false),
2852 active: flags.get_flag("active").unwrap_or(false),
2853 write: flags.get_flag("write").unwrap_or(false),
2854 read: flags.get_flag("read").unwrap_or(false),
2855 },
2856 ))
2857 }
2858
2859 pub fn gen_request<'a, W: Write + BackToTheBuffer + 'a>(
2861 method: &'a Request,
2862 ) -> impl SerializeFn<W> + 'a {
2863 move |mut input| {
2864 let mut flags = AMQPFlags::default();
2865 flags.add_flag("exclusive".to_string(), method.exclusive);
2866 flags.add_flag("passive".to_string(), method.passive);
2867 flags.add_flag("active".to_string(), method.active);
2868 flags.add_flag("write".to_string(), method.write);
2869 flags.add_flag("read".to_string(), method.read);
2870 input = gen_id(10)(input)?;
2871 input = gen_short_string(method.realm.as_str())(input)?;
2872 input = gen_flags(&flags)(input)?;
2873 Ok(input)
2874 }
2875 }
2876 #[derive(Clone, Debug, Default, PartialEq)]
2878 pub struct RequestOk {}
2879
2880 impl RequestOk {
2881 pub fn get_amqp_class_id(&self) -> Identifier {
2883 30
2884 }
2885
2886 pub fn get_amqp_method_id(&self) -> Identifier {
2888 11
2889 }
2890 }
2891
2892 pub fn parse_request_ok<I: ParsableInput>(i: I) -> ParserResult<I, RequestOk> {
2894 let (i, _) = parse_short_uint.parse(i)?;
2895 Ok((i, RequestOk {}))
2896 }
2897
2898 pub fn gen_request_ok<'a, W: Write + BackToTheBuffer + 'a>(
2900 _method: &'a RequestOk,
2901 ) -> impl SerializeFn<W> + 'a {
2902 move |mut input| {
2903 input = gen_id(11)(input)?;
2904 input = gen_short_uint(1)(input)?;
2905 Ok(input)
2906 }
2907 }
2908}
2909pub mod exchange {
2911 use super::*;
2912
2913 pub fn parse_exchange<I: ParsableInput>(i: I) -> ParserResult<I, exchange::AMQPMethod> {
2915 context(
2916 "parse_exchange",
2917 map_opt(
2918 flat_map(parse_id, |id| {
2919 move |i| match id {
2920 10 => context(
2921 "parse_declare",
2922 map(map(parse_declare, AMQPMethod::Declare), Some),
2923 )
2924 .parse(i),
2925 11 => context(
2926 "parse_declare_ok",
2927 map(map(parse_declare_ok, AMQPMethod::DeclareOk), Some),
2928 )
2929 .parse(i),
2930 20 => context(
2931 "parse_delete",
2932 map(map(parse_delete, AMQPMethod::Delete), Some),
2933 )
2934 .parse(i),
2935 21 => context(
2936 "parse_delete_ok",
2937 map(map(parse_delete_ok, AMQPMethod::DeleteOk), Some),
2938 )
2939 .parse(i),
2940 30 => context("parse_bind", map(map(parse_bind, AMQPMethod::Bind), Some))
2941 .parse(i),
2942 31 => context(
2943 "parse_bind_ok",
2944 map(map(parse_bind_ok, AMQPMethod::BindOk), Some),
2945 )
2946 .parse(i),
2947 40 => context(
2948 "parse_unbind",
2949 map(map(parse_unbind, AMQPMethod::Unbind), Some),
2950 )
2951 .parse(i),
2952 51 => context(
2953 "parse_unbind_ok",
2954 map(map(parse_unbind_ok, AMQPMethod::UnbindOk), Some),
2955 )
2956 .parse(i),
2957 _ => Ok((i, None)),
2958 }
2959 }),
2960 std::convert::identity,
2961 ),
2962 )
2963 .parse(i)
2964 }
2965
2966 pub fn gen_exchange<'a, W: Write + BackToTheBuffer + 'a>(
2968 method: &'a AMQPMethod,
2969 ) -> impl SerializeFn<W> + 'a {
2970 cookie_factory::sequence::pair(gen_id(40), move |input| match *method {
2971 AMQPMethod::Declare(ref declare) => gen_declare(declare)(input),
2972 AMQPMethod::DeclareOk(ref declare_ok) => gen_declare_ok(declare_ok)(input),
2973 AMQPMethod::Delete(ref delete) => gen_delete(delete)(input),
2974 AMQPMethod::DeleteOk(ref delete_ok) => gen_delete_ok(delete_ok)(input),
2975 AMQPMethod::Bind(ref bind) => gen_bind(bind)(input),
2976 AMQPMethod::BindOk(ref bind_ok) => gen_bind_ok(bind_ok)(input),
2977 AMQPMethod::Unbind(ref unbind) => gen_unbind(unbind)(input),
2978 AMQPMethod::UnbindOk(ref unbind_ok) => gen_unbind_ok(unbind_ok)(input),
2979 })
2980 }
2981
2982 #[derive(Clone, Debug, PartialEq)]
2984 pub enum AMQPMethod {
2985 Declare(Declare),
2987 DeclareOk(DeclareOk),
2989 Delete(Delete),
2991 DeleteOk(DeleteOk),
2993 Bind(Bind),
2995 BindOk(BindOk),
2997 Unbind(Unbind),
2999 UnbindOk(UnbindOk),
3001 }
3002
3003 #[derive(Clone, Debug, Default, PartialEq)]
3005 pub struct Declare {
3006 pub exchange: ShortString,
3008 pub kind: ShortString,
3010 pub passive: Boolean,
3012 pub durable: Boolean,
3014 pub auto_delete: Boolean,
3016 pub internal: Boolean,
3018 pub nowait: Boolean,
3020 pub arguments: FieldTable,
3022 }
3023
3024 impl Declare {
3025 pub fn get_amqp_class_id(&self) -> Identifier {
3027 40
3028 }
3029
3030 pub fn get_amqp_method_id(&self) -> Identifier {
3032 10
3033 }
3034 }
3035
3036 pub fn parse_declare<I: ParsableInput>(i: I) -> ParserResult<I, Declare> {
3038 let (i, _) = parse_short_uint.parse(i)?;
3039 let (i, exchange) = parse_short_string.parse(i)?;
3040 let (i, kind) = parse_short_string.parse(i)?;
3041 let (i, flags) = parse_flags(
3042 i,
3043 &["passive", "durable", "auto_delete", "internal", "nowait"],
3044 )?;
3045 let (i, arguments) = parse_field_table.parse(i)?;
3046 Ok((
3047 i,
3048 Declare {
3049 exchange,
3050 kind,
3051 passive: flags.get_flag("passive").unwrap_or(false),
3052 durable: flags.get_flag("durable").unwrap_or(false),
3053 auto_delete: flags.get_flag("auto_delete").unwrap_or(false),
3054 internal: flags.get_flag("internal").unwrap_or(false),
3055 nowait: flags.get_flag("nowait").unwrap_or(false),
3056 arguments,
3057 },
3058 ))
3059 }
3060
3061 pub fn gen_declare<'a, W: Write + BackToTheBuffer + 'a>(
3063 method: &'a Declare,
3064 ) -> impl SerializeFn<W> + 'a {
3065 move |mut input| {
3066 let mut flags = AMQPFlags::default();
3067 flags.add_flag("passive".to_string(), method.passive);
3068 flags.add_flag("durable".to_string(), method.durable);
3069 flags.add_flag("auto_delete".to_string(), method.auto_delete);
3070 flags.add_flag("internal".to_string(), method.internal);
3071 flags.add_flag("nowait".to_string(), method.nowait);
3072 input = gen_id(10)(input)?;
3073 input = gen_short_uint(0)(input)?;
3074 input = gen_short_string(method.exchange.as_str())(input)?;
3075 input = gen_short_string(method.kind.as_str())(input)?;
3076 input = gen_flags(&flags)(input)?;
3077 input = gen_field_table(&method.arguments)(input)?;
3078 Ok(input)
3079 }
3080 }
3081 #[derive(Clone, Debug, Default, PartialEq)]
3083 pub struct DeclareOk {}
3084
3085 impl DeclareOk {
3086 pub fn get_amqp_class_id(&self) -> Identifier {
3088 40
3089 }
3090
3091 pub fn get_amqp_method_id(&self) -> Identifier {
3093 11
3094 }
3095 }
3096
3097 pub fn parse_declare_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeclareOk> {
3099 Ok((i, DeclareOk {}))
3100 }
3101
3102 pub fn gen_declare_ok<'a, W: Write + BackToTheBuffer + 'a>(
3104 _: &'a DeclareOk,
3105 ) -> impl SerializeFn<W> + 'a {
3106 move |mut input| {
3107 input = gen_id(11)(input)?;
3108 Ok(input)
3109 }
3110 }
3111 #[derive(Clone, Debug, Default, PartialEq)]
3113 pub struct Delete {
3114 pub exchange: ShortString,
3116 pub if_unused: Boolean,
3118 pub nowait: Boolean,
3120 }
3121
3122 impl Delete {
3123 pub fn get_amqp_class_id(&self) -> Identifier {
3125 40
3126 }
3127
3128 pub fn get_amqp_method_id(&self) -> Identifier {
3130 20
3131 }
3132 }
3133
3134 pub fn parse_delete<I: ParsableInput>(i: I) -> ParserResult<I, Delete> {
3136 let (i, _) = parse_short_uint.parse(i)?;
3137 let (i, exchange) = parse_short_string.parse(i)?;
3138 let (i, flags) = parse_flags(i, &["if_unused", "nowait"])?;
3139 Ok((
3140 i,
3141 Delete {
3142 exchange,
3143 if_unused: flags.get_flag("if_unused").unwrap_or(false),
3144 nowait: flags.get_flag("nowait").unwrap_or(false),
3145 },
3146 ))
3147 }
3148
3149 pub fn gen_delete<'a, W: Write + BackToTheBuffer + 'a>(
3151 method: &'a Delete,
3152 ) -> impl SerializeFn<W> + 'a {
3153 move |mut input| {
3154 let mut flags = AMQPFlags::default();
3155 flags.add_flag("if_unused".to_string(), method.if_unused);
3156 flags.add_flag("nowait".to_string(), method.nowait);
3157 input = gen_id(20)(input)?;
3158 input = gen_short_uint(0)(input)?;
3159 input = gen_short_string(method.exchange.as_str())(input)?;
3160 input = gen_flags(&flags)(input)?;
3161 Ok(input)
3162 }
3163 }
3164 #[derive(Clone, Debug, Default, PartialEq)]
3166 pub struct DeleteOk {}
3167
3168 impl DeleteOk {
3169 pub fn get_amqp_class_id(&self) -> Identifier {
3171 40
3172 }
3173
3174 pub fn get_amqp_method_id(&self) -> Identifier {
3176 21
3177 }
3178 }
3179
3180 pub fn parse_delete_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeleteOk> {
3182 Ok((i, DeleteOk {}))
3183 }
3184
3185 pub fn gen_delete_ok<'a, W: Write + BackToTheBuffer + 'a>(
3187 _: &'a DeleteOk,
3188 ) -> impl SerializeFn<W> + 'a {
3189 move |mut input| {
3190 input = gen_id(21)(input)?;
3191 Ok(input)
3192 }
3193 }
3194 #[derive(Clone, Debug, Default, PartialEq)]
3196 pub struct Bind {
3197 pub destination: ShortString,
3199 pub source: ShortString,
3201 pub routing_key: ShortString,
3203 pub nowait: Boolean,
3205 pub arguments: FieldTable,
3207 }
3208
3209 impl Bind {
3210 pub fn get_amqp_class_id(&self) -> Identifier {
3212 40
3213 }
3214
3215 pub fn get_amqp_method_id(&self) -> Identifier {
3217 30
3218 }
3219 }
3220
3221 pub fn parse_bind<I: ParsableInput>(i: I) -> ParserResult<I, Bind> {
3223 let (i, _) = parse_short_uint.parse(i)?;
3224 let (i, destination) = parse_short_string.parse(i)?;
3225 let (i, source) = parse_short_string.parse(i)?;
3226 let (i, routing_key) = parse_short_string.parse(i)?;
3227 let (i, flags) = parse_flags(i, &["nowait"])?;
3228 let (i, arguments) = parse_field_table.parse(i)?;
3229 Ok((
3230 i,
3231 Bind {
3232 destination,
3233 source,
3234 routing_key,
3235 nowait: flags.get_flag("nowait").unwrap_or(false),
3236 arguments,
3237 },
3238 ))
3239 }
3240
3241 pub fn gen_bind<'a, W: Write + BackToTheBuffer + 'a>(
3243 method: &'a Bind,
3244 ) -> impl SerializeFn<W> + 'a {
3245 move |mut input| {
3246 let mut flags = AMQPFlags::default();
3247 flags.add_flag("nowait".to_string(), method.nowait);
3248 input = gen_id(30)(input)?;
3249 input = gen_short_uint(0)(input)?;
3250 input = gen_short_string(method.destination.as_str())(input)?;
3251 input = gen_short_string(method.source.as_str())(input)?;
3252 input = gen_short_string(method.routing_key.as_str())(input)?;
3253 input = gen_flags(&flags)(input)?;
3254 input = gen_field_table(&method.arguments)(input)?;
3255 Ok(input)
3256 }
3257 }
3258 #[derive(Clone, Debug, Default, PartialEq)]
3260 pub struct BindOk {}
3261
3262 impl BindOk {
3263 pub fn get_amqp_class_id(&self) -> Identifier {
3265 40
3266 }
3267
3268 pub fn get_amqp_method_id(&self) -> Identifier {
3270 31
3271 }
3272 }
3273
3274 pub fn parse_bind_ok<I: ParsableInput>(i: I) -> ParserResult<I, BindOk> {
3276 Ok((i, BindOk {}))
3277 }
3278
3279 pub fn gen_bind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3281 _: &'a BindOk,
3282 ) -> impl SerializeFn<W> + 'a {
3283 move |mut input| {
3284 input = gen_id(31)(input)?;
3285 Ok(input)
3286 }
3287 }
3288 #[derive(Clone, Debug, Default, PartialEq)]
3290 pub struct Unbind {
3291 pub destination: ShortString,
3293 pub source: ShortString,
3295 pub routing_key: ShortString,
3297 pub nowait: Boolean,
3299 pub arguments: FieldTable,
3301 }
3302
3303 impl Unbind {
3304 pub fn get_amqp_class_id(&self) -> Identifier {
3306 40
3307 }
3308
3309 pub fn get_amqp_method_id(&self) -> Identifier {
3311 40
3312 }
3313 }
3314
3315 pub fn parse_unbind<I: ParsableInput>(i: I) -> ParserResult<I, Unbind> {
3317 let (i, _) = parse_short_uint.parse(i)?;
3318 let (i, destination) = parse_short_string.parse(i)?;
3319 let (i, source) = parse_short_string.parse(i)?;
3320 let (i, routing_key) = parse_short_string.parse(i)?;
3321 let (i, flags) = parse_flags(i, &["nowait"])?;
3322 let (i, arguments) = parse_field_table.parse(i)?;
3323 Ok((
3324 i,
3325 Unbind {
3326 destination,
3327 source,
3328 routing_key,
3329 nowait: flags.get_flag("nowait").unwrap_or(false),
3330 arguments,
3331 },
3332 ))
3333 }
3334
3335 pub fn gen_unbind<'a, W: Write + BackToTheBuffer + 'a>(
3337 method: &'a Unbind,
3338 ) -> impl SerializeFn<W> + 'a {
3339 move |mut input| {
3340 let mut flags = AMQPFlags::default();
3341 flags.add_flag("nowait".to_string(), method.nowait);
3342 input = gen_id(40)(input)?;
3343 input = gen_short_uint(0)(input)?;
3344 input = gen_short_string(method.destination.as_str())(input)?;
3345 input = gen_short_string(method.source.as_str())(input)?;
3346 input = gen_short_string(method.routing_key.as_str())(input)?;
3347 input = gen_flags(&flags)(input)?;
3348 input = gen_field_table(&method.arguments)(input)?;
3349 Ok(input)
3350 }
3351 }
3352 #[derive(Clone, Debug, Default, PartialEq)]
3354 pub struct UnbindOk {}
3355
3356 impl UnbindOk {
3357 pub fn get_amqp_class_id(&self) -> Identifier {
3359 40
3360 }
3361
3362 pub fn get_amqp_method_id(&self) -> Identifier {
3364 51
3365 }
3366 }
3367
3368 pub fn parse_unbind_ok<I: ParsableInput>(i: I) -> ParserResult<I, UnbindOk> {
3370 Ok((i, UnbindOk {}))
3371 }
3372
3373 pub fn gen_unbind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3375 _: &'a UnbindOk,
3376 ) -> impl SerializeFn<W> + 'a {
3377 move |mut input| {
3378 input = gen_id(51)(input)?;
3379 Ok(input)
3380 }
3381 }
3382}
3383pub mod queue {
3385 use super::*;
3386
3387 pub fn parse_queue<I: ParsableInput>(i: I) -> ParserResult<I, queue::AMQPMethod> {
3389 context(
3390 "parse_queue",
3391 map_opt(
3392 flat_map(parse_id, |id| {
3393 move |i| match id {
3394 10 => context(
3395 "parse_declare",
3396 map(map(parse_declare, AMQPMethod::Declare), Some),
3397 )
3398 .parse(i),
3399 11 => context(
3400 "parse_declare_ok",
3401 map(map(parse_declare_ok, AMQPMethod::DeclareOk), Some),
3402 )
3403 .parse(i),
3404 20 => context("parse_bind", map(map(parse_bind, AMQPMethod::Bind), Some))
3405 .parse(i),
3406 21 => context(
3407 "parse_bind_ok",
3408 map(map(parse_bind_ok, AMQPMethod::BindOk), Some),
3409 )
3410 .parse(i),
3411 30 => context(
3412 "parse_purge",
3413 map(map(parse_purge, AMQPMethod::Purge), Some),
3414 )
3415 .parse(i),
3416 31 => context(
3417 "parse_purge_ok",
3418 map(map(parse_purge_ok, AMQPMethod::PurgeOk), Some),
3419 )
3420 .parse(i),
3421 40 => context(
3422 "parse_delete",
3423 map(map(parse_delete, AMQPMethod::Delete), Some),
3424 )
3425 .parse(i),
3426 41 => context(
3427 "parse_delete_ok",
3428 map(map(parse_delete_ok, AMQPMethod::DeleteOk), Some),
3429 )
3430 .parse(i),
3431 50 => context(
3432 "parse_unbind",
3433 map(map(parse_unbind, AMQPMethod::Unbind), Some),
3434 )
3435 .parse(i),
3436 51 => context(
3437 "parse_unbind_ok",
3438 map(map(parse_unbind_ok, AMQPMethod::UnbindOk), Some),
3439 )
3440 .parse(i),
3441 _ => Ok((i, None)),
3442 }
3443 }),
3444 std::convert::identity,
3445 ),
3446 )
3447 .parse(i)
3448 }
3449
3450 pub fn gen_queue<'a, W: Write + BackToTheBuffer + 'a>(
3452 method: &'a AMQPMethod,
3453 ) -> impl SerializeFn<W> + 'a {
3454 cookie_factory::sequence::pair(gen_id(50), move |input| match *method {
3455 AMQPMethod::Declare(ref declare) => gen_declare(declare)(input),
3456 AMQPMethod::DeclareOk(ref declare_ok) => gen_declare_ok(declare_ok)(input),
3457 AMQPMethod::Bind(ref bind) => gen_bind(bind)(input),
3458 AMQPMethod::BindOk(ref bind_ok) => gen_bind_ok(bind_ok)(input),
3459 AMQPMethod::Purge(ref purge) => gen_purge(purge)(input),
3460 AMQPMethod::PurgeOk(ref purge_ok) => gen_purge_ok(purge_ok)(input),
3461 AMQPMethod::Delete(ref delete) => gen_delete(delete)(input),
3462 AMQPMethod::DeleteOk(ref delete_ok) => gen_delete_ok(delete_ok)(input),
3463 AMQPMethod::Unbind(ref unbind) => gen_unbind(unbind)(input),
3464 AMQPMethod::UnbindOk(ref unbind_ok) => gen_unbind_ok(unbind_ok)(input),
3465 })
3466 }
3467
3468 #[derive(Clone, Debug, PartialEq)]
3470 pub enum AMQPMethod {
3471 Declare(Declare),
3473 DeclareOk(DeclareOk),
3475 Bind(Bind),
3477 BindOk(BindOk),
3479 Purge(Purge),
3481 PurgeOk(PurgeOk),
3483 Delete(Delete),
3485 DeleteOk(DeleteOk),
3487 Unbind(Unbind),
3489 UnbindOk(UnbindOk),
3491 }
3492
3493 #[derive(Clone, Debug, Default, PartialEq)]
3495 pub struct Declare {
3496 pub queue: ShortString,
3498 pub passive: Boolean,
3500 pub durable: Boolean,
3502 pub exclusive: Boolean,
3504 pub auto_delete: Boolean,
3506 pub nowait: Boolean,
3508 pub arguments: FieldTable,
3510 }
3511
3512 impl Declare {
3513 pub fn get_amqp_class_id(&self) -> Identifier {
3515 50
3516 }
3517
3518 pub fn get_amqp_method_id(&self) -> Identifier {
3520 10
3521 }
3522 }
3523
3524 pub fn parse_declare<I: ParsableInput>(i: I) -> ParserResult<I, Declare> {
3526 let (i, _) = parse_short_uint.parse(i)?;
3527 let (i, queue) = parse_short_string.parse(i)?;
3528 let (i, flags) = parse_flags(
3529 i,
3530 &["passive", "durable", "exclusive", "auto_delete", "nowait"],
3531 )?;
3532 let (i, arguments) = parse_field_table.parse(i)?;
3533 Ok((
3534 i,
3535 Declare {
3536 queue,
3537 passive: flags.get_flag("passive").unwrap_or(false),
3538 durable: flags.get_flag("durable").unwrap_or(false),
3539 exclusive: flags.get_flag("exclusive").unwrap_or(false),
3540 auto_delete: flags.get_flag("auto_delete").unwrap_or(false),
3541 nowait: flags.get_flag("nowait").unwrap_or(false),
3542 arguments,
3543 },
3544 ))
3545 }
3546
3547 pub fn gen_declare<'a, W: Write + BackToTheBuffer + 'a>(
3549 method: &'a Declare,
3550 ) -> impl SerializeFn<W> + 'a {
3551 move |mut input| {
3552 let mut flags = AMQPFlags::default();
3553 flags.add_flag("passive".to_string(), method.passive);
3554 flags.add_flag("durable".to_string(), method.durable);
3555 flags.add_flag("exclusive".to_string(), method.exclusive);
3556 flags.add_flag("auto_delete".to_string(), method.auto_delete);
3557 flags.add_flag("nowait".to_string(), method.nowait);
3558 input = gen_id(10)(input)?;
3559 input = gen_short_uint(0)(input)?;
3560 input = gen_short_string(method.queue.as_str())(input)?;
3561 input = gen_flags(&flags)(input)?;
3562 input = gen_field_table(&method.arguments)(input)?;
3563 Ok(input)
3564 }
3565 }
3566 #[derive(Clone, Debug, Default, PartialEq)]
3568 pub struct DeclareOk {
3569 pub queue: ShortString,
3571 pub message_count: LongUInt,
3573 pub consumer_count: LongUInt,
3575 }
3576
3577 impl DeclareOk {
3578 pub fn get_amqp_class_id(&self) -> Identifier {
3580 50
3581 }
3582
3583 pub fn get_amqp_method_id(&self) -> Identifier {
3585 11
3586 }
3587 }
3588
3589 pub fn parse_declare_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeclareOk> {
3591 let (i, queue) = parse_short_string.parse(i)?;
3592 let (i, message_count) = parse_long_uint.parse(i)?;
3593 let (i, consumer_count) = parse_long_uint.parse(i)?;
3594 Ok((
3595 i,
3596 DeclareOk {
3597 queue,
3598 message_count,
3599 consumer_count,
3600 },
3601 ))
3602 }
3603
3604 pub fn gen_declare_ok<'a, W: Write + BackToTheBuffer + 'a>(
3606 method: &'a DeclareOk,
3607 ) -> impl SerializeFn<W> + 'a {
3608 move |mut input| {
3609 input = gen_id(11)(input)?;
3610 input = gen_short_string(method.queue.as_str())(input)?;
3611 input = gen_long_uint(method.message_count)(input)?;
3612 input = gen_long_uint(method.consumer_count)(input)?;
3613 Ok(input)
3614 }
3615 }
3616 #[derive(Clone, Debug, Default, PartialEq)]
3618 pub struct Bind {
3619 pub queue: ShortString,
3621 pub exchange: ShortString,
3623 pub routing_key: ShortString,
3625 pub nowait: Boolean,
3627 pub arguments: FieldTable,
3629 }
3630
3631 impl Bind {
3632 pub fn get_amqp_class_id(&self) -> Identifier {
3634 50
3635 }
3636
3637 pub fn get_amqp_method_id(&self) -> Identifier {
3639 20
3640 }
3641 }
3642
3643 pub fn parse_bind<I: ParsableInput>(i: I) -> ParserResult<I, Bind> {
3645 let (i, _) = parse_short_uint.parse(i)?;
3646 let (i, queue) = parse_short_string.parse(i)?;
3647 let (i, exchange) = parse_short_string.parse(i)?;
3648 let (i, routing_key) = parse_short_string.parse(i)?;
3649 let (i, flags) = parse_flags(i, &["nowait"])?;
3650 let (i, arguments) = parse_field_table.parse(i)?;
3651 Ok((
3652 i,
3653 Bind {
3654 queue,
3655 exchange,
3656 routing_key,
3657 nowait: flags.get_flag("nowait").unwrap_or(false),
3658 arguments,
3659 },
3660 ))
3661 }
3662
3663 pub fn gen_bind<'a, W: Write + BackToTheBuffer + 'a>(
3665 method: &'a Bind,
3666 ) -> impl SerializeFn<W> + 'a {
3667 move |mut input| {
3668 let mut flags = AMQPFlags::default();
3669 flags.add_flag("nowait".to_string(), method.nowait);
3670 input = gen_id(20)(input)?;
3671 input = gen_short_uint(0)(input)?;
3672 input = gen_short_string(method.queue.as_str())(input)?;
3673 input = gen_short_string(method.exchange.as_str())(input)?;
3674 input = gen_short_string(method.routing_key.as_str())(input)?;
3675 input = gen_flags(&flags)(input)?;
3676 input = gen_field_table(&method.arguments)(input)?;
3677 Ok(input)
3678 }
3679 }
3680 #[derive(Clone, Debug, Default, PartialEq)]
3682 pub struct BindOk {}
3683
3684 impl BindOk {
3685 pub fn get_amqp_class_id(&self) -> Identifier {
3687 50
3688 }
3689
3690 pub fn get_amqp_method_id(&self) -> Identifier {
3692 21
3693 }
3694 }
3695
3696 pub fn parse_bind_ok<I: ParsableInput>(i: I) -> ParserResult<I, BindOk> {
3698 Ok((i, BindOk {}))
3699 }
3700
3701 pub fn gen_bind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3703 _: &'a BindOk,
3704 ) -> impl SerializeFn<W> + 'a {
3705 move |mut input| {
3706 input = gen_id(21)(input)?;
3707 Ok(input)
3708 }
3709 }
3710 #[derive(Clone, Debug, Default, PartialEq)]
3712 pub struct Purge {
3713 pub queue: ShortString,
3715 pub nowait: Boolean,
3717 }
3718
3719 impl Purge {
3720 pub fn get_amqp_class_id(&self) -> Identifier {
3722 50
3723 }
3724
3725 pub fn get_amqp_method_id(&self) -> Identifier {
3727 30
3728 }
3729 }
3730
3731 pub fn parse_purge<I: ParsableInput>(i: I) -> ParserResult<I, Purge> {
3733 let (i, _) = parse_short_uint.parse(i)?;
3734 let (i, queue) = parse_short_string.parse(i)?;
3735 let (i, flags) = parse_flags(i, &["nowait"])?;
3736 Ok((
3737 i,
3738 Purge {
3739 queue,
3740 nowait: flags.get_flag("nowait").unwrap_or(false),
3741 },
3742 ))
3743 }
3744
3745 pub fn gen_purge<'a, W: Write + BackToTheBuffer + 'a>(
3747 method: &'a Purge,
3748 ) -> impl SerializeFn<W> + 'a {
3749 move |mut input| {
3750 let mut flags = AMQPFlags::default();
3751 flags.add_flag("nowait".to_string(), method.nowait);
3752 input = gen_id(30)(input)?;
3753 input = gen_short_uint(0)(input)?;
3754 input = gen_short_string(method.queue.as_str())(input)?;
3755 input = gen_flags(&flags)(input)?;
3756 Ok(input)
3757 }
3758 }
3759 #[derive(Clone, Debug, Default, PartialEq)]
3761 pub struct PurgeOk {
3762 pub message_count: LongUInt,
3764 }
3765
3766 impl PurgeOk {
3767 pub fn get_amqp_class_id(&self) -> Identifier {
3769 50
3770 }
3771
3772 pub fn get_amqp_method_id(&self) -> Identifier {
3774 31
3775 }
3776 }
3777
3778 pub fn parse_purge_ok<I: ParsableInput>(i: I) -> ParserResult<I, PurgeOk> {
3780 let (i, message_count) = parse_long_uint.parse(i)?;
3781 Ok((i, PurgeOk { message_count }))
3782 }
3783
3784 pub fn gen_purge_ok<'a, W: Write + BackToTheBuffer + 'a>(
3786 method: &'a PurgeOk,
3787 ) -> impl SerializeFn<W> + 'a {
3788 move |mut input| {
3789 input = gen_id(31)(input)?;
3790 input = gen_long_uint(method.message_count)(input)?;
3791 Ok(input)
3792 }
3793 }
3794 #[derive(Clone, Debug, Default, PartialEq)]
3796 pub struct Delete {
3797 pub queue: ShortString,
3799 pub if_unused: Boolean,
3801 pub if_empty: Boolean,
3803 pub nowait: Boolean,
3805 }
3806
3807 impl Delete {
3808 pub fn get_amqp_class_id(&self) -> Identifier {
3810 50
3811 }
3812
3813 pub fn get_amqp_method_id(&self) -> Identifier {
3815 40
3816 }
3817 }
3818
3819 pub fn parse_delete<I: ParsableInput>(i: I) -> ParserResult<I, Delete> {
3821 let (i, _) = parse_short_uint.parse(i)?;
3822 let (i, queue) = parse_short_string.parse(i)?;
3823 let (i, flags) = parse_flags(i, &["if_unused", "if_empty", "nowait"])?;
3824 Ok((
3825 i,
3826 Delete {
3827 queue,
3828 if_unused: flags.get_flag("if_unused").unwrap_or(false),
3829 if_empty: flags.get_flag("if_empty").unwrap_or(false),
3830 nowait: flags.get_flag("nowait").unwrap_or(false),
3831 },
3832 ))
3833 }
3834
3835 pub fn gen_delete<'a, W: Write + BackToTheBuffer + 'a>(
3837 method: &'a Delete,
3838 ) -> impl SerializeFn<W> + 'a {
3839 move |mut input| {
3840 let mut flags = AMQPFlags::default();
3841 flags.add_flag("if_unused".to_string(), method.if_unused);
3842 flags.add_flag("if_empty".to_string(), method.if_empty);
3843 flags.add_flag("nowait".to_string(), method.nowait);
3844 input = gen_id(40)(input)?;
3845 input = gen_short_uint(0)(input)?;
3846 input = gen_short_string(method.queue.as_str())(input)?;
3847 input = gen_flags(&flags)(input)?;
3848 Ok(input)
3849 }
3850 }
3851 #[derive(Clone, Debug, Default, PartialEq)]
3853 pub struct DeleteOk {
3854 pub message_count: LongUInt,
3856 }
3857
3858 impl DeleteOk {
3859 pub fn get_amqp_class_id(&self) -> Identifier {
3861 50
3862 }
3863
3864 pub fn get_amqp_method_id(&self) -> Identifier {
3866 41
3867 }
3868 }
3869
3870 pub fn parse_delete_ok<I: ParsableInput>(i: I) -> ParserResult<I, DeleteOk> {
3872 let (i, message_count) = parse_long_uint.parse(i)?;
3873 Ok((i, DeleteOk { message_count }))
3874 }
3875
3876 pub fn gen_delete_ok<'a, W: Write + BackToTheBuffer + 'a>(
3878 method: &'a DeleteOk,
3879 ) -> impl SerializeFn<W> + 'a {
3880 move |mut input| {
3881 input = gen_id(41)(input)?;
3882 input = gen_long_uint(method.message_count)(input)?;
3883 Ok(input)
3884 }
3885 }
3886 #[derive(Clone, Debug, Default, PartialEq)]
3888 pub struct Unbind {
3889 pub queue: ShortString,
3891 pub exchange: ShortString,
3893 pub routing_key: ShortString,
3895 pub arguments: FieldTable,
3897 }
3898
3899 impl Unbind {
3900 pub fn get_amqp_class_id(&self) -> Identifier {
3902 50
3903 }
3904
3905 pub fn get_amqp_method_id(&self) -> Identifier {
3907 50
3908 }
3909 }
3910
3911 pub fn parse_unbind<I: ParsableInput>(i: I) -> ParserResult<I, Unbind> {
3913 let (i, _) = parse_short_uint.parse(i)?;
3914 let (i, queue) = parse_short_string.parse(i)?;
3915 let (i, exchange) = parse_short_string.parse(i)?;
3916 let (i, routing_key) = parse_short_string.parse(i)?;
3917 let (i, arguments) = parse_field_table.parse(i)?;
3918 Ok((
3919 i,
3920 Unbind {
3921 queue,
3922 exchange,
3923 routing_key,
3924 arguments,
3925 },
3926 ))
3927 }
3928
3929 pub fn gen_unbind<'a, W: Write + BackToTheBuffer + 'a>(
3931 method: &'a Unbind,
3932 ) -> impl SerializeFn<W> + 'a {
3933 move |mut input| {
3934 input = gen_id(50)(input)?;
3935 input = gen_short_uint(0)(input)?;
3936 input = gen_short_string(method.queue.as_str())(input)?;
3937 input = gen_short_string(method.exchange.as_str())(input)?;
3938 input = gen_short_string(method.routing_key.as_str())(input)?;
3939 input = gen_field_table(&method.arguments)(input)?;
3940 Ok(input)
3941 }
3942 }
3943 #[derive(Clone, Debug, Default, PartialEq)]
3945 pub struct UnbindOk {}
3946
3947 impl UnbindOk {
3948 pub fn get_amqp_class_id(&self) -> Identifier {
3950 50
3951 }
3952
3953 pub fn get_amqp_method_id(&self) -> Identifier {
3955 51
3956 }
3957 }
3958
3959 pub fn parse_unbind_ok<I: ParsableInput>(i: I) -> ParserResult<I, UnbindOk> {
3961 Ok((i, UnbindOk {}))
3962 }
3963
3964 pub fn gen_unbind_ok<'a, W: Write + BackToTheBuffer + 'a>(
3966 _: &'a UnbindOk,
3967 ) -> impl SerializeFn<W> + 'a {
3968 move |mut input| {
3969 input = gen_id(51)(input)?;
3970 Ok(input)
3971 }
3972 }
3973}
3974pub mod tx {
3976 use super::*;
3977
3978 pub fn parse_tx<I: ParsableInput>(i: I) -> ParserResult<I, tx::AMQPMethod> {
3980 context(
3981 "parse_tx",
3982 map_opt(
3983 flat_map(parse_id, |id| {
3984 move |i| match id {
3985 10 => context(
3986 "parse_select",
3987 map(map(parse_select, AMQPMethod::Select), Some),
3988 )
3989 .parse(i),
3990 11 => context(
3991 "parse_select_ok",
3992 map(map(parse_select_ok, AMQPMethod::SelectOk), Some),
3993 )
3994 .parse(i),
3995 20 => context(
3996 "parse_commit",
3997 map(map(parse_commit, AMQPMethod::Commit), Some),
3998 )
3999 .parse(i),
4000 21 => context(
4001 "parse_commit_ok",
4002 map(map(parse_commit_ok, AMQPMethod::CommitOk), Some),
4003 )
4004 .parse(i),
4005 30 => context(
4006 "parse_rollback",
4007 map(map(parse_rollback, AMQPMethod::Rollback), Some),
4008 )
4009 .parse(i),
4010 31 => context(
4011 "parse_rollback_ok",
4012 map(map(parse_rollback_ok, AMQPMethod::RollbackOk), Some),
4013 )
4014 .parse(i),
4015 _ => Ok((i, None)),
4016 }
4017 }),
4018 std::convert::identity,
4019 ),
4020 )
4021 .parse(i)
4022 }
4023
4024 pub fn gen_tx<'a, W: Write + BackToTheBuffer + 'a>(
4026 method: &'a AMQPMethod,
4027 ) -> impl SerializeFn<W> + 'a {
4028 cookie_factory::sequence::pair(gen_id(90), move |input| match *method {
4029 AMQPMethod::Select(ref select) => gen_select(select)(input),
4030 AMQPMethod::SelectOk(ref select_ok) => gen_select_ok(select_ok)(input),
4031 AMQPMethod::Commit(ref commit) => gen_commit(commit)(input),
4032 AMQPMethod::CommitOk(ref commit_ok) => gen_commit_ok(commit_ok)(input),
4033 AMQPMethod::Rollback(ref rollback) => gen_rollback(rollback)(input),
4034 AMQPMethod::RollbackOk(ref rollback_ok) => gen_rollback_ok(rollback_ok)(input),
4035 })
4036 }
4037
4038 #[derive(Clone, Debug, PartialEq)]
4040 pub enum AMQPMethod {
4041 Select(Select),
4043 SelectOk(SelectOk),
4045 Commit(Commit),
4047 CommitOk(CommitOk),
4049 Rollback(Rollback),
4051 RollbackOk(RollbackOk),
4053 }
4054
4055 #[derive(Clone, Debug, Default, PartialEq)]
4057 pub struct Select {}
4058
4059 impl Select {
4060 pub fn get_amqp_class_id(&self) -> Identifier {
4062 90
4063 }
4064
4065 pub fn get_amqp_method_id(&self) -> Identifier {
4067 10
4068 }
4069 }
4070
4071 pub fn parse_select<I: ParsableInput>(i: I) -> ParserResult<I, Select> {
4073 Ok((i, Select {}))
4074 }
4075
4076 pub fn gen_select<'a, W: Write + BackToTheBuffer + 'a>(
4078 _: &'a Select,
4079 ) -> impl SerializeFn<W> + 'a {
4080 move |mut input| {
4081 input = gen_id(10)(input)?;
4082 Ok(input)
4083 }
4084 }
4085 #[derive(Clone, Debug, Default, PartialEq)]
4087 pub struct SelectOk {}
4088
4089 impl SelectOk {
4090 pub fn get_amqp_class_id(&self) -> Identifier {
4092 90
4093 }
4094
4095 pub fn get_amqp_method_id(&self) -> Identifier {
4097 11
4098 }
4099 }
4100
4101 pub fn parse_select_ok<I: ParsableInput>(i: I) -> ParserResult<I, SelectOk> {
4103 Ok((i, SelectOk {}))
4104 }
4105
4106 pub fn gen_select_ok<'a, W: Write + BackToTheBuffer + 'a>(
4108 _: &'a SelectOk,
4109 ) -> impl SerializeFn<W> + 'a {
4110 move |mut input| {
4111 input = gen_id(11)(input)?;
4112 Ok(input)
4113 }
4114 }
4115 #[derive(Clone, Debug, Default, PartialEq)]
4117 pub struct Commit {}
4118
4119 impl Commit {
4120 pub fn get_amqp_class_id(&self) -> Identifier {
4122 90
4123 }
4124
4125 pub fn get_amqp_method_id(&self) -> Identifier {
4127 20
4128 }
4129 }
4130
4131 pub fn parse_commit<I: ParsableInput>(i: I) -> ParserResult<I, Commit> {
4133 Ok((i, Commit {}))
4134 }
4135
4136 pub fn gen_commit<'a, W: Write + BackToTheBuffer + 'a>(
4138 _: &'a Commit,
4139 ) -> impl SerializeFn<W> + 'a {
4140 move |mut input| {
4141 input = gen_id(20)(input)?;
4142 Ok(input)
4143 }
4144 }
4145 #[derive(Clone, Debug, Default, PartialEq)]
4147 pub struct CommitOk {}
4148
4149 impl CommitOk {
4150 pub fn get_amqp_class_id(&self) -> Identifier {
4152 90
4153 }
4154
4155 pub fn get_amqp_method_id(&self) -> Identifier {
4157 21
4158 }
4159 }
4160
4161 pub fn parse_commit_ok<I: ParsableInput>(i: I) -> ParserResult<I, CommitOk> {
4163 Ok((i, CommitOk {}))
4164 }
4165
4166 pub fn gen_commit_ok<'a, W: Write + BackToTheBuffer + 'a>(
4168 _: &'a CommitOk,
4169 ) -> impl SerializeFn<W> + 'a {
4170 move |mut input| {
4171 input = gen_id(21)(input)?;
4172 Ok(input)
4173 }
4174 }
4175 #[derive(Clone, Debug, Default, PartialEq)]
4177 pub struct Rollback {}
4178
4179 impl Rollback {
4180 pub fn get_amqp_class_id(&self) -> Identifier {
4182 90
4183 }
4184
4185 pub fn get_amqp_method_id(&self) -> Identifier {
4187 30
4188 }
4189 }
4190
4191 pub fn parse_rollback<I: ParsableInput>(i: I) -> ParserResult<I, Rollback> {
4193 Ok((i, Rollback {}))
4194 }
4195
4196 pub fn gen_rollback<'a, W: Write + BackToTheBuffer + 'a>(
4198 _: &'a Rollback,
4199 ) -> impl SerializeFn<W> + 'a {
4200 move |mut input| {
4201 input = gen_id(30)(input)?;
4202 Ok(input)
4203 }
4204 }
4205 #[derive(Clone, Debug, Default, PartialEq)]
4207 pub struct RollbackOk {}
4208
4209 impl RollbackOk {
4210 pub fn get_amqp_class_id(&self) -> Identifier {
4212 90
4213 }
4214
4215 pub fn get_amqp_method_id(&self) -> Identifier {
4217 31
4218 }
4219 }
4220
4221 pub fn parse_rollback_ok<I: ParsableInput>(i: I) -> ParserResult<I, RollbackOk> {
4223 Ok((i, RollbackOk {}))
4224 }
4225
4226 pub fn gen_rollback_ok<'a, W: Write + BackToTheBuffer + 'a>(
4228 _: &'a RollbackOk,
4229 ) -> impl SerializeFn<W> + 'a {
4230 move |mut input| {
4231 input = gen_id(31)(input)?;
4232 Ok(input)
4233 }
4234 }
4235}
4236pub mod confirm {
4238 use super::*;
4239
4240 pub fn parse_confirm<I: ParsableInput>(i: I) -> ParserResult<I, confirm::AMQPMethod> {
4242 context(
4243 "parse_confirm",
4244 map_opt(
4245 flat_map(parse_id, |id| {
4246 move |i| match id {
4247 10 => context(
4248 "parse_select",
4249 map(map(parse_select, AMQPMethod::Select), Some),
4250 )
4251 .parse(i),
4252 11 => context(
4253 "parse_select_ok",
4254 map(map(parse_select_ok, AMQPMethod::SelectOk), Some),
4255 )
4256 .parse(i),
4257 _ => Ok((i, None)),
4258 }
4259 }),
4260 std::convert::identity,
4261 ),
4262 )
4263 .parse(i)
4264 }
4265
4266 pub fn gen_confirm<'a, W: Write + BackToTheBuffer + 'a>(
4268 method: &'a AMQPMethod,
4269 ) -> impl SerializeFn<W> + 'a {
4270 cookie_factory::sequence::pair(gen_id(85), move |input| match *method {
4271 AMQPMethod::Select(ref select) => gen_select(select)(input),
4272 AMQPMethod::SelectOk(ref select_ok) => gen_select_ok(select_ok)(input),
4273 })
4274 }
4275
4276 #[derive(Clone, Debug, PartialEq)]
4278 pub enum AMQPMethod {
4279 Select(Select),
4281 SelectOk(SelectOk),
4283 }
4284
4285 #[derive(Clone, Debug, Default, PartialEq)]
4287 pub struct Select {
4288 pub nowait: Boolean,
4290 }
4291
4292 impl Select {
4293 pub fn get_amqp_class_id(&self) -> Identifier {
4295 85
4296 }
4297
4298 pub fn get_amqp_method_id(&self) -> Identifier {
4300 10
4301 }
4302 }
4303
4304 pub fn parse_select<I: ParsableInput>(i: I) -> ParserResult<I, Select> {
4306 let (i, flags) = parse_flags(i, &["nowait"])?;
4307 Ok((
4308 i,
4309 Select {
4310 nowait: flags.get_flag("nowait").unwrap_or(false),
4311 },
4312 ))
4313 }
4314
4315 pub fn gen_select<'a, W: Write + BackToTheBuffer + 'a>(
4317 method: &'a Select,
4318 ) -> impl SerializeFn<W> + 'a {
4319 move |mut input| {
4320 let mut flags = AMQPFlags::default();
4321 flags.add_flag("nowait".to_string(), method.nowait);
4322 input = gen_id(10)(input)?;
4323 input = gen_flags(&flags)(input)?;
4324 Ok(input)
4325 }
4326 }
4327 #[derive(Clone, Debug, Default, PartialEq)]
4329 pub struct SelectOk {}
4330
4331 impl SelectOk {
4332 pub fn get_amqp_class_id(&self) -> Identifier {
4334 85
4335 }
4336
4337 pub fn get_amqp_method_id(&self) -> Identifier {
4339 11
4340 }
4341 }
4342
4343 pub fn parse_select_ok<I: ParsableInput>(i: I) -> ParserResult<I, SelectOk> {
4345 Ok((i, SelectOk {}))
4346 }
4347
4348 pub fn gen_select_ok<'a, W: Write + BackToTheBuffer + 'a>(
4350 _: &'a SelectOk,
4351 ) -> impl SerializeFn<W> + 'a {
4352 move |mut input| {
4353 input = gen_id(11)(input)?;
4354 Ok(input)
4355 }
4356 }
4357}