more renaming

This commit is contained in:
nora 2022-02-20 15:39:24 +01:00
parent 7ce8f8058d
commit 186f744715
9 changed files with 213 additions and 341 deletions

View file

@ -107,8 +107,8 @@ impl Connection {
ensure_conn(start_ok_frame.kind == FrameType::Method)?; ensure_conn(start_ok_frame.kind == FrameType::Method)?;
let class = methods::parse_method(&start_ok_frame.payload)?; let method = methods::parse_method(&start_ok_frame.payload)?;
Ok(class) Ok(method)
} }
async fn start(&mut self) -> Result<()> { async fn start(&mut self) -> Result<()> {

View file

@ -906,24 +906,19 @@ pub mod parse {
fn connection_start(input: &[u8]) -> IResult<'_, Method> { fn connection_start(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, version_major) = domain_octet(input) let (input, version_major) =
.map_err(fail_err("field version-major in method start")) domain_octet(input).map_err(fail_err("field version-major in method start"))?;
.map_err(failure)?; let (input, version_minor) =
let (input, version_minor) = domain_octet(input) domain_octet(input).map_err(fail_err("field version-minor in method start"))?;
.map_err(fail_err("field version-minor in method start"))
.map_err(failure)?;
let (input, server_properties) = domain_peer_properties(input) let (input, server_properties) = domain_peer_properties(input)
.map_err(fail_err("field server-properties in method start")) .map_err(fail_err("field server-properties in method start"))?;
.map_err(failure)?; let (input, mechanisms) =
let (input, mechanisms) = domain_longstr(input) domain_longstr(input).map_err(fail_err("field mechanisms in method start"))?;
.map_err(fail_err("field mechanisms in method start"))
.map_err(failure)?;
if mechanisms.is_empty() { if mechanisms.is_empty() {
fail!("string was null for field mechanisms") fail!("string was null for field mechanisms")
} }
let (input, locales) = domain_longstr(input) let (input, locales) =
.map_err(fail_err("field locales in method start")) domain_longstr(input).map_err(fail_err("field locales in method start"))?;
.map_err(failure)?;
if locales.is_empty() { if locales.is_empty() {
fail!("string was null for field locales") fail!("string was null for field locales")
} }
@ -942,23 +937,19 @@ pub mod parse {
let (input, _) = let (input, _) =
tag(11_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(11_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, client_properties) = domain_peer_properties(input) let (input, client_properties) = domain_peer_properties(input)
.map_err(fail_err("field client-properties in method start-ok")) .map_err(fail_err("field client-properties in method start-ok"))?;
.map_err(failure)?; let (input, mechanism) =
let (input, mechanism) = domain_shortstr(input) domain_shortstr(input).map_err(fail_err("field mechanism in method start-ok"))?;
.map_err(fail_err("field mechanism in method start-ok"))
.map_err(failure)?;
if mechanism.is_empty() { if mechanism.is_empty() {
fail!("string was null for field mechanism") fail!("string was null for field mechanism")
} }
let (input, response) = domain_longstr(input) let (input, response) =
.map_err(fail_err("field response in method start-ok")) domain_longstr(input).map_err(fail_err("field response in method start-ok"))?;
.map_err(failure)?;
if response.is_empty() { if response.is_empty() {
fail!("string was null for field response") fail!("string was null for field response")
} }
let (input, locale) = domain_shortstr(input) let (input, locale) =
.map_err(fail_err("field locale in method start-ok")) domain_shortstr(input).map_err(fail_err("field locale in method start-ok"))?;
.map_err(failure)?;
if locale.is_empty() { if locale.is_empty() {
fail!("string was null for field locale") fail!("string was null for field locale")
} }
@ -975,17 +966,15 @@ pub mod parse {
fn connection_secure(input: &[u8]) -> IResult<'_, Method> { fn connection_secure(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, challenge) = domain_longstr(input) let (input, challenge) =
.map_err(fail_err("field challenge in method secure")) domain_longstr(input).map_err(fail_err("field challenge in method secure"))?;
.map_err(failure)?;
Ok((input, Method::ConnectionSecure { challenge })) Ok((input, Method::ConnectionSecure { challenge }))
} }
fn connection_secure_ok(input: &[u8]) -> IResult<'_, Method> { fn connection_secure_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(21_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(21_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, response) = domain_longstr(input) let (input, response) =
.map_err(fail_err("field response in method secure-ok")) domain_longstr(input).map_err(fail_err("field response in method secure-ok"))?;
.map_err(failure)?;
if response.is_empty() { if response.is_empty() {
fail!("string was null for field response") fail!("string was null for field response")
} }
@ -994,15 +983,12 @@ pub mod parse {
fn connection_tune(input: &[u8]) -> IResult<'_, Method> { fn connection_tune(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(30_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(30_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, channel_max) = domain_short(input) let (input, channel_max) =
.map_err(fail_err("field channel-max in method tune")) domain_short(input).map_err(fail_err("field channel-max in method tune"))?;
.map_err(failure)?; let (input, frame_max) =
let (input, frame_max) = domain_long(input) domain_long(input).map_err(fail_err("field frame-max in method tune"))?;
.map_err(fail_err("field frame-max in method tune")) let (input, heartbeat) =
.map_err(failure)?; domain_short(input).map_err(fail_err("field heartbeat in method tune"))?;
let (input, heartbeat) = domain_short(input)
.map_err(fail_err("field heartbeat in method tune"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::ConnectionTune { Method::ConnectionTune {
@ -1015,18 +1001,15 @@ pub mod parse {
fn connection_tune_ok(input: &[u8]) -> IResult<'_, Method> { fn connection_tune_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(31_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(31_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, channel_max) = domain_short(input) let (input, channel_max) =
.map_err(fail_err("field channel-max in method tune-ok")) domain_short(input).map_err(fail_err("field channel-max in method tune-ok"))?;
.map_err(failure)?;
if channel_max == 0 { if channel_max == 0 {
fail!("number was 0 for field channel_max") fail!("number was 0 for field channel_max")
} }
let (input, frame_max) = domain_long(input) let (input, frame_max) =
.map_err(fail_err("field frame-max in method tune-ok")) domain_long(input).map_err(fail_err("field frame-max in method tune-ok"))?;
.map_err(failure)?; let (input, heartbeat) =
let (input, heartbeat) = domain_short(input) domain_short(input).map_err(fail_err("field heartbeat in method tune-ok"))?;
.map_err(fail_err("field heartbeat in method tune-ok"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::ConnectionTuneOk { Method::ConnectionTuneOk {
@ -1039,15 +1022,11 @@ pub mod parse {
fn connection_open(input: &[u8]) -> IResult<'_, Method> { fn connection_open(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, virtual_host) = domain_path(input) let (input, virtual_host) =
.map_err(fail_err("field virtual-host in method open")) domain_path(input).map_err(fail_err("field virtual-host in method open"))?;
.map_err(failure)?; let (input, reserved_1) =
let (input, reserved_1) = domain_shortstr(input) domain_shortstr(input).map_err(fail_err("field reserved-1 in method open"))?;
.map_err(fail_err("field reserved-1 in method open")) let (input, bits) = bit(input, 1).map_err(fail_err("field reserved-2 in method open"))?;
.map_err(failure)?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field reserved-2 in method open"))
.map_err(failure)?;
let reserved_2 = bits[0]; let reserved_2 = bits[0];
Ok(( Ok((
input, input,
@ -1061,26 +1040,21 @@ pub mod parse {
fn connection_open_ok(input: &[u8]) -> IResult<'_, Method> { fn connection_open_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(41_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(41_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_shortstr(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method open-ok")) domain_shortstr(input).map_err(fail_err("field reserved-1 in method open-ok"))?;
.map_err(failure)?;
Ok((input, Method::ConnectionOpenOk { reserved_1 })) Ok((input, Method::ConnectionOpenOk { reserved_1 }))
} }
fn connection_close(input: &[u8]) -> IResult<'_, Method> { fn connection_close(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(50_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(50_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reply_code) = domain_reply_code(input) let (input, reply_code) =
.map_err(fail_err("field reply-code in method close")) domain_reply_code(input).map_err(fail_err("field reply-code in method close"))?;
.map_err(failure)?; let (input, reply_text) =
let (input, reply_text) = domain_reply_text(input) domain_reply_text(input).map_err(fail_err("field reply-text in method close"))?;
.map_err(fail_err("field reply-text in method close")) let (input, class_id) =
.map_err(failure)?; domain_class_id(input).map_err(fail_err("field class-id in method close"))?;
let (input, class_id) = domain_class_id(input) let (input, method_id) =
.map_err(fail_err("field class-id in method close")) domain_method_id(input).map_err(fail_err("field method-id in method close"))?;
.map_err(failure)?;
let (input, method_id) = domain_method_id(input)
.map_err(fail_err("field method-id in method close"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::ConnectionClose { Method::ConnectionClose {
@ -1112,52 +1086,42 @@ pub mod parse {
fn channel_open(input: &[u8]) -> IResult<'_, Method> { fn channel_open(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_shortstr(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method open")) domain_shortstr(input).map_err(fail_err("field reserved-1 in method open"))?;
.map_err(failure)?;
Ok((input, Method::ChannelOpen { reserved_1 })) Ok((input, Method::ChannelOpen { reserved_1 }))
} }
fn channel_open_ok(input: &[u8]) -> IResult<'_, Method> { fn channel_open_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(11_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(11_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_longstr(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method open-ok")) domain_longstr(input).map_err(fail_err("field reserved-1 in method open-ok"))?;
.map_err(failure)?;
Ok((input, Method::ChannelOpenOk { reserved_1 })) Ok((input, Method::ChannelOpenOk { reserved_1 }))
} }
fn channel_flow(input: &[u8]) -> IResult<'_, Method> { fn channel_flow(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, bits) = bit(input, 1) let (input, bits) = bit(input, 1).map_err(fail_err("field active in method flow"))?;
.map_err(fail_err("field active in method flow"))
.map_err(failure)?;
let active = bits[0]; let active = bits[0];
Ok((input, Method::ChannelFlow { active })) Ok((input, Method::ChannelFlow { active }))
} }
fn channel_flow_ok(input: &[u8]) -> IResult<'_, Method> { fn channel_flow_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(21_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(21_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, bits) = bit(input, 1) let (input, bits) = bit(input, 1).map_err(fail_err("field active in method flow-ok"))?;
.map_err(fail_err("field active in method flow-ok"))
.map_err(failure)?;
let active = bits[0]; let active = bits[0];
Ok((input, Method::ChannelFlowOk { active })) Ok((input, Method::ChannelFlowOk { active }))
} }
fn channel_close(input: &[u8]) -> IResult<'_, Method> { fn channel_close(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reply_code) = domain_reply_code(input) let (input, reply_code) =
.map_err(fail_err("field reply-code in method close")) domain_reply_code(input).map_err(fail_err("field reply-code in method close"))?;
.map_err(failure)?; let (input, reply_text) =
let (input, reply_text) = domain_reply_text(input) domain_reply_text(input).map_err(fail_err("field reply-text in method close"))?;
.map_err(fail_err("field reply-text in method close")) let (input, class_id) =
.map_err(failure)?; domain_class_id(input).map_err(fail_err("field class-id in method close"))?;
let (input, class_id) = domain_class_id(input) let (input, method_id) =
.map_err(fail_err("field class-id in method close")) domain_method_id(input).map_err(fail_err("field method-id in method close"))?;
.map_err(failure)?;
let (input, method_id) = domain_method_id(input)
.map_err(fail_err("field method-id in method close"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::ChannelClose { Method::ChannelClose {
@ -1187,29 +1151,23 @@ pub mod parse {
fn exchange_declare(input: &[u8]) -> IResult<'_, Method> { fn exchange_declare(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method declare")) domain_short(input).map_err(fail_err("field reserved-1 in method declare"))?;
.map_err(failure)?; let (input, exchange) =
let (input, exchange) = domain_exchange_name(input) domain_exchange_name(input).map_err(fail_err("field exchange in method declare"))?;
.map_err(fail_err("field exchange in method declare"))
.map_err(failure)?;
if exchange.is_empty() { if exchange.is_empty() {
fail!("string was null for field exchange") fail!("string was null for field exchange")
} }
let (input, r#type) = domain_shortstr(input) let (input, r#type) =
.map_err(fail_err("field type in method declare")) domain_shortstr(input).map_err(fail_err("field type in method declare"))?;
.map_err(failure)?; let (input, bits) = bit(input, 5).map_err(fail_err("field passive in method declare"))?;
let (input, bits) = bit(input, 5)
.map_err(fail_err("field passive in method declare"))
.map_err(failure)?;
let passive = bits[0]; let passive = bits[0];
let durable = bits[1]; let durable = bits[1];
let reserved_2 = bits[2]; let reserved_2 = bits[2];
let reserved_3 = bits[3]; let reserved_3 = bits[3];
let no_wait = bits[4]; let no_wait = bits[4];
let (input, arguments) = domain_table(input) let (input, arguments) =
.map_err(fail_err("field arguments in method declare")) domain_table(input).map_err(fail_err("field arguments in method declare"))?;
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::ExchangeDeclare { Method::ExchangeDeclare {
@ -1233,18 +1191,14 @@ pub mod parse {
fn exchange_delete(input: &[u8]) -> IResult<'_, Method> { fn exchange_delete(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method delete")) domain_short(input).map_err(fail_err("field reserved-1 in method delete"))?;
.map_err(failure)?; let (input, exchange) =
let (input, exchange) = domain_exchange_name(input) domain_exchange_name(input).map_err(fail_err("field exchange in method delete"))?;
.map_err(fail_err("field exchange in method delete"))
.map_err(failure)?;
if exchange.is_empty() { if exchange.is_empty() {
fail!("string was null for field exchange") fail!("string was null for field exchange")
} }
let (input, bits) = bit(input, 2) let (input, bits) = bit(input, 2).map_err(fail_err("field if-unused in method delete"))?;
.map_err(fail_err("field if-unused in method delete"))
.map_err(failure)?;
let if_unused = bits[0]; let if_unused = bits[0];
let no_wait = bits[1]; let no_wait = bits[1];
Ok(( Ok((
@ -1282,23 +1236,18 @@ pub mod parse {
fn queue_declare(input: &[u8]) -> IResult<'_, Method> { fn queue_declare(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method declare")) domain_short(input).map_err(fail_err("field reserved-1 in method declare"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method declare"))?;
.map_err(fail_err("field queue in method declare")) let (input, bits) = bit(input, 5).map_err(fail_err("field passive in method declare"))?;
.map_err(failure)?;
let (input, bits) = bit(input, 5)
.map_err(fail_err("field passive in method declare"))
.map_err(failure)?;
let passive = bits[0]; let passive = bits[0];
let durable = bits[1]; let durable = bits[1];
let exclusive = bits[2]; let exclusive = bits[2];
let auto_delete = bits[3]; let auto_delete = bits[3];
let no_wait = bits[4]; let no_wait = bits[4];
let (input, arguments) = domain_table(input) let (input, arguments) =
.map_err(fail_err("field arguments in method declare")) domain_table(input).map_err(fail_err("field arguments in method declare"))?;
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::QueueDeclare { Method::QueueDeclare {
@ -1316,18 +1265,15 @@ pub mod parse {
fn queue_declare_ok(input: &[u8]) -> IResult<'_, Method> { fn queue_declare_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(11_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(11_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, queue) = domain_queue_name(input) let (input, queue) =
.map_err(fail_err("field queue in method declare-ok")) domain_queue_name(input).map_err(fail_err("field queue in method declare-ok"))?;
.map_err(failure)?;
if queue.is_empty() { if queue.is_empty() {
fail!("string was null for field queue") fail!("string was null for field queue")
} }
let (input, message_count) = domain_message_count(input) let (input, message_count) = domain_message_count(input)
.map_err(fail_err("field message-count in method declare-ok")) .map_err(fail_err("field message-count in method declare-ok"))?;
.map_err(failure)?; let (input, consumer_count) =
let (input, consumer_count) = domain_long(input) domain_long(input).map_err(fail_err("field consumer-count in method declare-ok"))?;
.map_err(fail_err("field consumer-count in method declare-ok"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::QueueDeclareOk { Method::QueueDeclareOk {
@ -1340,25 +1286,18 @@ pub mod parse {
fn queue_bind(input: &[u8]) -> IResult<'_, Method> { fn queue_bind(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method bind")) domain_short(input).map_err(fail_err("field reserved-1 in method bind"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method bind"))?;
.map_err(fail_err("field queue in method bind")) let (input, exchange) =
.map_err(failure)?; domain_exchange_name(input).map_err(fail_err("field exchange in method bind"))?;
let (input, exchange) = domain_exchange_name(input) let (input, routing_key) =
.map_err(fail_err("field exchange in method bind")) domain_shortstr(input).map_err(fail_err("field routing-key in method bind"))?;
.map_err(failure)?; let (input, bits) = bit(input, 1).map_err(fail_err("field no-wait in method bind"))?;
let (input, routing_key) = domain_shortstr(input)
.map_err(fail_err("field routing-key in method bind"))
.map_err(failure)?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field no-wait in method bind"))
.map_err(failure)?;
let no_wait = bits[0]; let no_wait = bits[0];
let (input, arguments) = domain_table(input) let (input, arguments) =
.map_err(fail_err("field arguments in method bind")) domain_table(input).map_err(fail_err("field arguments in method bind"))?;
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::QueueBind { Method::QueueBind {
@ -1379,21 +1318,16 @@ pub mod parse {
fn queue_unbind(input: &[u8]) -> IResult<'_, Method> { fn queue_unbind(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(50_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(50_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method unbind")) domain_short(input).map_err(fail_err("field reserved-1 in method unbind"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method unbind"))?;
.map_err(fail_err("field queue in method unbind")) let (input, exchange) =
.map_err(failure)?; domain_exchange_name(input).map_err(fail_err("field exchange in method unbind"))?;
let (input, exchange) = domain_exchange_name(input) let (input, routing_key) =
.map_err(fail_err("field exchange in method unbind")) domain_shortstr(input).map_err(fail_err("field routing-key in method unbind"))?;
.map_err(failure)?; let (input, arguments) =
let (input, routing_key) = domain_shortstr(input) domain_table(input).map_err(fail_err("field arguments in method unbind"))?;
.map_err(fail_err("field routing-key in method unbind"))
.map_err(failure)?;
let (input, arguments) = domain_table(input)
.map_err(fail_err("field arguments in method unbind"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::QueueUnbind { Method::QueueUnbind {
@ -1413,15 +1347,11 @@ pub mod parse {
fn queue_purge(input: &[u8]) -> IResult<'_, Method> { fn queue_purge(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(30_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(30_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method purge")) domain_short(input).map_err(fail_err("field reserved-1 in method purge"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method purge"))?;
.map_err(fail_err("field queue in method purge")) let (input, bits) = bit(input, 1).map_err(fail_err("field no-wait in method purge"))?;
.map_err(failure)?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field no-wait in method purge"))
.map_err(failure)?;
let no_wait = bits[0]; let no_wait = bits[0];
Ok(( Ok((
input, input,
@ -1436,22 +1366,17 @@ pub mod parse {
let (input, _) = let (input, _) =
tag(31_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(31_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, message_count) = domain_message_count(input) let (input, message_count) = domain_message_count(input)
.map_err(fail_err("field message-count in method purge-ok")) .map_err(fail_err("field message-count in method purge-ok"))?;
.map_err(failure)?;
Ok((input, Method::QueuePurgeOk { message_count })) Ok((input, Method::QueuePurgeOk { message_count }))
} }
fn queue_delete(input: &[u8]) -> IResult<'_, Method> { fn queue_delete(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method delete")) domain_short(input).map_err(fail_err("field reserved-1 in method delete"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method delete"))?;
.map_err(fail_err("field queue in method delete")) let (input, bits) = bit(input, 3).map_err(fail_err("field if-unused in method delete"))?;
.map_err(failure)?;
let (input, bits) = bit(input, 3)
.map_err(fail_err("field if-unused in method delete"))
.map_err(failure)?;
let if_unused = bits[0]; let if_unused = bits[0];
let if_empty = bits[1]; let if_empty = bits[1];
let no_wait = bits[2]; let no_wait = bits[2];
@ -1470,8 +1395,7 @@ pub mod parse {
let (input, _) = let (input, _) =
tag(41_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(41_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, message_count) = domain_message_count(input) let (input, message_count) = domain_message_count(input)
.map_err(fail_err("field message-count in method delete-ok")) .map_err(fail_err("field message-count in method delete-ok"))?;
.map_err(failure)?;
Ok((input, Method::QueueDeleteOk { message_count })) Ok((input, Method::QueueDeleteOk { message_count }))
} }
fn basic(input: &[u8]) -> IResult<'_, Method> { fn basic(input: &[u8]) -> IResult<'_, Method> {
@ -1501,15 +1425,11 @@ pub mod parse {
fn basic_qos(input: &[u8]) -> IResult<'_, Method> { fn basic_qos(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(10_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, prefetch_size) = domain_long(input) let (input, prefetch_size) =
.map_err(fail_err("field prefetch-size in method qos")) domain_long(input).map_err(fail_err("field prefetch-size in method qos"))?;
.map_err(failure)?; let (input, prefetch_count) =
let (input, prefetch_count) = domain_short(input) domain_short(input).map_err(fail_err("field prefetch-count in method qos"))?;
.map_err(fail_err("field prefetch-count in method qos")) let (input, bits) = bit(input, 1).map_err(fail_err("field global in method qos"))?;
.map_err(failure)?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field global in method qos"))
.map_err(failure)?;
let global = bits[0]; let global = bits[0];
Ok(( Ok((
input, input,
@ -1528,25 +1448,19 @@ pub mod parse {
fn basic_consume(input: &[u8]) -> IResult<'_, Method> { fn basic_consume(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(20_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method consume")) domain_short(input).map_err(fail_err("field reserved-1 in method consume"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method consume"))?;
.map_err(fail_err("field queue in method consume")) let (input, consumer_tag) =
.map_err(failure)?; domain_consumer_tag(input).map_err(fail_err("field consumer-tag in method consume"))?;
let (input, consumer_tag) = domain_consumer_tag(input) let (input, bits) = bit(input, 4).map_err(fail_err("field no-local in method consume"))?;
.map_err(fail_err("field consumer-tag in method consume"))
.map_err(failure)?;
let (input, bits) = bit(input, 4)
.map_err(fail_err("field no-local in method consume"))
.map_err(failure)?;
let no_local = bits[0]; let no_local = bits[0];
let no_ack = bits[1]; let no_ack = bits[1];
let exclusive = bits[2]; let exclusive = bits[2];
let no_wait = bits[3]; let no_wait = bits[3];
let (input, arguments) = domain_table(input) let (input, arguments) =
.map_err(fail_err("field arguments in method consume")) domain_table(input).map_err(fail_err("field arguments in method consume"))?;
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::BasicConsume { Method::BasicConsume {
@ -1565,19 +1479,15 @@ pub mod parse {
let (input, _) = let (input, _) =
tag(21_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(21_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, consumer_tag) = domain_consumer_tag(input) let (input, consumer_tag) = domain_consumer_tag(input)
.map_err(fail_err("field consumer-tag in method consume-ok")) .map_err(fail_err("field consumer-tag in method consume-ok"))?;
.map_err(failure)?;
Ok((input, Method::BasicConsumeOk { consumer_tag })) Ok((input, Method::BasicConsumeOk { consumer_tag }))
} }
fn basic_cancel(input: &[u8]) -> IResult<'_, Method> { fn basic_cancel(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(30_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(30_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, consumer_tag) = domain_consumer_tag(input) let (input, consumer_tag) =
.map_err(fail_err("field consumer-tag in method cancel")) domain_consumer_tag(input).map_err(fail_err("field consumer-tag in method cancel"))?;
.map_err(failure)?; let (input, bits) = bit(input, 1).map_err(fail_err("field no-wait in method cancel"))?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field no-wait in method cancel"))
.map_err(failure)?;
let no_wait = bits[0]; let no_wait = bits[0];
Ok(( Ok((
input, input,
@ -1591,25 +1501,19 @@ pub mod parse {
let (input, _) = let (input, _) =
tag(31_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(31_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, consumer_tag) = domain_consumer_tag(input) let (input, consumer_tag) = domain_consumer_tag(input)
.map_err(fail_err("field consumer-tag in method cancel-ok")) .map_err(fail_err("field consumer-tag in method cancel-ok"))?;
.map_err(failure)?;
Ok((input, Method::BasicCancelOk { consumer_tag })) Ok((input, Method::BasicCancelOk { consumer_tag }))
} }
fn basic_publish(input: &[u8]) -> IResult<'_, Method> { fn basic_publish(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(40_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method publish")) domain_short(input).map_err(fail_err("field reserved-1 in method publish"))?;
.map_err(failure)?; let (input, exchange) =
let (input, exchange) = domain_exchange_name(input) domain_exchange_name(input).map_err(fail_err("field exchange in method publish"))?;
.map_err(fail_err("field exchange in method publish")) let (input, routing_key) =
.map_err(failure)?; domain_shortstr(input).map_err(fail_err("field routing-key in method publish"))?;
let (input, routing_key) = domain_shortstr(input) let (input, bits) = bit(input, 2).map_err(fail_err("field mandatory in method publish"))?;
.map_err(fail_err("field routing-key in method publish"))
.map_err(failure)?;
let (input, bits) = bit(input, 2)
.map_err(fail_err("field mandatory in method publish"))
.map_err(failure)?;
let mandatory = bits[0]; let mandatory = bits[0];
let immediate = bits[1]; let immediate = bits[1];
Ok(( Ok((
@ -1626,18 +1530,14 @@ pub mod parse {
fn basic_return(input: &[u8]) -> IResult<'_, Method> { fn basic_return(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(50_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(50_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reply_code) = domain_reply_code(input) let (input, reply_code) =
.map_err(fail_err("field reply-code in method return")) domain_reply_code(input).map_err(fail_err("field reply-code in method return"))?;
.map_err(failure)?; let (input, reply_text) =
let (input, reply_text) = domain_reply_text(input) domain_reply_text(input).map_err(fail_err("field reply-text in method return"))?;
.map_err(fail_err("field reply-text in method return")) let (input, exchange) =
.map_err(failure)?; domain_exchange_name(input).map_err(fail_err("field exchange in method return"))?;
let (input, exchange) = domain_exchange_name(input) let (input, routing_key) =
.map_err(fail_err("field exchange in method return")) domain_shortstr(input).map_err(fail_err("field routing-key in method return"))?;
.map_err(failure)?;
let (input, routing_key) = domain_shortstr(input)
.map_err(fail_err("field routing-key in method return"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::BasicReturn { Method::BasicReturn {
@ -1651,22 +1551,17 @@ pub mod parse {
fn basic_deliver(input: &[u8]) -> IResult<'_, Method> { fn basic_deliver(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(60_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(60_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, consumer_tag) = domain_consumer_tag(input) let (input, consumer_tag) =
.map_err(fail_err("field consumer-tag in method deliver")) domain_consumer_tag(input).map_err(fail_err("field consumer-tag in method deliver"))?;
.map_err(failure)?; let (input, delivery_tag) =
let (input, delivery_tag) = domain_delivery_tag(input) domain_delivery_tag(input).map_err(fail_err("field delivery-tag in method deliver"))?;
.map_err(fail_err("field delivery-tag in method deliver")) let (input, bits) =
.map_err(failure)?; bit(input, 1).map_err(fail_err("field redelivered in method deliver"))?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field redelivered in method deliver"))
.map_err(failure)?;
let redelivered = bits[0]; let redelivered = bits[0];
let (input, exchange) = domain_exchange_name(input) let (input, exchange) =
.map_err(fail_err("field exchange in method deliver")) domain_exchange_name(input).map_err(fail_err("field exchange in method deliver"))?;
.map_err(failure)?; let (input, routing_key) =
let (input, routing_key) = domain_shortstr(input) domain_shortstr(input).map_err(fail_err("field routing-key in method deliver"))?;
.map_err(fail_err("field routing-key in method deliver"))
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::BasicDeliver { Method::BasicDeliver {
@ -1681,15 +1576,11 @@ pub mod parse {
fn basic_get(input: &[u8]) -> IResult<'_, Method> { fn basic_get(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(70_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(70_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_short(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method get")) domain_short(input).map_err(fail_err("field reserved-1 in method get"))?;
.map_err(failure)?; let (input, queue) =
let (input, queue) = domain_queue_name(input) domain_queue_name(input).map_err(fail_err("field queue in method get"))?;
.map_err(fail_err("field queue in method get")) let (input, bits) = bit(input, 1).map_err(fail_err("field no-ack in method get"))?;
.map_err(failure)?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field no-ack in method get"))
.map_err(failure)?;
let no_ack = bits[0]; let no_ack = bits[0];
Ok(( Ok((
input, input,
@ -1703,22 +1594,17 @@ pub mod parse {
fn basic_get_ok(input: &[u8]) -> IResult<'_, Method> { fn basic_get_ok(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(71_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(71_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, delivery_tag) = domain_delivery_tag(input) let (input, delivery_tag) =
.map_err(fail_err("field delivery-tag in method get-ok")) domain_delivery_tag(input).map_err(fail_err("field delivery-tag in method get-ok"))?;
.map_err(failure)?; let (input, bits) =
let (input, bits) = bit(input, 1) bit(input, 1).map_err(fail_err("field redelivered in method get-ok"))?;
.map_err(fail_err("field redelivered in method get-ok"))
.map_err(failure)?;
let redelivered = bits[0]; let redelivered = bits[0];
let (input, exchange) = domain_exchange_name(input) let (input, exchange) =
.map_err(fail_err("field exchange in method get-ok")) domain_exchange_name(input).map_err(fail_err("field exchange in method get-ok"))?;
.map_err(failure)?; let (input, routing_key) =
let (input, routing_key) = domain_shortstr(input) domain_shortstr(input).map_err(fail_err("field routing-key in method get-ok"))?;
.map_err(fail_err("field routing-key in method get-ok"))
.map_err(failure)?;
let (input, message_count) = domain_message_count(input) let (input, message_count) = domain_message_count(input)
.map_err(fail_err("field message-count in method get-ok")) .map_err(fail_err("field message-count in method get-ok"))?;
.map_err(failure)?;
Ok(( Ok((
input, input,
Method::BasicGetOk { Method::BasicGetOk {
@ -1733,20 +1619,16 @@ pub mod parse {
fn basic_get_empty(input: &[u8]) -> IResult<'_, Method> { fn basic_get_empty(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(72_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(72_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, reserved_1) = domain_shortstr(input) let (input, reserved_1) =
.map_err(fail_err("field reserved-1 in method get-empty")) domain_shortstr(input).map_err(fail_err("field reserved-1 in method get-empty"))?;
.map_err(failure)?;
Ok((input, Method::BasicGetEmpty { reserved_1 })) Ok((input, Method::BasicGetEmpty { reserved_1 }))
} }
fn basic_ack(input: &[u8]) -> IResult<'_, Method> { fn basic_ack(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(80_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(80_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, delivery_tag) = domain_delivery_tag(input) let (input, delivery_tag) =
.map_err(fail_err("field delivery-tag in method ack")) domain_delivery_tag(input).map_err(fail_err("field delivery-tag in method ack"))?;
.map_err(failure)?; let (input, bits) = bit(input, 1).map_err(fail_err("field multiple in method ack"))?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field multiple in method ack"))
.map_err(failure)?;
let multiple = bits[0]; let multiple = bits[0];
Ok(( Ok((
input, input,
@ -1759,12 +1641,9 @@ pub mod parse {
fn basic_reject(input: &[u8]) -> IResult<'_, Method> { fn basic_reject(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(90_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(90_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, delivery_tag) = domain_delivery_tag(input) let (input, delivery_tag) =
.map_err(fail_err("field delivery-tag in method reject")) domain_delivery_tag(input).map_err(fail_err("field delivery-tag in method reject"))?;
.map_err(failure)?; let (input, bits) = bit(input, 1).map_err(fail_err("field requeue in method reject"))?;
let (input, bits) = bit(input, 1)
.map_err(fail_err("field requeue in method reject"))
.map_err(failure)?;
let requeue = bits[0]; let requeue = bits[0];
Ok(( Ok((
input, input,
@ -1777,18 +1656,15 @@ pub mod parse {
fn basic_recover_async(input: &[u8]) -> IResult<'_, Method> { fn basic_recover_async(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(100_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(100_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, bits) = bit(input, 1) let (input, bits) =
.map_err(fail_err("field requeue in method recover-async")) bit(input, 1).map_err(fail_err("field requeue in method recover-async"))?;
.map_err(failure)?;
let requeue = bits[0]; let requeue = bits[0];
Ok((input, Method::BasicRecoverAsync { requeue })) Ok((input, Method::BasicRecoverAsync { requeue }))
} }
fn basic_recover(input: &[u8]) -> IResult<'_, Method> { fn basic_recover(input: &[u8]) -> IResult<'_, Method> {
let (input, _) = let (input, _) =
tag(110_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?; tag(110_u16.to_be_bytes())(input).map_err(fail_err("parsing method index"))?;
let (input, bits) = bit(input, 1) let (input, bits) = bit(input, 1).map_err(fail_err("field requeue in method recover"))?;
.map_err(fail_err("field requeue in method recover"))
.map_err(failure)?;
let requeue = bits[0]; let requeue = bits[0];
Ok((input, Method::BasicRecover { requeue })) Ok((input, Method::BasicRecover { requeue }))
} }
@ -1847,8 +1723,8 @@ pub mod write {
use crate::methods::write_helper::*; use crate::methods::write_helper::*;
use std::io::Write; use std::io::Write;
pub fn write_method<W: Write>(class: Method, mut writer: W) -> Result<(), TransError> { pub fn write_method<W: Write>(method: Method, mut writer: W) -> Result<(), TransError> {
match class { match method {
Method::ConnectionStart { Method::ConnectionStart {
version_major, version_major,
version_minor, version_minor,

View file

@ -35,12 +35,12 @@ pub enum FieldValue {
pub use generated::*; pub use generated::*;
/// Parses the payload of a method frame into the class/method /// Parses the payload of a method frame into the method
pub fn parse_method(payload: &[u8]) -> Result<generated::Method, TransError> { pub fn parse_method(payload: &[u8]) -> Result<generated::Method, TransError> {
let nom_result = generated::parse::parse_method(payload); let nom_result = generated::parse::parse_method(payload);
match nom_result { match nom_result {
Ok(([], class)) => Ok(class), Ok(([], method)) => Ok(method),
Ok((_, _)) => { Ok((_, _)) => {
Err( Err(
ConException::SyntaxError(vec!["could not consume all input".to_string()]) ConException::SyntaxError(vec!["could not consume all input".to_string()])

View file

@ -53,14 +53,6 @@ pub fn err_other<E, S: Into<String>>(msg: S) -> impl FnOnce(E) -> Err<TransError
move |_| Err::Error(ConException::SyntaxError(vec![msg.into()]).into_trans()) move |_| Err::Error(ConException::SyntaxError(vec![msg.into()]).into_trans())
} }
pub fn failure<E>(err: Err<E>) -> Err<E> {
match err {
Err::Incomplete(needed) => Err::Incomplete(needed),
Err::Error(e) => Err::Failure(e),
Err::Failure(e) => Err::Failure(e),
}
}
#[macro_export] #[macro_export]
macro_rules! fail { macro_rules! fail {
($cause:expr) => { ($cause:expr) => {

View file

@ -103,21 +103,26 @@ fn random_ser_de() {
let mut rng = rand::rngs::StdRng::from_seed([0; 32]); let mut rng = rand::rngs::StdRng::from_seed([0; 32]);
for _ in 0..ITERATIONS { for _ in 0..ITERATIONS {
let class = Method::random(&mut rng); let method = Method::random(&mut rng);
let mut bytes = Vec::new(); let mut bytes = Vec::new();
if let Err(err) = super::write::write_method(class.clone(), &mut bytes) { if let Err(err) = super::write::write_method(method.clone(), &mut bytes) {
eprintln!("{class:#?}"); eprintln!("{method:#?}");
eprintln!("{err:?}"); eprintln!("{err:?}");
panic!("Failed to serialize"); panic!("Failed to serialize");
} }
match super::parse_method(&bytes) { match super::parse_method(&bytes) {
Ok(parsed) => { Ok(parsed) => {
assert_eq!(class, parsed); if method != parsed {
eprintln!("{method:#?}");
eprintln!("{bytes:?}");
eprintln!("{parsed:?}");
panic!("Not equal!");
}
} }
Err(err) => { Err(err) => {
eprintln!("{class:#?}"); eprintln!("{method:#?}");
eprintln!("{bytes:?}"); eprintln!("{bytes:?}");
eprintln!("{err:?}"); eprintln!("{err:?}");
panic!("Failed to deserialize"); panic!("Failed to deserialize");

View file

@ -21,7 +21,7 @@ pub(super) fn codegen_parser(amqp: &Amqp) {
println!( println!(
"pub mod parse {{ "pub mod parse {{
use super::*; use super::*;
use crate::classes::parse_helper::*; use crate::methods::parse_helper::*;
use crate::error::TransError; use crate::error::TransError;
use nom::{{branch::alt, bytes::complete::tag}}; use nom::{{branch::alt, bytes::complete::tag}};
use regex::Regex; use regex::Regex;
@ -108,9 +108,8 @@ fn method_parser(amqp: &Amqp, class: &Class, method: &Method) {
let fields_with_bit = subsequent_bit_fields(amqp, field, &mut iter); let fields_with_bit = subsequent_bit_fields(amqp, field, &mut iter);
let amount = fields_with_bit.len(); let amount = fields_with_bit.len();
// todo: remove those map_err(failure)
println!( println!(
r#" let (input, bits) = bit(input, {amount}).map_err(fail_err("field {field_name_raw} in method {method_name_raw}")).map_err(failure)?;"# r#" let (input, bits) = bit(input, {amount}).map_err(fail_err("field {field_name_raw} in method {method_name_raw}"))?;"#
); );
for (i, field) in fields_with_bit.iter().enumerate() { for (i, field) in fields_with_bit.iter().enumerate() {
@ -121,7 +120,7 @@ fn method_parser(amqp: &Amqp, class: &Class, method: &Method) {
let fn_name = domain_function_name(field_type(field)); let fn_name = domain_function_name(field_type(field));
let field_name = snake_case(&field.name); let field_name = snake_case(&field.name);
println!( println!(
r#" let (input, {field_name}) = {fn_name}(input).map_err(fail_err("field {field_name_raw} in method {method_name_raw}")).map_err(failure)?;"# r#" let (input, {field_name}) = {fn_name}(input).map_err(fail_err("field {field_name_raw} in method {method_name_raw}"))?;"#
); );
for assert in &field.asserts { for assert in &field.asserts {

View file

@ -6,7 +6,7 @@ pub(super) fn codegen_random(amqp: &Amqp) {
"#[cfg(test)] "#[cfg(test)]
mod random {{ mod random {{
use rand::Rng; use rand::Rng;
use crate::classes::tests::RandomMethod; use crate::methods::tests::RandomMethod;
use super::*; use super::*;
" "
); );

View file

@ -5,12 +5,12 @@ pub(super) fn codegen_write(amqp: &Amqp) {
println!( println!(
"pub mod write {{ "pub mod write {{
use super::*; use super::*;
use crate::classes::write_helper::*; use crate::methods::write_helper::*;
use crate::error::TransError; use crate::error::TransError;
use std::io::Write; use std::io::Write;
pub fn write_method<W: Write>(class: Method, mut writer: W) -> Result<(), TransError> {{ pub fn write_method<W: Write>(method: Method, mut writer: W) -> Result<(), TransError> {{
match class {{" match method {{"
); );
for class in &amqp.classes { for class in &amqp.classes {

View file

@ -16,7 +16,7 @@ fn main() {
fn help() { fn help() {
println!( println!(
"Available tasks: "Available tasks:
generate - Generate amqp method code in `amqp_transport/src/classes/generated.rs. generate - Generate amqp method code in `amqp_transport/src/methods/generated.rs.
Dumps code to stdout and should be redirected manually." Dumps code to stdout and should be redirected manually."
); );
} }