From 044ea98e70438003ac4b63a6e66453d1decb8840 Mon Sep 17 00:00:00 2001 From: Michael Zhalevich Date: Tue, 17 Sep 2024 15:36:55 +0200 Subject: [PATCH] parsing: fixed parsing frames with attributes contained dashes --- protocol/src/frame/parsing.rs | 21 +++++++++++++++++++++ protocol/src/generated.rs | 12 ++++++------ protocol/templates/protocol.rs | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/protocol/src/frame/parsing.rs b/protocol/src/frame/parsing.rs index 6d917dd..ef6dfb2 100644 --- a/protocol/src/frame/parsing.rs +++ b/protocol/src/frame/parsing.rs @@ -162,4 +162,25 @@ mod test { Ok((&[][..], AMQPFrame::Heartbeat(1))) ); } + + #[test] + fn test_parse_declare_queue_frame() { + let frame = AMQPFrame::Method( + 1, + AMQPClass::Queue(queue::AMQPMethod::Declare(queue::Declare { + queue: "some_queue".into(), + passive: true, + durable: true, + exclusive: true, + auto_delete: true, + nowait: true, + arguments: Default::default(), + })), + ); + + let mut buffer = vec![0u8; 30]; + + assert!(gen_frame(&frame)(buffer.as_mut_slice().into()).is_ok()); + assert_eq!(parse_frame(buffer.as_slice()), Ok((&[][..], frame))); + } } diff --git a/protocol/src/generated.rs b/protocol/src/generated.rs index 00e4743..3b72154 100644 --- a/protocol/src/generated.rs +++ b/protocol/src/generated.rs @@ -646,7 +646,7 @@ pub mod basic { let (i, _) = parse_short_uint.parse(i)?; let (i, queue) = parse_short_string.parse(i)?; let (i, consumer_tag) = parse_short_string.parse(i)?; - let (i, flags) = parse_flags(i, &["no-local", "no-ack", "exclusive", "nowait"])?; + let (i, flags) = parse_flags(i, &["no_local", "no_ack", "exclusive", "nowait"])?; let (i, arguments) = parse_field_table.parse(i)?; Ok(( i, @@ -998,7 +998,7 @@ pub mod basic { pub fn parse_get(i: I) -> ParserResult { let (i, _) = parse_short_uint.parse(i)?; let (i, queue) = parse_short_string.parse(i)?; - let (i, flags) = parse_flags(i, &["no-ack"])?; + let (i, flags) = parse_flags(i, &["no_ack"])?; Ok(( i, Get { @@ -3040,7 +3040,7 @@ pub mod exchange { let (i, kind) = parse_short_string.parse(i)?; let (i, flags) = parse_flags( i, - &["passive", "durable", "auto-delete", "internal", "nowait"], + &["passive", "durable", "auto_delete", "internal", "nowait"], )?; let (i, arguments) = parse_field_table.parse(i)?; Ok(( @@ -3135,7 +3135,7 @@ pub mod exchange { pub fn parse_delete(i: I) -> ParserResult { let (i, _) = parse_short_uint.parse(i)?; let (i, exchange) = parse_short_string.parse(i)?; - let (i, flags) = parse_flags(i, &["if-unused", "nowait"])?; + let (i, flags) = parse_flags(i, &["if_unused", "nowait"])?; Ok(( i, Delete { @@ -3527,7 +3527,7 @@ pub mod queue { let (i, queue) = parse_short_string.parse(i)?; let (i, flags) = parse_flags( i, - &["passive", "durable", "exclusive", "auto-delete", "nowait"], + &["passive", "durable", "exclusive", "auto_delete", "nowait"], )?; let (i, arguments) = parse_field_table.parse(i)?; Ok(( @@ -3820,7 +3820,7 @@ pub mod queue { pub fn parse_delete(i: I) -> ParserResult { let (i, _) = parse_short_uint.parse(i)?; let (i, queue) = parse_short_string.parse(i)?; - let (i, flags) = parse_flags(i, &["if-unused", "if-empty", "nowait"])?; + let (i, flags) = parse_flags(i, &["if_unused", "if_empty", "nowait"])?; Ok(( i, Delete { diff --git a/protocol/templates/protocol.rs b/protocol/templates/protocol.rs index ab16fd9..5688a93 100644 --- a/protocol/templates/protocol.rs +++ b/protocol/templates/protocol.rs @@ -241,7 +241,7 @@ pub mod {{snake class.name}} { {{else}} let (i, {{#if argument.ignore_flags ~}}_{{else}}flags{{/if ~}}) = parse_flags(i, &[ {{#each argument.flags as |flag| ~}} - "{{flag.name}}", + "{{snake flag.name}}", {{/each ~}} ])?; {{/if ~}}