From ed4a107c44e3646a108809b01874c4bf7d07116f Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 20 Feb 2022 14:10:19 +0100 Subject: [PATCH] cleanup --- Cargo.lock | 124 - Cargo.toml | 2 +- amqp_core/src/lib.rs | 2 + amqp_dashboard/Cargo.toml | 1 - amqp_dashboard/src/lib.rs | 2 + amqp_transport/Cargo.toml | 2 +- amqp_transport/src/classes/generated.rs | 3099 +++++++++----------- amqp_transport/src/classes/parse_helper.rs | 58 +- amqp_transport/src/connection.rs | 1 + amqp_transport/src/lib.rs | 2 +- src/main.rs | 11 +- xtask/src/codegen/mod.rs | 2 + xtask/src/codegen/parser.rs | 2 +- 13 files changed, 1448 insertions(+), 1860 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb7a8e8..a90b3c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aho-corasick" version = "0.7.18" @@ -55,7 +40,6 @@ dependencies = [ "axum", "serde", "tokio", - "tower-http", "tracing", ] @@ -89,9 +73,6 @@ name = "anyhow" version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" -dependencies = [ - "backtrace", -] [[package]] name = "async-trait" @@ -104,12 +85,6 @@ dependencies = [ "syn", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "axum" version = "0.4.5" @@ -155,21 +130,6 @@ dependencies = [ "mime", ] -[[package]] -name = "backtrace" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -182,12 +142,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" -[[package]] -name = "cc" -version = "1.0.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" - [[package]] name = "cfg-if" version = "1.0.0" @@ -266,12 +220,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "gimli" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" - [[package]] name = "heck" version = "0.4.0" @@ -401,15 +349,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata", -] - [[package]] name = "matches" version = "0.1.9" @@ -434,32 +373,12 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg", -] - [[package]] name = "mio" version = "0.8.0" @@ -512,15 +431,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.9.0" @@ -672,27 +582,12 @@ dependencies = [ "regex-syntax", ] -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax", -] - [[package]] name = "regex-syntax" version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" -[[package]] -name = "rustc-demangle" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" - [[package]] name = "ryu" version = "1.0.9" @@ -941,13 +836,7 @@ dependencies = [ "http", "http-body", "http-range-header", - "httpdate", - "mime", - "mime_guess", - "percent-encoding", "pin-project-lite", - "tokio", - "tokio-util 0.7.0", "tower-layer", "tower-service", ] @@ -1016,13 +905,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa" dependencies = [ "ansi_term", - "lazy_static", - "matchers", - "regex", "sharded-slab", "smallvec", "thread_local", - "tracing", "tracing-core", "tracing-log", ] @@ -1033,15 +918,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-xid" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 9492d22..eec63dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ amqp_dashboard = { path = "./amqp_dashboard" } amqp_transport = { path = "./amqp_transport" } tokio = { version = "1.16.1", features = ["full"] } tracing = "0.1.30" -tracing-subscriber = { version = "0.3.8", features = ["env-filter"] } +tracing-subscriber = "0.3.8" diff --git a/amqp_core/src/lib.rs b/amqp_core/src/lib.rs index 42ecdd0..e9f7db2 100644 --- a/amqp_core/src/lib.rs +++ b/amqp_core/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(rust_2018_idioms)] + use parking_lot::Mutex; use std::collections::HashMap; use std::net::SocketAddr; diff --git a/amqp_dashboard/Cargo.toml b/amqp_dashboard/Cargo.toml index cd2d40d..f5a37b5 100644 --- a/amqp_dashboard/Cargo.toml +++ b/amqp_dashboard/Cargo.toml @@ -10,5 +10,4 @@ amqp_core = { path = "../amqp_core" } axum = "0.4.5" serde = { version = "1.0.136", features = ["derive"] } tokio = { version = "1.17.0", features = ["full"] } -tower-http = { version = "0.2.3", features = ["fs"] } tracing = "0.1.31" diff --git a/amqp_dashboard/src/lib.rs b/amqp_dashboard/src/lib.rs index 9e3282d..1fef800 100644 --- a/amqp_dashboard/src/lib.rs +++ b/amqp_dashboard/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(rust_2018_idioms)] + use amqp_core::GlobalData; use axum::body::{boxed, Full}; use axum::response::{Html, IntoResponse, Response}; diff --git a/amqp_transport/Cargo.toml b/amqp_transport/Cargo.toml index 743d328..383d1cf 100644 --- a/amqp_transport/Cargo.toml +++ b/amqp_transport/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] amqp_core = { path = "../amqp_core" } -anyhow = { version = "1.0.53", features = ["backtrace"] } +anyhow = "1.0.53" nom = "7.1.0" once_cell = "1.9.0" rand = "0.8.4" diff --git a/amqp_transport/src/classes/generated.rs b/amqp_transport/src/classes/generated.rs index 93b6ee3..8a48ef4 100644 --- a/amqp_transport/src/classes/generated.rs +++ b/amqp_transport/src/classes/generated.rs @@ -238,7 +238,9 @@ pub enum Connection { reserved_2: Bit, }, /// This method signals to the client that the connection is ready for use. - OpenOk { reserved_1: Shortstr }, + OpenOk { + reserved_1: Shortstr, + }, /// This method indicates that the sender wants to close the connection. This may be /// due to internal conditions (e.g. a forced shut-down) or due to an error handling /// a specific method, i.e. an exception. When a close is due to an exception, the @@ -261,9 +263,13 @@ pub enum Connection { #[derive(Debug, Clone, PartialEq)] pub enum Channel { /// This method opens a channel to the server. - Open { reserved_1: Shortstr }, + Open { + reserved_1: Shortstr, + }, /// This method signals to the client that the channel is ready for use. - OpenOk { reserved_1: Longstr }, + OpenOk { + reserved_1: Longstr, + }, /// This method asks the peer to pause or restart the flow of content data sent by /// a consumer. This is a simple flow-control mechanism that a peer can use to avoid /// overflowing its queues or otherwise finding itself receiving more messages than @@ -539,7 +545,9 @@ pub enum Basic { no_wait: NoWait, }, /// This method confirms that the cancellation was completed. - CancelOk { consumer_tag: ConsumerTag }, + CancelOk { + consumer_tag: ConsumerTag, + }, /// This method publishes a message to a specific exchange. The message will be routed /// to queues as defined by the exchange configuration and distributed to any active /// consumers when the transaction, if any, is committed. @@ -613,7 +621,9 @@ pub enum Basic { }, /// This method tells the client that the queue has no messages available for the /// client. - GetEmpty { reserved_1: Shortstr }, + GetEmpty { + reserved_1: Shortstr, + }, /// This method acknowledges one or more messages delivered via the Deliver or Get-Ok /// methods. The client can ask to confirm a single message or a set of messages up to /// and including a specific message. @@ -688,1711 +698,1402 @@ pub enum Tx { RollbackOk, } pub mod parse { - use super::*; - use crate::classes::parse_helper::*; - use crate::error::TransError; - use nom::{branch::alt, bytes::complete::tag}; - use once_cell::sync::Lazy; - use regex::Regex; +use super::*; +use crate::classes::parse_helper::*; +use crate::error::TransError; +use nom::{branch::alt, bytes::complete::tag}; +use regex::Regex; +use once_cell::sync::Lazy; - pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>; +pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>; + +pub fn parse_method(input: &[u8]) -> Result<(&[u8], Class), nom::Err> { + alt((connection, channel, exchange, queue, basic, tx))(input) +} +fn domain_class_id(input: &[u8]) -> IResult<'_, ClassId> { + short(input) +} +fn domain_consumer_tag(input: &[u8]) -> IResult<'_, ConsumerTag> { + shortstr(input) +} +fn domain_delivery_tag(input: &[u8]) -> IResult<'_, DeliveryTag> { + longlong(input) +} +fn domain_exchange_name(input: &[u8]) -> IResult<'_, ExchangeName> { + let (input, result) = shortstr(input)?; + if result.len() > 127 { fail!("value is shorter than 127 for field result") } + static REGEX: Lazy = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9-_.:]*$").unwrap()); + if !REGEX.is_match(&result) { fail!(r"regex `^[a-zA-Z0-9-_.:]*$` did not match value for field result") } + Ok((input, result)) +} +fn domain_method_id(input: &[u8]) -> IResult<'_, MethodId> { + short(input) +} +fn domain_path(input: &[u8]) -> IResult<'_, Path> { + let (input, result) = shortstr(input)?; + if result.is_empty() { fail!("string was null for field result") } + if result.len() > 127 { fail!("value is shorter than 127 for field result") } + Ok((input, result)) +} +fn domain_peer_properties(input: &[u8]) -> IResult<'_, PeerProperties> { + table(input) +} +fn domain_queue_name(input: &[u8]) -> IResult<'_, QueueName> { + let (input, result) = shortstr(input)?; + if result.len() > 127 { fail!("value is shorter than 127 for field result") } + static REGEX: Lazy = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9-_.:]*$").unwrap()); + if !REGEX.is_match(&result) { fail!(r"regex `^[a-zA-Z0-9-_.:]*$` did not match value for field result") } + Ok((input, result)) +} +fn domain_message_count(input: &[u8]) -> IResult<'_, MessageCount> { + long(input) +} +fn domain_reply_code(input: &[u8]) -> IResult<'_, ReplyCode> { + let (input, result) = short(input)?; + if result == 0 { fail!("number was 0 for field result") } + Ok((input, result)) +} +fn domain_reply_text(input: &[u8]) -> IResult<'_, ReplyText> { + let (input, result) = shortstr(input)?; + if result.is_empty() { fail!("string was null for field result") } + Ok((input, result)) +} +fn domain_octet(input: &[u8]) -> IResult<'_, Octet> { + octet(input) +} +fn domain_short(input: &[u8]) -> IResult<'_, Short> { + short(input) +} +fn domain_long(input: &[u8]) -> IResult<'_, Long> { + long(input) +} +fn domain_longlong(input: &[u8]) -> IResult<'_, Longlong> { + longlong(input) +} +fn domain_shortstr(input: &[u8]) -> IResult<'_, Shortstr> { + shortstr(input) +} +fn domain_longstr(input: &[u8]) -> IResult<'_, Longstr> { + longstr(input) +} +fn domain_timestamp(input: &[u8]) -> IResult<'_, Timestamp> { + timestamp(input) +} +fn domain_table(input: &[u8]) -> IResult<'_, Table> { + table(input) +} +fn connection(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("invalid tag for class connection"))?; + alt((connection_start, connection_start_ok, connection_secure, connection_secure_ok, connection_tune, connection_tune_ok, connection_open, connection_open_ok, connection_close, connection_close_ok))(input).map_err(err("class connection")).map_err(failure) +} +fn connection_start(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, version_major) = domain_octet(input).map_err(err("field version-major in method start")).map_err(failure)?; + let (input, version_minor) = domain_octet(input).map_err(err("field version-minor in method start")).map_err(failure)?; + let (input, server_properties) = domain_peer_properties(input).map_err(err("field server-properties in method start")).map_err(failure)?; + let (input, mechanisms) = domain_longstr(input).map_err(err("field mechanisms in method start")).map_err(failure)?; + if mechanisms.is_empty() { fail!("string was null for field mechanisms") } + let (input, locales) = domain_longstr(input).map_err(err("field locales in method start")).map_err(failure)?; + if locales.is_empty() { fail!("string was null for field locales") } + Ok((input, Class::Connection(Connection::Start { + version_major, + version_minor, + server_properties, + mechanisms, + locales, + }))) +} +fn connection_start_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, client_properties) = domain_peer_properties(input).map_err(err("field client-properties in method start-ok")).map_err(failure)?; + let (input, mechanism) = domain_shortstr(input).map_err(err("field mechanism in method start-ok")).map_err(failure)?; + if mechanism.is_empty() { fail!("string was null for field mechanism") } + let (input, response) = domain_longstr(input).map_err(err("field response in method start-ok")).map_err(failure)?; + if response.is_empty() { fail!("string was null for field response") } + let (input, locale) = domain_shortstr(input).map_err(err("field locale in method start-ok")).map_err(failure)?; + if locale.is_empty() { fail!("string was null for field locale") } + Ok((input, Class::Connection(Connection::StartOk { + client_properties, + mechanism, + response, + locale, + }))) +} +fn connection_secure(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, challenge) = domain_longstr(input).map_err(err("field challenge in method secure")).map_err(failure)?; + Ok((input, Class::Connection(Connection::Secure { + challenge, + }))) +} +fn connection_secure_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, response) = domain_longstr(input).map_err(err("field response in method secure-ok")).map_err(failure)?; + if response.is_empty() { fail!("string was null for field response") } + Ok((input, Class::Connection(Connection::SecureOk { + response, + }))) +} +fn connection_tune(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, channel_max) = domain_short(input).map_err(err("field channel-max in method tune")).map_err(failure)?; + let (input, frame_max) = domain_long(input).map_err(err("field frame-max in method tune")).map_err(failure)?; + let (input, heartbeat) = domain_short(input).map_err(err("field heartbeat in method tune")).map_err(failure)?; + Ok((input, Class::Connection(Connection::Tune { + channel_max, + frame_max, + heartbeat, + }))) +} +fn connection_tune_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, channel_max) = domain_short(input).map_err(err("field channel-max in method tune-ok")).map_err(failure)?; + if channel_max == 0 { fail!("number was 0 for field channel_max") } + let (input, frame_max) = domain_long(input).map_err(err("field frame-max in method tune-ok")).map_err(failure)?; + let (input, heartbeat) = domain_short(input).map_err(err("field heartbeat in method tune-ok")).map_err(failure)?; + Ok((input, Class::Connection(Connection::TuneOk { + channel_max, + frame_max, + heartbeat, + }))) +} +fn connection_open(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, virtual_host) = domain_path(input).map_err(err("field virtual-host in method open")).map_err(failure)?; + let (input, reserved_1) = domain_shortstr(input).map_err(err("field reserved-1 in method open")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field reserved-2 in method open")).map_err(failure)?; + let reserved_2 = bits[0]; + Ok((input, Class::Connection(Connection::Open { + virtual_host, + reserved_1, + reserved_2, + }))) +} +fn connection_open_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(41_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_shortstr(input).map_err(err("field reserved-1 in method open-ok")).map_err(failure)?; + Ok((input, Class::Connection(Connection::OpenOk { + reserved_1, + }))) +} +fn connection_close(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reply_code) = domain_reply_code(input).map_err(err("field reply-code in method close")).map_err(failure)?; + let (input, reply_text) = domain_reply_text(input).map_err(err("field reply-text in method close")).map_err(failure)?; + let (input, class_id) = domain_class_id(input).map_err(err("field class-id in method close")).map_err(failure)?; + let (input, method_id) = domain_method_id(input).map_err(err("field method-id in method close")).map_err(failure)?; + Ok((input, Class::Connection(Connection::Close { + reply_code, + reply_text, + class_id, + method_id, + }))) +} +fn connection_close_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(51_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Connection(Connection::CloseOk { + }))) +} +fn channel(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("invalid tag for class channel"))?; + alt((channel_open, channel_open_ok, channel_flow, channel_flow_ok, channel_close, channel_close_ok))(input).map_err(err("class channel")).map_err(failure) +} +fn channel_open(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_shortstr(input).map_err(err("field reserved-1 in method open")).map_err(failure)?; + Ok((input, Class::Channel(Channel::Open { + reserved_1, + }))) +} +fn channel_open_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_longstr(input).map_err(err("field reserved-1 in method open-ok")).map_err(failure)?; + Ok((input, Class::Channel(Channel::OpenOk { + reserved_1, + }))) +} +fn channel_flow(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, bits) = bit(input, 1).map_err(err("field active in method flow")).map_err(failure)?; + let active = bits[0]; + Ok((input, Class::Channel(Channel::Flow { + active, + }))) +} +fn channel_flow_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, bits) = bit(input, 1).map_err(err("field active in method flow-ok")).map_err(failure)?; + let active = bits[0]; + Ok((input, Class::Channel(Channel::FlowOk { + active, + }))) +} +fn channel_close(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reply_code) = domain_reply_code(input).map_err(err("field reply-code in method close")).map_err(failure)?; + let (input, reply_text) = domain_reply_text(input).map_err(err("field reply-text in method close")).map_err(failure)?; + let (input, class_id) = domain_class_id(input).map_err(err("field class-id in method close")).map_err(failure)?; + let (input, method_id) = domain_method_id(input).map_err(err("field method-id in method close")).map_err(failure)?; + Ok((input, Class::Channel(Channel::Close { + reply_code, + reply_text, + class_id, + method_id, + }))) +} +fn channel_close_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(41_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Channel(Channel::CloseOk { + }))) +} +fn exchange(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("invalid tag for class exchange"))?; + alt((exchange_declare, exchange_declare_ok, exchange_delete, exchange_delete_ok))(input).map_err(err("class exchange")).map_err(failure) +} +fn exchange_declare(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method declare")).map_err(failure)?; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method declare")).map_err(failure)?; + if exchange.is_empty() { fail!("string was null for field exchange") } + let (input, r#type) = domain_shortstr(input).map_err(err("field type in method declare")).map_err(failure)?; + let (input, bits) = bit(input, 5).map_err(err("field passive in method declare")).map_err(failure)?; + let passive = bits[0]; + let durable = bits[1]; + let reserved_2 = bits[2]; + let reserved_3 = bits[3]; + let no_wait = bits[4]; + let (input, arguments) = domain_table(input).map_err(err("field arguments in method declare")).map_err(failure)?; + Ok((input, Class::Exchange(Exchange::Declare { + reserved_1, + exchange, + r#type, + passive, + durable, + reserved_2, + reserved_3, + no_wait, + arguments, + }))) +} +fn exchange_declare_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Exchange(Exchange::DeclareOk { + }))) +} +fn exchange_delete(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method delete")).map_err(failure)?; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method delete")).map_err(failure)?; + if exchange.is_empty() { fail!("string was null for field exchange") } + let (input, bits) = bit(input, 2).map_err(err("field if-unused in method delete")).map_err(failure)?; + let if_unused = bits[0]; + let no_wait = bits[1]; + Ok((input, Class::Exchange(Exchange::Delete { + reserved_1, + exchange, + if_unused, + no_wait, + }))) +} +fn exchange_delete_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Exchange(Exchange::DeleteOk { + }))) +} +fn queue(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("invalid tag for class queue"))?; + alt((queue_declare, queue_declare_ok, queue_bind, queue_bind_ok, queue_unbind, queue_unbind_ok, queue_purge, queue_purge_ok, queue_delete, queue_delete_ok))(input).map_err(err("class queue")).map_err(failure) +} +fn queue_declare(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method declare")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method declare")).map_err(failure)?; + let (input, bits) = bit(input, 5).map_err(err("field passive in method declare")).map_err(failure)?; + let passive = bits[0]; + let durable = bits[1]; + let exclusive = bits[2]; + let auto_delete = bits[3]; + let no_wait = bits[4]; + let (input, arguments) = domain_table(input).map_err(err("field arguments in method declare")).map_err(failure)?; + Ok((input, Class::Queue(Queue::Declare { + reserved_1, + queue, + passive, + durable, + exclusive, + auto_delete, + no_wait, + arguments, + }))) +} +fn queue_declare_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method declare-ok")).map_err(failure)?; + if queue.is_empty() { fail!("string was null for field queue") } + let (input, message_count) = domain_message_count(input).map_err(err("field message-count in method declare-ok")).map_err(failure)?; + let (input, consumer_count) = domain_long(input).map_err(err("field consumer-count in method declare-ok")).map_err(failure)?; + Ok((input, Class::Queue(Queue::DeclareOk { + queue, + message_count, + consumer_count, + }))) +} +fn queue_bind(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method bind")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method bind")).map_err(failure)?; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method bind")).map_err(failure)?; + let (input, routing_key) = domain_shortstr(input).map_err(err("field routing-key in method bind")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field no-wait in method bind")).map_err(failure)?; + let no_wait = bits[0]; + let (input, arguments) = domain_table(input).map_err(err("field arguments in method bind")).map_err(failure)?; + Ok((input, Class::Queue(Queue::Bind { + reserved_1, + queue, + exchange, + routing_key, + no_wait, + arguments, + }))) +} +fn queue_bind_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Queue(Queue::BindOk { + }))) +} +fn queue_unbind(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method unbind")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method unbind")).map_err(failure)?; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method unbind")).map_err(failure)?; + let (input, routing_key) = domain_shortstr(input).map_err(err("field routing-key in method unbind")).map_err(failure)?; + let (input, arguments) = domain_table(input).map_err(err("field arguments in method unbind")).map_err(failure)?; + Ok((input, Class::Queue(Queue::Unbind { + reserved_1, + queue, + exchange, + routing_key, + arguments, + }))) +} +fn queue_unbind_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(51_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Queue(Queue::UnbindOk { + }))) +} +fn queue_purge(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method purge")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method purge")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field no-wait in method purge")).map_err(failure)?; + let no_wait = bits[0]; + Ok((input, Class::Queue(Queue::Purge { + reserved_1, + queue, + no_wait, + }))) +} +fn queue_purge_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, message_count) = domain_message_count(input).map_err(err("field message-count in method purge-ok")).map_err(failure)?; + Ok((input, Class::Queue(Queue::PurgeOk { + message_count, + }))) +} +fn queue_delete(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method delete")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method delete")).map_err(failure)?; + let (input, bits) = bit(input, 3).map_err(err("field if-unused in method delete")).map_err(failure)?; + let if_unused = bits[0]; + let if_empty = bits[1]; + let no_wait = bits[2]; + Ok((input, Class::Queue(Queue::Delete { + reserved_1, + queue, + if_unused, + if_empty, + no_wait, + }))) +} +fn queue_delete_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(41_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, message_count) = domain_message_count(input).map_err(err("field message-count in method delete-ok")).map_err(failure)?; + Ok((input, Class::Queue(Queue::DeleteOk { + message_count, + }))) +} +fn basic(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(60_u16.to_be_bytes())(input).map_err(err("invalid tag for class basic"))?; + alt((basic_qos, basic_qos_ok, basic_consume, basic_consume_ok, basic_cancel, basic_cancel_ok, basic_publish, basic_return, basic_deliver, basic_get, basic_get_ok, basic_get_empty, basic_ack, basic_reject, basic_recover_async, basic_recover, basic_recover_ok))(input).map_err(err("class basic")).map_err(failure) +} +fn basic_qos(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, prefetch_size) = domain_long(input).map_err(err("field prefetch-size in method qos")).map_err(failure)?; + let (input, prefetch_count) = domain_short(input).map_err(err("field prefetch-count in method qos")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field global in method qos")).map_err(failure)?; + let global = bits[0]; + Ok((input, Class::Basic(Basic::Qos { + prefetch_size, + prefetch_count, + global, + }))) +} +fn basic_qos_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Basic(Basic::QosOk { + }))) +} +fn basic_consume(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method consume")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method consume")).map_err(failure)?; + let (input, consumer_tag) = domain_consumer_tag(input).map_err(err("field consumer-tag in method consume")).map_err(failure)?; + let (input, bits) = bit(input, 4).map_err(err("field no-local in method consume")).map_err(failure)?; + let no_local = bits[0]; + let no_ack = bits[1]; + let exclusive = bits[2]; + let no_wait = bits[3]; + let (input, arguments) = domain_table(input).map_err(err("field arguments in method consume")).map_err(failure)?; + Ok((input, Class::Basic(Basic::Consume { + reserved_1, + queue, + consumer_tag, + no_local, + no_ack, + exclusive, + no_wait, + arguments, + }))) +} +fn basic_consume_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, consumer_tag) = domain_consumer_tag(input).map_err(err("field consumer-tag in method consume-ok")).map_err(failure)?; + Ok((input, Class::Basic(Basic::ConsumeOk { + consumer_tag, + }))) +} +fn basic_cancel(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, consumer_tag) = domain_consumer_tag(input).map_err(err("field consumer-tag in method cancel")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field no-wait in method cancel")).map_err(failure)?; + let no_wait = bits[0]; + Ok((input, Class::Basic(Basic::Cancel { + consumer_tag, + no_wait, + }))) +} +fn basic_cancel_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, consumer_tag) = domain_consumer_tag(input).map_err(err("field consumer-tag in method cancel-ok")).map_err(failure)?; + Ok((input, Class::Basic(Basic::CancelOk { + consumer_tag, + }))) +} +fn basic_publish(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method publish")).map_err(failure)?; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method publish")).map_err(failure)?; + let (input, routing_key) = domain_shortstr(input).map_err(err("field routing-key in method publish")).map_err(failure)?; + let (input, bits) = bit(input, 2).map_err(err("field mandatory in method publish")).map_err(failure)?; + let mandatory = bits[0]; + let immediate = bits[1]; + Ok((input, Class::Basic(Basic::Publish { + reserved_1, + exchange, + routing_key, + mandatory, + immediate, + }))) +} +fn basic_return(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reply_code) = domain_reply_code(input).map_err(err("field reply-code in method return")).map_err(failure)?; + let (input, reply_text) = domain_reply_text(input).map_err(err("field reply-text in method return")).map_err(failure)?; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method return")).map_err(failure)?; + let (input, routing_key) = domain_shortstr(input).map_err(err("field routing-key in method return")).map_err(failure)?; + Ok((input, Class::Basic(Basic::Return { + reply_code, + reply_text, + exchange, + routing_key, + }))) +} +fn basic_deliver(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(60_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, consumer_tag) = domain_consumer_tag(input).map_err(err("field consumer-tag in method deliver")).map_err(failure)?; + let (input, delivery_tag) = domain_delivery_tag(input).map_err(err("field delivery-tag in method deliver")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field redelivered in method deliver")).map_err(failure)?; + let redelivered = bits[0]; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method deliver")).map_err(failure)?; + let (input, routing_key) = domain_shortstr(input).map_err(err("field routing-key in method deliver")).map_err(failure)?; + Ok((input, Class::Basic(Basic::Deliver { + consumer_tag, + delivery_tag, + redelivered, + exchange, + routing_key, + }))) +} +fn basic_get(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(70_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_short(input).map_err(err("field reserved-1 in method get")).map_err(failure)?; + let (input, queue) = domain_queue_name(input).map_err(err("field queue in method get")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field no-ack in method get")).map_err(failure)?; + let no_ack = bits[0]; + Ok((input, Class::Basic(Basic::Get { + reserved_1, + queue, + no_ack, + }))) +} +fn basic_get_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(71_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, delivery_tag) = domain_delivery_tag(input).map_err(err("field delivery-tag in method get-ok")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field redelivered in method get-ok")).map_err(failure)?; + let redelivered = bits[0]; + let (input, exchange) = domain_exchange_name(input).map_err(err("field exchange in method get-ok")).map_err(failure)?; + let (input, routing_key) = domain_shortstr(input).map_err(err("field routing-key in method get-ok")).map_err(failure)?; + let (input, message_count) = domain_message_count(input).map_err(err("field message-count in method get-ok")).map_err(failure)?; + Ok((input, Class::Basic(Basic::GetOk { + delivery_tag, + redelivered, + exchange, + routing_key, + message_count, + }))) +} +fn basic_get_empty(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(72_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, reserved_1) = domain_shortstr(input).map_err(err("field reserved-1 in method get-empty")).map_err(failure)?; + Ok((input, Class::Basic(Basic::GetEmpty { + reserved_1, + }))) +} +fn basic_ack(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(80_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, delivery_tag) = domain_delivery_tag(input).map_err(err("field delivery-tag in method ack")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field multiple in method ack")).map_err(failure)?; + let multiple = bits[0]; + Ok((input, Class::Basic(Basic::Ack { + delivery_tag, + multiple, + }))) +} +fn basic_reject(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(90_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, delivery_tag) = domain_delivery_tag(input).map_err(err("field delivery-tag in method reject")).map_err(failure)?; + let (input, bits) = bit(input, 1).map_err(err("field requeue in method reject")).map_err(failure)?; + let requeue = bits[0]; + Ok((input, Class::Basic(Basic::Reject { + delivery_tag, + requeue, + }))) +} +fn basic_recover_async(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(100_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, bits) = bit(input, 1).map_err(err("field requeue in method recover-async")).map_err(failure)?; + let requeue = bits[0]; + Ok((input, Class::Basic(Basic::RecoverAsync { + requeue, + }))) +} +fn basic_recover(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(110_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + let (input, bits) = bit(input, 1).map_err(err("field requeue in method recover")).map_err(failure)?; + let requeue = bits[0]; + Ok((input, Class::Basic(Basic::Recover { + requeue, + }))) +} +fn basic_recover_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(111_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Basic(Basic::RecoverOk { + }))) +} +fn tx(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(90_u16.to_be_bytes())(input).map_err(err("invalid tag for class tx"))?; + alt((tx_select, tx_select_ok, tx_commit, tx_commit_ok, tx_rollback, tx_rollback_ok))(input).map_err(err("class tx")).map_err(failure) +} +fn tx_select(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Tx(Tx::Select { + }))) +} +fn tx_select_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Tx(Tx::SelectOk { + }))) +} +fn tx_commit(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Tx(Tx::Commit { + }))) +} +fn tx_commit_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Tx(Tx::CommitOk { + }))) +} +fn tx_rollback(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Tx(Tx::Rollback { + }))) +} +fn tx_rollback_ok(input: &[u8]) -> IResult<'_, Class> { + let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; + Ok((input, Class::Tx(Tx::RollbackOk { + }))) +} - pub fn parse_method(input: &[u8]) -> Result<(&[u8], Class), nom::Err> { - alt((connection, channel, exchange, queue, basic, tx))(input) - } - fn domain_class_id(input: &[u8]) -> IResult { - short(input) - } - fn domain_consumer_tag(input: &[u8]) -> IResult { - shortstr(input) - } - fn domain_delivery_tag(input: &[u8]) -> IResult { - longlong(input) - } - fn domain_exchange_name(input: &[u8]) -> IResult { - let (input, result) = shortstr(input)?; - if result.len() > 127 { - fail!("value is shorter than 127 for field result") - } - static REGEX: Lazy = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9-_.:]*$").unwrap()); - if !REGEX.is_match(&result) { - fail!(r"regex `^[a-zA-Z0-9-_.:]*$` did not match value for field result") - } - Ok((input, result)) - } - fn domain_method_id(input: &[u8]) -> IResult { - short(input) - } - fn domain_path(input: &[u8]) -> IResult { - let (input, result) = shortstr(input)?; - if result.is_empty() { - fail!("string was null for field result") - } - if result.len() > 127 { - fail!("value is shorter than 127 for field result") - } - Ok((input, result)) - } - fn domain_peer_properties(input: &[u8]) -> IResult { - table(input) - } - fn domain_queue_name(input: &[u8]) -> IResult { - let (input, result) = shortstr(input)?; - if result.len() > 127 { - fail!("value is shorter than 127 for field result") - } - static REGEX: Lazy = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9-_.:]*$").unwrap()); - if !REGEX.is_match(&result) { - fail!(r"regex `^[a-zA-Z0-9-_.:]*$` did not match value for field result") - } - Ok((input, result)) - } - fn domain_message_count(input: &[u8]) -> IResult { - long(input) - } - fn domain_reply_code(input: &[u8]) -> IResult { - let (input, result) = short(input)?; - if result == 0 { - fail!("number was 0 for field result") - } - Ok((input, result)) - } - fn domain_reply_text(input: &[u8]) -> IResult { - let (input, result) = shortstr(input)?; - if result.is_empty() { - fail!("string was null for field result") - } - Ok((input, result)) - } - fn domain_octet(input: &[u8]) -> IResult { - octet(input) - } - fn domain_short(input: &[u8]) -> IResult { - short(input) - } - fn domain_long(input: &[u8]) -> IResult { - long(input) - } - fn domain_longlong(input: &[u8]) -> IResult { - longlong(input) - } - fn domain_shortstr(input: &[u8]) -> IResult { - shortstr(input) - } - fn domain_longstr(input: &[u8]) -> IResult { - longstr(input) - } - fn domain_timestamp(input: &[u8]) -> IResult { - timestamp(input) - } - fn domain_table(input: &[u8]) -> IResult { - table(input) - } - fn connection(input: &[u8]) -> IResult { - let (input, _) = - tag(10_u16.to_be_bytes())(input).map_err(err("invalid tag for class connection"))?; - alt(( - connection_start, - connection_start_ok, - connection_secure, - connection_secure_ok, - connection_tune, - connection_tune_ok, - connection_open, - connection_open_ok, - connection_close, - connection_close_ok, - ))(input) - .map_err(err("class connection")) - .map_err(failure) - } - fn connection_start(input: &[u8]) -> IResult { - let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, version_major) = domain_octet(input) - .map_err(err("field version-major in method start")) - .map_err(failure)?; - let (input, version_minor) = domain_octet(input) - .map_err(err("field version-minor in method start")) - .map_err(failure)?; - let (input, server_properties) = domain_peer_properties(input) - .map_err(err("field server-properties in method start")) - .map_err(failure)?; - let (input, mechanisms) = domain_longstr(input) - .map_err(err("field mechanisms in method start")) - .map_err(failure)?; - if mechanisms.is_empty() { - fail!("string was null for field mechanisms") - } - let (input, locales) = domain_longstr(input) - .map_err(err("field locales in method start")) - .map_err(failure)?; - if locales.is_empty() { - fail!("string was null for field locales") - } - Ok(( - input, - Class::Connection(Connection::Start { - version_major, - version_minor, - server_properties, - mechanisms, - locales, - }), - )) - } - fn connection_start_ok(input: &[u8]) -> IResult { - let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, client_properties) = domain_peer_properties(input) - .map_err(err("field client-properties in method start-ok")) - .map_err(failure)?; - let (input, mechanism) = domain_shortstr(input) - .map_err(err("field mechanism in method start-ok")) - .map_err(failure)?; - if mechanism.is_empty() { - fail!("string was null for field mechanism") - } - let (input, response) = domain_longstr(input) - .map_err(err("field response in method start-ok")) - .map_err(failure)?; - if response.is_empty() { - fail!("string was null for field response") - } - let (input, locale) = domain_shortstr(input) - .map_err(err("field locale in method start-ok")) - .map_err(failure)?; - if locale.is_empty() { - fail!("string was null for field locale") - } - Ok(( - input, - Class::Connection(Connection::StartOk { - client_properties, - mechanism, - response, - locale, - }), - )) - } - fn connection_secure(input: &[u8]) -> IResult { - let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, challenge) = domain_longstr(input) - .map_err(err("field challenge in method secure")) - .map_err(failure)?; - Ok((input, Class::Connection(Connection::Secure { challenge }))) - } - fn connection_secure_ok(input: &[u8]) -> IResult { - let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, response) = domain_longstr(input) - .map_err(err("field response in method secure-ok")) - .map_err(failure)?; - if response.is_empty() { - fail!("string was null for field response") - } - Ok((input, Class::Connection(Connection::SecureOk { response }))) - } - fn connection_tune(input: &[u8]) -> IResult { - let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, channel_max) = domain_short(input) - .map_err(err("field channel-max in method tune")) - .map_err(failure)?; - let (input, frame_max) = domain_long(input) - .map_err(err("field frame-max in method tune")) - .map_err(failure)?; - let (input, heartbeat) = domain_short(input) - .map_err(err("field heartbeat in method tune")) - .map_err(failure)?; - Ok(( - input, - Class::Connection(Connection::Tune { - channel_max, - frame_max, - heartbeat, - }), - )) - } - fn connection_tune_ok(input: &[u8]) -> IResult { - let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, channel_max) = domain_short(input) - .map_err(err("field channel-max in method tune-ok")) - .map_err(failure)?; - if channel_max == 0 { - fail!("number was 0 for field channel_max") - } - let (input, frame_max) = domain_long(input) - .map_err(err("field frame-max in method tune-ok")) - .map_err(failure)?; - let (input, heartbeat) = domain_short(input) - .map_err(err("field heartbeat in method tune-ok")) - .map_err(failure)?; - Ok(( - input, - Class::Connection(Connection::TuneOk { - channel_max, - frame_max, - heartbeat, - }), - )) - } - fn connection_open(input: &[u8]) -> IResult { - let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, virtual_host) = domain_path(input) - .map_err(err("field virtual-host in method open")) - .map_err(failure)?; - let (input, reserved_1) = domain_shortstr(input) - .map_err(err("field reserved-1 in method open")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field reserved-2 in method open")) - .map_err(failure)?; - let reserved_2 = bits[0]; - Ok(( - input, - Class::Connection(Connection::Open { - virtual_host, - reserved_1, - reserved_2, - }), - )) - } - fn connection_open_ok(input: &[u8]) -> IResult { - let (input, _) = tag(41_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_shortstr(input) - .map_err(err("field reserved-1 in method open-ok")) - .map_err(failure)?; - Ok((input, Class::Connection(Connection::OpenOk { reserved_1 }))) - } - fn connection_close(input: &[u8]) -> IResult { - let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reply_code) = domain_reply_code(input) - .map_err(err("field reply-code in method close")) - .map_err(failure)?; - let (input, reply_text) = domain_reply_text(input) - .map_err(err("field reply-text in method close")) - .map_err(failure)?; - let (input, class_id) = domain_class_id(input) - .map_err(err("field class-id in method close")) - .map_err(failure)?; - let (input, method_id) = domain_method_id(input) - .map_err(err("field method-id in method close")) - .map_err(failure)?; - Ok(( - input, - Class::Connection(Connection::Close { - reply_code, - reply_text, - class_id, - method_id, - }), - )) - } - fn connection_close_ok(input: &[u8]) -> IResult { - let (input, _) = tag(51_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Connection(Connection::CloseOk {}))) - } - fn channel(input: &[u8]) -> IResult { - let (input, _) = - tag(20_u16.to_be_bytes())(input).map_err(err("invalid tag for class channel"))?; - alt(( - channel_open, - channel_open_ok, - channel_flow, - channel_flow_ok, - channel_close, - channel_close_ok, - ))(input) - .map_err(err("class channel")) - .map_err(failure) - } - fn channel_open(input: &[u8]) -> IResult { - let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_shortstr(input) - .map_err(err("field reserved-1 in method open")) - .map_err(failure)?; - Ok((input, Class::Channel(Channel::Open { reserved_1 }))) - } - fn channel_open_ok(input: &[u8]) -> IResult { - let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_longstr(input) - .map_err(err("field reserved-1 in method open-ok")) - .map_err(failure)?; - Ok((input, Class::Channel(Channel::OpenOk { reserved_1 }))) - } - fn channel_flow(input: &[u8]) -> IResult { - let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, bits) = bit(input, 1) - .map_err(err("field active in method flow")) - .map_err(failure)?; - let active = bits[0]; - Ok((input, Class::Channel(Channel::Flow { active }))) - } - fn channel_flow_ok(input: &[u8]) -> IResult { - let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, bits) = bit(input, 1) - .map_err(err("field active in method flow-ok")) - .map_err(failure)?; - let active = bits[0]; - Ok((input, Class::Channel(Channel::FlowOk { active }))) - } - fn channel_close(input: &[u8]) -> IResult { - let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reply_code) = domain_reply_code(input) - .map_err(err("field reply-code in method close")) - .map_err(failure)?; - let (input, reply_text) = domain_reply_text(input) - .map_err(err("field reply-text in method close")) - .map_err(failure)?; - let (input, class_id) = domain_class_id(input) - .map_err(err("field class-id in method close")) - .map_err(failure)?; - let (input, method_id) = domain_method_id(input) - .map_err(err("field method-id in method close")) - .map_err(failure)?; - Ok(( - input, - Class::Channel(Channel::Close { - reply_code, - reply_text, - class_id, - method_id, - }), - )) - } - fn channel_close_ok(input: &[u8]) -> IResult { - let (input, _) = tag(41_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Channel(Channel::CloseOk {}))) - } - fn exchange(input: &[u8]) -> IResult { - let (input, _) = - tag(40_u16.to_be_bytes())(input).map_err(err("invalid tag for class exchange"))?; - alt(( - exchange_declare, - exchange_declare_ok, - exchange_delete, - exchange_delete_ok, - ))(input) - .map_err(err("class exchange")) - .map_err(failure) - } - fn exchange_declare(input: &[u8]) -> IResult { - let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method declare")) - .map_err(failure)?; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method declare")) - .map_err(failure)?; - if exchange.is_empty() { - fail!("string was null for field exchange") - } - let (input, r#type) = domain_shortstr(input) - .map_err(err("field type in method declare")) - .map_err(failure)?; - let (input, bits) = bit(input, 5) - .map_err(err("field passive in method declare")) - .map_err(failure)?; - let passive = bits[0]; - let durable = bits[1]; - let reserved_2 = bits[2]; - let reserved_3 = bits[3]; - let no_wait = bits[4]; - let (input, arguments) = domain_table(input) - .map_err(err("field arguments in method declare")) - .map_err(failure)?; - Ok(( - input, - Class::Exchange(Exchange::Declare { - reserved_1, - exchange, - r#type, - passive, - durable, - reserved_2, - reserved_3, - no_wait, - arguments, - }), - )) - } - fn exchange_declare_ok(input: &[u8]) -> IResult { - let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Exchange(Exchange::DeclareOk {}))) - } - fn exchange_delete(input: &[u8]) -> IResult { - let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method delete")) - .map_err(failure)?; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method delete")) - .map_err(failure)?; - if exchange.is_empty() { - fail!("string was null for field exchange") - } - let (input, bits) = bit(input, 2) - .map_err(err("field if-unused in method delete")) - .map_err(failure)?; - let if_unused = bits[0]; - let no_wait = bits[1]; - Ok(( - input, - Class::Exchange(Exchange::Delete { - reserved_1, - exchange, - if_unused, - no_wait, - }), - )) - } - fn exchange_delete_ok(input: &[u8]) -> IResult { - let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Exchange(Exchange::DeleteOk {}))) - } - fn queue(input: &[u8]) -> IResult { - let (input, _) = - tag(50_u16.to_be_bytes())(input).map_err(err("invalid tag for class queue"))?; - alt(( - queue_declare, - queue_declare_ok, - queue_bind, - queue_bind_ok, - queue_unbind, - queue_unbind_ok, - queue_purge, - queue_purge_ok, - queue_delete, - queue_delete_ok, - ))(input) - .map_err(err("class queue")) - .map_err(failure) - } - fn queue_declare(input: &[u8]) -> IResult { - let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method declare")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method declare")) - .map_err(failure)?; - let (input, bits) = bit(input, 5) - .map_err(err("field passive in method declare")) - .map_err(failure)?; - let passive = bits[0]; - let durable = bits[1]; - let exclusive = bits[2]; - let auto_delete = bits[3]; - let no_wait = bits[4]; - let (input, arguments) = domain_table(input) - .map_err(err("field arguments in method declare")) - .map_err(failure)?; - Ok(( - input, - Class::Queue(Queue::Declare { - reserved_1, - queue, - passive, - durable, - exclusive, - auto_delete, - no_wait, - arguments, - }), - )) - } - fn queue_declare_ok(input: &[u8]) -> IResult { - let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method declare-ok")) - .map_err(failure)?; - if queue.is_empty() { - fail!("string was null for field queue") - } - let (input, message_count) = domain_message_count(input) - .map_err(err("field message-count in method declare-ok")) - .map_err(failure)?; - let (input, consumer_count) = domain_long(input) - .map_err(err("field consumer-count in method declare-ok")) - .map_err(failure)?; - Ok(( - input, - Class::Queue(Queue::DeclareOk { - queue, - message_count, - consumer_count, - }), - )) - } - fn queue_bind(input: &[u8]) -> IResult { - let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method bind")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method bind")) - .map_err(failure)?; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method bind")) - .map_err(failure)?; - let (input, routing_key) = domain_shortstr(input) - .map_err(err("field routing-key in method bind")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field no-wait in method bind")) - .map_err(failure)?; - let no_wait = bits[0]; - let (input, arguments) = domain_table(input) - .map_err(err("field arguments in method bind")) - .map_err(failure)?; - Ok(( - input, - Class::Queue(Queue::Bind { - reserved_1, - queue, - exchange, - routing_key, - no_wait, - arguments, - }), - )) - } - fn queue_bind_ok(input: &[u8]) -> IResult { - let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Queue(Queue::BindOk {}))) - } - fn queue_unbind(input: &[u8]) -> IResult { - let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method unbind")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method unbind")) - .map_err(failure)?; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method unbind")) - .map_err(failure)?; - let (input, routing_key) = domain_shortstr(input) - .map_err(err("field routing-key in method unbind")) - .map_err(failure)?; - let (input, arguments) = domain_table(input) - .map_err(err("field arguments in method unbind")) - .map_err(failure)?; - Ok(( - input, - Class::Queue(Queue::Unbind { - reserved_1, - queue, - exchange, - routing_key, - arguments, - }), - )) - } - fn queue_unbind_ok(input: &[u8]) -> IResult { - let (input, _) = tag(51_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Queue(Queue::UnbindOk {}))) - } - fn queue_purge(input: &[u8]) -> IResult { - let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method purge")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method purge")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field no-wait in method purge")) - .map_err(failure)?; - let no_wait = bits[0]; - Ok(( - input, - Class::Queue(Queue::Purge { - reserved_1, - queue, - no_wait, - }), - )) - } - fn queue_purge_ok(input: &[u8]) -> IResult { - let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, message_count) = domain_message_count(input) - .map_err(err("field message-count in method purge-ok")) - .map_err(failure)?; - Ok((input, Class::Queue(Queue::PurgeOk { message_count }))) - } - fn queue_delete(input: &[u8]) -> IResult { - let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method delete")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method delete")) - .map_err(failure)?; - let (input, bits) = bit(input, 3) - .map_err(err("field if-unused in method delete")) - .map_err(failure)?; - let if_unused = bits[0]; - let if_empty = bits[1]; - let no_wait = bits[2]; - Ok(( - input, - Class::Queue(Queue::Delete { - reserved_1, - queue, - if_unused, - if_empty, - no_wait, - }), - )) - } - fn queue_delete_ok(input: &[u8]) -> IResult { - let (input, _) = tag(41_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, message_count) = domain_message_count(input) - .map_err(err("field message-count in method delete-ok")) - .map_err(failure)?; - Ok((input, Class::Queue(Queue::DeleteOk { message_count }))) - } - fn basic(input: &[u8]) -> IResult { - let (input, _) = - tag(60_u16.to_be_bytes())(input).map_err(err("invalid tag for class basic"))?; - alt(( - basic_qos, - basic_qos_ok, - basic_consume, - basic_consume_ok, - basic_cancel, - basic_cancel_ok, - basic_publish, - basic_return, - basic_deliver, - basic_get, - basic_get_ok, - basic_get_empty, - basic_ack, - basic_reject, - basic_recover_async, - basic_recover, - basic_recover_ok, - ))(input) - .map_err(err("class basic")) - .map_err(failure) - } - fn basic_qos(input: &[u8]) -> IResult { - let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, prefetch_size) = domain_long(input) - .map_err(err("field prefetch-size in method qos")) - .map_err(failure)?; - let (input, prefetch_count) = domain_short(input) - .map_err(err("field prefetch-count in method qos")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field global in method qos")) - .map_err(failure)?; - let global = bits[0]; - Ok(( - input, - Class::Basic(Basic::Qos { - prefetch_size, - prefetch_count, - global, - }), - )) - } - fn basic_qos_ok(input: &[u8]) -> IResult { - let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Basic(Basic::QosOk {}))) - } - fn basic_consume(input: &[u8]) -> IResult { - let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method consume")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method consume")) - .map_err(failure)?; - let (input, consumer_tag) = domain_consumer_tag(input) - .map_err(err("field consumer-tag in method consume")) - .map_err(failure)?; - let (input, bits) = bit(input, 4) - .map_err(err("field no-local in method consume")) - .map_err(failure)?; - let no_local = bits[0]; - let no_ack = bits[1]; - let exclusive = bits[2]; - let no_wait = bits[3]; - let (input, arguments) = domain_table(input) - .map_err(err("field arguments in method consume")) - .map_err(failure)?; - Ok(( - input, - Class::Basic(Basic::Consume { - reserved_1, - queue, - consumer_tag, - no_local, - no_ack, - exclusive, - no_wait, - arguments, - }), - )) - } - fn basic_consume_ok(input: &[u8]) -> IResult { - let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, consumer_tag) = domain_consumer_tag(input) - .map_err(err("field consumer-tag in method consume-ok")) - .map_err(failure)?; - Ok((input, Class::Basic(Basic::ConsumeOk { consumer_tag }))) - } - fn basic_cancel(input: &[u8]) -> IResult { - let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, consumer_tag) = domain_consumer_tag(input) - .map_err(err("field consumer-tag in method cancel")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field no-wait in method cancel")) - .map_err(failure)?; - let no_wait = bits[0]; - Ok(( - input, - Class::Basic(Basic::Cancel { - consumer_tag, - no_wait, - }), - )) - } - fn basic_cancel_ok(input: &[u8]) -> IResult { - let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, consumer_tag) = domain_consumer_tag(input) - .map_err(err("field consumer-tag in method cancel-ok")) - .map_err(failure)?; - Ok((input, Class::Basic(Basic::CancelOk { consumer_tag }))) - } - fn basic_publish(input: &[u8]) -> IResult { - let (input, _) = tag(40_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method publish")) - .map_err(failure)?; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method publish")) - .map_err(failure)?; - let (input, routing_key) = domain_shortstr(input) - .map_err(err("field routing-key in method publish")) - .map_err(failure)?; - let (input, bits) = bit(input, 2) - .map_err(err("field mandatory in method publish")) - .map_err(failure)?; - let mandatory = bits[0]; - let immediate = bits[1]; - Ok(( - input, - Class::Basic(Basic::Publish { - reserved_1, - exchange, - routing_key, - mandatory, - immediate, - }), - )) - } - fn basic_return(input: &[u8]) -> IResult { - let (input, _) = tag(50_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reply_code) = domain_reply_code(input) - .map_err(err("field reply-code in method return")) - .map_err(failure)?; - let (input, reply_text) = domain_reply_text(input) - .map_err(err("field reply-text in method return")) - .map_err(failure)?; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method return")) - .map_err(failure)?; - let (input, routing_key) = domain_shortstr(input) - .map_err(err("field routing-key in method return")) - .map_err(failure)?; - Ok(( - input, - Class::Basic(Basic::Return { - reply_code, - reply_text, - exchange, - routing_key, - }), - )) - } - fn basic_deliver(input: &[u8]) -> IResult { - let (input, _) = tag(60_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, consumer_tag) = domain_consumer_tag(input) - .map_err(err("field consumer-tag in method deliver")) - .map_err(failure)?; - let (input, delivery_tag) = domain_delivery_tag(input) - .map_err(err("field delivery-tag in method deliver")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field redelivered in method deliver")) - .map_err(failure)?; - let redelivered = bits[0]; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method deliver")) - .map_err(failure)?; - let (input, routing_key) = domain_shortstr(input) - .map_err(err("field routing-key in method deliver")) - .map_err(failure)?; - Ok(( - input, - Class::Basic(Basic::Deliver { - consumer_tag, - delivery_tag, - redelivered, - exchange, - routing_key, - }), - )) - } - fn basic_get(input: &[u8]) -> IResult { - let (input, _) = tag(70_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_short(input) - .map_err(err("field reserved-1 in method get")) - .map_err(failure)?; - let (input, queue) = domain_queue_name(input) - .map_err(err("field queue in method get")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field no-ack in method get")) - .map_err(failure)?; - let no_ack = bits[0]; - Ok(( - input, - Class::Basic(Basic::Get { - reserved_1, - queue, - no_ack, - }), - )) - } - fn basic_get_ok(input: &[u8]) -> IResult { - let (input, _) = tag(71_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, delivery_tag) = domain_delivery_tag(input) - .map_err(err("field delivery-tag in method get-ok")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field redelivered in method get-ok")) - .map_err(failure)?; - let redelivered = bits[0]; - let (input, exchange) = domain_exchange_name(input) - .map_err(err("field exchange in method get-ok")) - .map_err(failure)?; - let (input, routing_key) = domain_shortstr(input) - .map_err(err("field routing-key in method get-ok")) - .map_err(failure)?; - let (input, message_count) = domain_message_count(input) - .map_err(err("field message-count in method get-ok")) - .map_err(failure)?; - Ok(( - input, - Class::Basic(Basic::GetOk { - delivery_tag, - redelivered, - exchange, - routing_key, - message_count, - }), - )) - } - fn basic_get_empty(input: &[u8]) -> IResult { - let (input, _) = tag(72_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, reserved_1) = domain_shortstr(input) - .map_err(err("field reserved-1 in method get-empty")) - .map_err(failure)?; - Ok((input, Class::Basic(Basic::GetEmpty { reserved_1 }))) - } - fn basic_ack(input: &[u8]) -> IResult { - let (input, _) = tag(80_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, delivery_tag) = domain_delivery_tag(input) - .map_err(err("field delivery-tag in method ack")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field multiple in method ack")) - .map_err(failure)?; - let multiple = bits[0]; - Ok(( - input, - Class::Basic(Basic::Ack { - delivery_tag, - multiple, - }), - )) - } - fn basic_reject(input: &[u8]) -> IResult { - let (input, _) = tag(90_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, delivery_tag) = domain_delivery_tag(input) - .map_err(err("field delivery-tag in method reject")) - .map_err(failure)?; - let (input, bits) = bit(input, 1) - .map_err(err("field requeue in method reject")) - .map_err(failure)?; - let requeue = bits[0]; - Ok(( - input, - Class::Basic(Basic::Reject { - delivery_tag, - requeue, - }), - )) - } - fn basic_recover_async(input: &[u8]) -> IResult { - let (input, _) = tag(100_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, bits) = bit(input, 1) - .map_err(err("field requeue in method recover-async")) - .map_err(failure)?; - let requeue = bits[0]; - Ok((input, Class::Basic(Basic::RecoverAsync { requeue }))) - } - fn basic_recover(input: &[u8]) -> IResult { - let (input, _) = tag(110_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - let (input, bits) = bit(input, 1) - .map_err(err("field requeue in method recover")) - .map_err(failure)?; - let requeue = bits[0]; - Ok((input, Class::Basic(Basic::Recover { requeue }))) - } - fn basic_recover_ok(input: &[u8]) -> IResult { - let (input, _) = tag(111_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Basic(Basic::RecoverOk {}))) - } - fn tx(input: &[u8]) -> IResult { - let (input, _) = - tag(90_u16.to_be_bytes())(input).map_err(err("invalid tag for class tx"))?; - alt(( - tx_select, - tx_select_ok, - tx_commit, - tx_commit_ok, - tx_rollback, - tx_rollback_ok, - ))(input) - .map_err(err("class tx")) - .map_err(failure) - } - fn tx_select(input: &[u8]) -> IResult { - let (input, _) = tag(10_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Tx(Tx::Select {}))) - } - fn tx_select_ok(input: &[u8]) -> IResult { - let (input, _) = tag(11_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Tx(Tx::SelectOk {}))) - } - fn tx_commit(input: &[u8]) -> IResult { - let (input, _) = tag(20_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Tx(Tx::Commit {}))) - } - fn tx_commit_ok(input: &[u8]) -> IResult { - let (input, _) = tag(21_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Tx(Tx::CommitOk {}))) - } - fn tx_rollback(input: &[u8]) -> IResult { - let (input, _) = tag(30_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Tx(Tx::Rollback {}))) - } - fn tx_rollback_ok(input: &[u8]) -> IResult { - let (input, _) = tag(31_u16.to_be_bytes())(input).map_err(err("parsing method index"))?; - Ok((input, Class::Tx(Tx::RollbackOk {}))) - } } pub mod write { - use super::*; - use crate::classes::write_helper::*; - use crate::error::TransError; - use std::io::Write; +use super::*; +use crate::classes::write_helper::*; +use crate::error::TransError; +use std::io::Write; - pub fn write_method(class: Class, mut writer: W) -> Result<(), TransError> { - match class { - Class::Connection(Connection::Start { - version_major, - version_minor, - server_properties, - mechanisms, - locales, - }) => { - writer.write_all(&[0, 10, 0, 10])?; - octet(version_major, &mut writer)?; - octet(version_minor, &mut writer)?; - table(server_properties, &mut writer)?; - longstr(mechanisms, &mut writer)?; - longstr(locales, &mut writer)?; - } - Class::Connection(Connection::StartOk { - client_properties, - mechanism, - response, - locale, - }) => { - writer.write_all(&[0, 10, 0, 11])?; - table(client_properties, &mut writer)?; - shortstr(mechanism, &mut writer)?; - longstr(response, &mut writer)?; - shortstr(locale, &mut writer)?; - } - Class::Connection(Connection::Secure { challenge }) => { - writer.write_all(&[0, 10, 0, 20])?; - longstr(challenge, &mut writer)?; - } - Class::Connection(Connection::SecureOk { response }) => { - writer.write_all(&[0, 10, 0, 21])?; - longstr(response, &mut writer)?; - } - Class::Connection(Connection::Tune { - channel_max, - frame_max, - heartbeat, - }) => { - writer.write_all(&[0, 10, 0, 30])?; - short(channel_max, &mut writer)?; - long(frame_max, &mut writer)?; - short(heartbeat, &mut writer)?; - } - Class::Connection(Connection::TuneOk { - channel_max, - frame_max, - heartbeat, - }) => { - writer.write_all(&[0, 10, 0, 31])?; - short(channel_max, &mut writer)?; - long(frame_max, &mut writer)?; - short(heartbeat, &mut writer)?; - } - Class::Connection(Connection::Open { - virtual_host, - reserved_1, - reserved_2, - }) => { - writer.write_all(&[0, 10, 0, 40])?; - shortstr(virtual_host, &mut writer)?; - shortstr(reserved_1, &mut writer)?; - bit(&[reserved_2], &mut writer)?; - } - Class::Connection(Connection::OpenOk { reserved_1 }) => { - writer.write_all(&[0, 10, 0, 41])?; - shortstr(reserved_1, &mut writer)?; - } - Class::Connection(Connection::Close { - reply_code, - reply_text, - class_id, - method_id, - }) => { - writer.write_all(&[0, 10, 0, 50])?; - short(reply_code, &mut writer)?; - shortstr(reply_text, &mut writer)?; - short(class_id, &mut writer)?; - short(method_id, &mut writer)?; - } - Class::Connection(Connection::CloseOk {}) => { - writer.write_all(&[0, 10, 0, 51])?; - } - Class::Channel(Channel::Open { reserved_1 }) => { - writer.write_all(&[0, 20, 0, 10])?; - shortstr(reserved_1, &mut writer)?; - } - Class::Channel(Channel::OpenOk { reserved_1 }) => { - writer.write_all(&[0, 20, 0, 11])?; - longstr(reserved_1, &mut writer)?; - } - Class::Channel(Channel::Flow { active }) => { - writer.write_all(&[0, 20, 0, 20])?; - bit(&[active], &mut writer)?; - } - Class::Channel(Channel::FlowOk { active }) => { - writer.write_all(&[0, 20, 0, 21])?; - bit(&[active], &mut writer)?; - } - Class::Channel(Channel::Close { - reply_code, - reply_text, - class_id, - method_id, - }) => { - writer.write_all(&[0, 20, 0, 40])?; - short(reply_code, &mut writer)?; - shortstr(reply_text, &mut writer)?; - short(class_id, &mut writer)?; - short(method_id, &mut writer)?; - } - Class::Channel(Channel::CloseOk {}) => { - writer.write_all(&[0, 20, 0, 41])?; - } - Class::Exchange(Exchange::Declare { - reserved_1, - exchange, - r#type, - passive, - durable, - reserved_2, - reserved_3, - no_wait, - arguments, - }) => { - writer.write_all(&[0, 40, 0, 10])?; - short(reserved_1, &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(r#type, &mut writer)?; - bit( - &[passive, durable, reserved_2, reserved_3, no_wait], - &mut writer, - )?; - table(arguments, &mut writer)?; - } - Class::Exchange(Exchange::DeclareOk {}) => { - writer.write_all(&[0, 40, 0, 11])?; - } - Class::Exchange(Exchange::Delete { - reserved_1, - exchange, - if_unused, - no_wait, - }) => { - writer.write_all(&[0, 40, 0, 20])?; - short(reserved_1, &mut writer)?; - shortstr(exchange, &mut writer)?; - bit(&[if_unused, no_wait], &mut writer)?; - } - Class::Exchange(Exchange::DeleteOk {}) => { - writer.write_all(&[0, 40, 0, 21])?; - } - Class::Queue(Queue::Declare { - reserved_1, - queue, - passive, - durable, - exclusive, - auto_delete, - no_wait, - arguments, - }) => { - writer.write_all(&[0, 50, 0, 10])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - bit( - &[passive, durable, exclusive, auto_delete, no_wait], - &mut writer, - )?; - table(arguments, &mut writer)?; - } - Class::Queue(Queue::DeclareOk { - queue, - message_count, - consumer_count, - }) => { - writer.write_all(&[0, 50, 0, 11])?; - shortstr(queue, &mut writer)?; - long(message_count, &mut writer)?; - long(consumer_count, &mut writer)?; - } - Class::Queue(Queue::Bind { - reserved_1, - queue, - exchange, - routing_key, - no_wait, - arguments, - }) => { - writer.write_all(&[0, 50, 0, 20])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(routing_key, &mut writer)?; - bit(&[no_wait], &mut writer)?; - table(arguments, &mut writer)?; - } - Class::Queue(Queue::BindOk {}) => { - writer.write_all(&[0, 50, 0, 21])?; - } - Class::Queue(Queue::Unbind { - reserved_1, - queue, - exchange, - routing_key, - arguments, - }) => { - writer.write_all(&[0, 50, 0, 50])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(routing_key, &mut writer)?; - table(arguments, &mut writer)?; - } - Class::Queue(Queue::UnbindOk {}) => { - writer.write_all(&[0, 50, 0, 51])?; - } - Class::Queue(Queue::Purge { - reserved_1, - queue, - no_wait, - }) => { - writer.write_all(&[0, 50, 0, 30])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - bit(&[no_wait], &mut writer)?; - } - Class::Queue(Queue::PurgeOk { message_count }) => { - writer.write_all(&[0, 50, 0, 31])?; - long(message_count, &mut writer)?; - } - Class::Queue(Queue::Delete { - reserved_1, - queue, - if_unused, - if_empty, - no_wait, - }) => { - writer.write_all(&[0, 50, 0, 40])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - bit(&[if_unused, if_empty, no_wait], &mut writer)?; - } - Class::Queue(Queue::DeleteOk { message_count }) => { - writer.write_all(&[0, 50, 0, 41])?; - long(message_count, &mut writer)?; - } - Class::Basic(Basic::Qos { - prefetch_size, - prefetch_count, - global, - }) => { - writer.write_all(&[0, 60, 0, 10])?; - long(prefetch_size, &mut writer)?; - short(prefetch_count, &mut writer)?; - bit(&[global], &mut writer)?; - } - Class::Basic(Basic::QosOk {}) => { - writer.write_all(&[0, 60, 0, 11])?; - } - Class::Basic(Basic::Consume { - reserved_1, - queue, - consumer_tag, - no_local, - no_ack, - exclusive, - no_wait, - arguments, - }) => { - writer.write_all(&[0, 60, 0, 20])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - shortstr(consumer_tag, &mut writer)?; - bit(&[no_local, no_ack, exclusive, no_wait], &mut writer)?; - table(arguments, &mut writer)?; - } - Class::Basic(Basic::ConsumeOk { consumer_tag }) => { - writer.write_all(&[0, 60, 0, 21])?; - shortstr(consumer_tag, &mut writer)?; - } - Class::Basic(Basic::Cancel { - consumer_tag, - no_wait, - }) => { - writer.write_all(&[0, 60, 0, 30])?; - shortstr(consumer_tag, &mut writer)?; - bit(&[no_wait], &mut writer)?; - } - Class::Basic(Basic::CancelOk { consumer_tag }) => { - writer.write_all(&[0, 60, 0, 31])?; - shortstr(consumer_tag, &mut writer)?; - } - Class::Basic(Basic::Publish { - reserved_1, - exchange, - routing_key, - mandatory, - immediate, - }) => { - writer.write_all(&[0, 60, 0, 40])?; - short(reserved_1, &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(routing_key, &mut writer)?; - bit(&[mandatory, immediate], &mut writer)?; - } - Class::Basic(Basic::Return { - reply_code, - reply_text, - exchange, - routing_key, - }) => { - writer.write_all(&[0, 60, 0, 50])?; - short(reply_code, &mut writer)?; - shortstr(reply_text, &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(routing_key, &mut writer)?; - } - Class::Basic(Basic::Deliver { - consumer_tag, - delivery_tag, - redelivered, - exchange, - routing_key, - }) => { - writer.write_all(&[0, 60, 0, 60])?; - shortstr(consumer_tag, &mut writer)?; - longlong(delivery_tag, &mut writer)?; - bit(&[redelivered], &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(routing_key, &mut writer)?; - } - Class::Basic(Basic::Get { - reserved_1, - queue, - no_ack, - }) => { - writer.write_all(&[0, 60, 0, 70])?; - short(reserved_1, &mut writer)?; - shortstr(queue, &mut writer)?; - bit(&[no_ack], &mut writer)?; - } - Class::Basic(Basic::GetOk { - delivery_tag, - redelivered, - exchange, - routing_key, - message_count, - }) => { - writer.write_all(&[0, 60, 0, 71])?; - longlong(delivery_tag, &mut writer)?; - bit(&[redelivered], &mut writer)?; - shortstr(exchange, &mut writer)?; - shortstr(routing_key, &mut writer)?; - long(message_count, &mut writer)?; - } - Class::Basic(Basic::GetEmpty { reserved_1 }) => { - writer.write_all(&[0, 60, 0, 72])?; - shortstr(reserved_1, &mut writer)?; - } - Class::Basic(Basic::Ack { - delivery_tag, - multiple, - }) => { - writer.write_all(&[0, 60, 0, 80])?; - longlong(delivery_tag, &mut writer)?; - bit(&[multiple], &mut writer)?; - } - Class::Basic(Basic::Reject { - delivery_tag, - requeue, - }) => { - writer.write_all(&[0, 60, 0, 90])?; - longlong(delivery_tag, &mut writer)?; - bit(&[requeue], &mut writer)?; - } - Class::Basic(Basic::RecoverAsync { requeue }) => { - writer.write_all(&[0, 60, 0, 100])?; - bit(&[requeue], &mut writer)?; - } - Class::Basic(Basic::Recover { requeue }) => { - writer.write_all(&[0, 60, 0, 110])?; - bit(&[requeue], &mut writer)?; - } - Class::Basic(Basic::RecoverOk {}) => { - writer.write_all(&[0, 60, 0, 111])?; - } - Class::Tx(Tx::Select {}) => { - writer.write_all(&[0, 90, 0, 10])?; - } - Class::Tx(Tx::SelectOk {}) => { - writer.write_all(&[0, 90, 0, 11])?; - } - Class::Tx(Tx::Commit {}) => { - writer.write_all(&[0, 90, 0, 20])?; - } - Class::Tx(Tx::CommitOk {}) => { - writer.write_all(&[0, 90, 0, 21])?; - } - Class::Tx(Tx::Rollback {}) => { - writer.write_all(&[0, 90, 0, 30])?; - } - Class::Tx(Tx::RollbackOk {}) => { - writer.write_all(&[0, 90, 0, 31])?; - } +pub fn write_method(class: Class, mut writer: W) -> Result<(), TransError> { + match class { + Class::Connection(Connection::Start { + version_major, + version_minor, + server_properties, + mechanisms, + locales, + }) => { + writer.write_all(&[0, 10, 0, 10])?; + octet(version_major, &mut writer)?; + octet(version_minor, &mut writer)?; + table(server_properties, &mut writer)?; + longstr(mechanisms, &mut writer)?; + longstr(locales, &mut writer)?; + } + Class::Connection(Connection::StartOk { + client_properties, + mechanism, + response, + locale, + }) => { + writer.write_all(&[0, 10, 0, 11])?; + table(client_properties, &mut writer)?; + shortstr(mechanism, &mut writer)?; + longstr(response, &mut writer)?; + shortstr(locale, &mut writer)?; + } + Class::Connection(Connection::Secure { + challenge, + }) => { + writer.write_all(&[0, 10, 0, 20])?; + longstr(challenge, &mut writer)?; + } + Class::Connection(Connection::SecureOk { + response, + }) => { + writer.write_all(&[0, 10, 0, 21])?; + longstr(response, &mut writer)?; + } + Class::Connection(Connection::Tune { + channel_max, + frame_max, + heartbeat, + }) => { + writer.write_all(&[0, 10, 0, 30])?; + short(channel_max, &mut writer)?; + long(frame_max, &mut writer)?; + short(heartbeat, &mut writer)?; + } + Class::Connection(Connection::TuneOk { + channel_max, + frame_max, + heartbeat, + }) => { + writer.write_all(&[0, 10, 0, 31])?; + short(channel_max, &mut writer)?; + long(frame_max, &mut writer)?; + short(heartbeat, &mut writer)?; + } + Class::Connection(Connection::Open { + virtual_host, + reserved_1, + reserved_2, + }) => { + writer.write_all(&[0, 10, 0, 40])?; + shortstr(virtual_host, &mut writer)?; + shortstr(reserved_1, &mut writer)?; + bit(&[reserved_2, ], &mut writer)?; + } + Class::Connection(Connection::OpenOk { + reserved_1, + }) => { + writer.write_all(&[0, 10, 0, 41])?; + shortstr(reserved_1, &mut writer)?; + } + Class::Connection(Connection::Close { + reply_code, + reply_text, + class_id, + method_id, + }) => { + writer.write_all(&[0, 10, 0, 50])?; + short(reply_code, &mut writer)?; + shortstr(reply_text, &mut writer)?; + short(class_id, &mut writer)?; + short(method_id, &mut writer)?; + } + Class::Connection(Connection::CloseOk { + }) => { + writer.write_all(&[0, 10, 0, 51])?; + } + Class::Channel(Channel::Open { + reserved_1, + }) => { + writer.write_all(&[0, 20, 0, 10])?; + shortstr(reserved_1, &mut writer)?; + } + Class::Channel(Channel::OpenOk { + reserved_1, + }) => { + writer.write_all(&[0, 20, 0, 11])?; + longstr(reserved_1, &mut writer)?; + } + Class::Channel(Channel::Flow { + active, + }) => { + writer.write_all(&[0, 20, 0, 20])?; + bit(&[active, ], &mut writer)?; + } + Class::Channel(Channel::FlowOk { + active, + }) => { + writer.write_all(&[0, 20, 0, 21])?; + bit(&[active, ], &mut writer)?; + } + Class::Channel(Channel::Close { + reply_code, + reply_text, + class_id, + method_id, + }) => { + writer.write_all(&[0, 20, 0, 40])?; + short(reply_code, &mut writer)?; + shortstr(reply_text, &mut writer)?; + short(class_id, &mut writer)?; + short(method_id, &mut writer)?; + } + Class::Channel(Channel::CloseOk { + }) => { + writer.write_all(&[0, 20, 0, 41])?; + } + Class::Exchange(Exchange::Declare { + reserved_1, + exchange, + r#type, + passive, + durable, + reserved_2, + reserved_3, + no_wait, + arguments, + }) => { + writer.write_all(&[0, 40, 0, 10])?; + short(reserved_1, &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(r#type, &mut writer)?; + bit(&[passive, durable, reserved_2, reserved_3, no_wait, ], &mut writer)?; + table(arguments, &mut writer)?; + } + Class::Exchange(Exchange::DeclareOk { + }) => { + writer.write_all(&[0, 40, 0, 11])?; + } + Class::Exchange(Exchange::Delete { + reserved_1, + exchange, + if_unused, + no_wait, + }) => { + writer.write_all(&[0, 40, 0, 20])?; + short(reserved_1, &mut writer)?; + shortstr(exchange, &mut writer)?; + bit(&[if_unused, no_wait, ], &mut writer)?; + } + Class::Exchange(Exchange::DeleteOk { + }) => { + writer.write_all(&[0, 40, 0, 21])?; + } + Class::Queue(Queue::Declare { + reserved_1, + queue, + passive, + durable, + exclusive, + auto_delete, + no_wait, + arguments, + }) => { + writer.write_all(&[0, 50, 0, 10])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + bit(&[passive, durable, exclusive, auto_delete, no_wait, ], &mut writer)?; + table(arguments, &mut writer)?; + } + Class::Queue(Queue::DeclareOk { + queue, + message_count, + consumer_count, + }) => { + writer.write_all(&[0, 50, 0, 11])?; + shortstr(queue, &mut writer)?; + long(message_count, &mut writer)?; + long(consumer_count, &mut writer)?; + } + Class::Queue(Queue::Bind { + reserved_1, + queue, + exchange, + routing_key, + no_wait, + arguments, + }) => { + writer.write_all(&[0, 50, 0, 20])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(routing_key, &mut writer)?; + bit(&[no_wait, ], &mut writer)?; + table(arguments, &mut writer)?; + } + Class::Queue(Queue::BindOk { + }) => { + writer.write_all(&[0, 50, 0, 21])?; + } + Class::Queue(Queue::Unbind { + reserved_1, + queue, + exchange, + routing_key, + arguments, + }) => { + writer.write_all(&[0, 50, 0, 50])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(routing_key, &mut writer)?; + table(arguments, &mut writer)?; + } + Class::Queue(Queue::UnbindOk { + }) => { + writer.write_all(&[0, 50, 0, 51])?; + } + Class::Queue(Queue::Purge { + reserved_1, + queue, + no_wait, + }) => { + writer.write_all(&[0, 50, 0, 30])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + bit(&[no_wait, ], &mut writer)?; + } + Class::Queue(Queue::PurgeOk { + message_count, + }) => { + writer.write_all(&[0, 50, 0, 31])?; + long(message_count, &mut writer)?; + } + Class::Queue(Queue::Delete { + reserved_1, + queue, + if_unused, + if_empty, + no_wait, + }) => { + writer.write_all(&[0, 50, 0, 40])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + bit(&[if_unused, if_empty, no_wait, ], &mut writer)?; + } + Class::Queue(Queue::DeleteOk { + message_count, + }) => { + writer.write_all(&[0, 50, 0, 41])?; + long(message_count, &mut writer)?; + } + Class::Basic(Basic::Qos { + prefetch_size, + prefetch_count, + global, + }) => { + writer.write_all(&[0, 60, 0, 10])?; + long(prefetch_size, &mut writer)?; + short(prefetch_count, &mut writer)?; + bit(&[global, ], &mut writer)?; + } + Class::Basic(Basic::QosOk { + }) => { + writer.write_all(&[0, 60, 0, 11])?; + } + Class::Basic(Basic::Consume { + reserved_1, + queue, + consumer_tag, + no_local, + no_ack, + exclusive, + no_wait, + arguments, + }) => { + writer.write_all(&[0, 60, 0, 20])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + shortstr(consumer_tag, &mut writer)?; + bit(&[no_local, no_ack, exclusive, no_wait, ], &mut writer)?; + table(arguments, &mut writer)?; + } + Class::Basic(Basic::ConsumeOk { + consumer_tag, + }) => { + writer.write_all(&[0, 60, 0, 21])?; + shortstr(consumer_tag, &mut writer)?; + } + Class::Basic(Basic::Cancel { + consumer_tag, + no_wait, + }) => { + writer.write_all(&[0, 60, 0, 30])?; + shortstr(consumer_tag, &mut writer)?; + bit(&[no_wait, ], &mut writer)?; + } + Class::Basic(Basic::CancelOk { + consumer_tag, + }) => { + writer.write_all(&[0, 60, 0, 31])?; + shortstr(consumer_tag, &mut writer)?; + } + Class::Basic(Basic::Publish { + reserved_1, + exchange, + routing_key, + mandatory, + immediate, + }) => { + writer.write_all(&[0, 60, 0, 40])?; + short(reserved_1, &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(routing_key, &mut writer)?; + bit(&[mandatory, immediate, ], &mut writer)?; + } + Class::Basic(Basic::Return { + reply_code, + reply_text, + exchange, + routing_key, + }) => { + writer.write_all(&[0, 60, 0, 50])?; + short(reply_code, &mut writer)?; + shortstr(reply_text, &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(routing_key, &mut writer)?; + } + Class::Basic(Basic::Deliver { + consumer_tag, + delivery_tag, + redelivered, + exchange, + routing_key, + }) => { + writer.write_all(&[0, 60, 0, 60])?; + shortstr(consumer_tag, &mut writer)?; + longlong(delivery_tag, &mut writer)?; + bit(&[redelivered, ], &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(routing_key, &mut writer)?; + } + Class::Basic(Basic::Get { + reserved_1, + queue, + no_ack, + }) => { + writer.write_all(&[0, 60, 0, 70])?; + short(reserved_1, &mut writer)?; + shortstr(queue, &mut writer)?; + bit(&[no_ack, ], &mut writer)?; + } + Class::Basic(Basic::GetOk { + delivery_tag, + redelivered, + exchange, + routing_key, + message_count, + }) => { + writer.write_all(&[0, 60, 0, 71])?; + longlong(delivery_tag, &mut writer)?; + bit(&[redelivered, ], &mut writer)?; + shortstr(exchange, &mut writer)?; + shortstr(routing_key, &mut writer)?; + long(message_count, &mut writer)?; + } + Class::Basic(Basic::GetEmpty { + reserved_1, + }) => { + writer.write_all(&[0, 60, 0, 72])?; + shortstr(reserved_1, &mut writer)?; + } + Class::Basic(Basic::Ack { + delivery_tag, + multiple, + }) => { + writer.write_all(&[0, 60, 0, 80])?; + longlong(delivery_tag, &mut writer)?; + bit(&[multiple, ], &mut writer)?; + } + Class::Basic(Basic::Reject { + delivery_tag, + requeue, + }) => { + writer.write_all(&[0, 60, 0, 90])?; + longlong(delivery_tag, &mut writer)?; + bit(&[requeue, ], &mut writer)?; + } + Class::Basic(Basic::RecoverAsync { + requeue, + }) => { + writer.write_all(&[0, 60, 0, 100])?; + bit(&[requeue, ], &mut writer)?; + } + Class::Basic(Basic::Recover { + requeue, + }) => { + writer.write_all(&[0, 60, 0, 110])?; + bit(&[requeue, ], &mut writer)?; + } + Class::Basic(Basic::RecoverOk { + }) => { + writer.write_all(&[0, 60, 0, 111])?; + } + Class::Tx(Tx::Select { + }) => { + writer.write_all(&[0, 90, 0, 10])?; + } + Class::Tx(Tx::SelectOk { + }) => { + writer.write_all(&[0, 90, 0, 11])?; + } + Class::Tx(Tx::Commit { + }) => { + writer.write_all(&[0, 90, 0, 20])?; + } + Class::Tx(Tx::CommitOk { + }) => { + writer.write_all(&[0, 90, 0, 21])?; + } + Class::Tx(Tx::Rollback { + }) => { + writer.write_all(&[0, 90, 0, 30])?; + } + Class::Tx(Tx::RollbackOk { + }) => { + writer.write_all(&[0, 90, 0, 31])?; } - Ok(()) } + Ok(()) +} } #[cfg(test)] mod random { - use super::*; - use crate::classes::tests::RandomMethod; - use rand::Rng; +use rand::Rng; +use crate::classes::tests::RandomMethod; +use super::*; - impl RandomMethod for Class { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..6) { - 0 => Class::Connection(Connection::random(rng)), - 1 => Class::Channel(Channel::random(rng)), - 2 => Class::Exchange(Exchange::random(rng)), - 3 => Class::Queue(Queue::random(rng)), - 4 => Class::Basic(Basic::random(rng)), - 5 => Class::Tx(Tx::random(rng)), - _ => unreachable!(), +impl RandomMethod for Class { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..6) { + 0 => Class::Connection(Connection::random(rng)), + 1 => Class::Channel(Channel::random(rng)), + 2 => Class::Exchange(Exchange::random(rng)), + 3 => Class::Queue(Queue::random(rng)), + 4 => Class::Basic(Basic::random(rng)), + 5 => Class::Tx(Tx::random(rng)), + _ => unreachable!(), } - } - } - impl RandomMethod for Connection { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..10) { - 0 => Connection::Start { - version_major: RandomMethod::random(rng), - version_minor: RandomMethod::random(rng), - server_properties: RandomMethod::random(rng), - mechanisms: RandomMethod::random(rng), - locales: RandomMethod::random(rng), - }, - 1 => Connection::StartOk { - client_properties: RandomMethod::random(rng), - mechanism: RandomMethod::random(rng), - response: RandomMethod::random(rng), - locale: RandomMethod::random(rng), - }, - 2 => Connection::Secure { - challenge: RandomMethod::random(rng), - }, - 3 => Connection::SecureOk { - response: RandomMethod::random(rng), - }, - 4 => Connection::Tune { - channel_max: RandomMethod::random(rng), - frame_max: RandomMethod::random(rng), - heartbeat: RandomMethod::random(rng), - }, - 5 => Connection::TuneOk { - channel_max: RandomMethod::random(rng), - frame_max: RandomMethod::random(rng), - heartbeat: RandomMethod::random(rng), - }, - 6 => Connection::Open { - virtual_host: RandomMethod::random(rng), - reserved_1: RandomMethod::random(rng), - reserved_2: RandomMethod::random(rng), - }, - 7 => Connection::OpenOk { - reserved_1: RandomMethod::random(rng), - }, - 8 => Connection::Close { - reply_code: RandomMethod::random(rng), - reply_text: RandomMethod::random(rng), - class_id: RandomMethod::random(rng), - method_id: RandomMethod::random(rng), - }, - 9 => Connection::CloseOk {}, - _ => unreachable!(), - } - } - } - impl RandomMethod for Channel { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..6) { - 0 => Channel::Open { - reserved_1: RandomMethod::random(rng), - }, - 1 => Channel::OpenOk { - reserved_1: RandomMethod::random(rng), - }, - 2 => Channel::Flow { - active: RandomMethod::random(rng), - }, - 3 => Channel::FlowOk { - active: RandomMethod::random(rng), - }, - 4 => Channel::Close { - reply_code: RandomMethod::random(rng), - reply_text: RandomMethod::random(rng), - class_id: RandomMethod::random(rng), - method_id: RandomMethod::random(rng), - }, - 5 => Channel::CloseOk {}, - _ => unreachable!(), - } - } - } - impl RandomMethod for Exchange { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..4) { - 0 => Exchange::Declare { - reserved_1: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - r#type: RandomMethod::random(rng), - passive: RandomMethod::random(rng), - durable: RandomMethod::random(rng), - reserved_2: RandomMethod::random(rng), - reserved_3: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - arguments: RandomMethod::random(rng), - }, - 1 => Exchange::DeclareOk {}, - 2 => Exchange::Delete { - reserved_1: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - if_unused: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - }, - 3 => Exchange::DeleteOk {}, - _ => unreachable!(), - } - } - } - impl RandomMethod for Queue { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..10) { - 0 => Queue::Declare { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - passive: RandomMethod::random(rng), - durable: RandomMethod::random(rng), - exclusive: RandomMethod::random(rng), - auto_delete: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - arguments: RandomMethod::random(rng), - }, - 1 => Queue::DeclareOk { - queue: RandomMethod::random(rng), - message_count: RandomMethod::random(rng), - consumer_count: RandomMethod::random(rng), - }, - 2 => Queue::Bind { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - routing_key: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - arguments: RandomMethod::random(rng), - }, - 3 => Queue::BindOk {}, - 4 => Queue::Unbind { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - routing_key: RandomMethod::random(rng), - arguments: RandomMethod::random(rng), - }, - 5 => Queue::UnbindOk {}, - 6 => Queue::Purge { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - }, - 7 => Queue::PurgeOk { - message_count: RandomMethod::random(rng), - }, - 8 => Queue::Delete { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - if_unused: RandomMethod::random(rng), - if_empty: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - }, - 9 => Queue::DeleteOk { - message_count: RandomMethod::random(rng), - }, - _ => unreachable!(), - } - } - } - impl RandomMethod for Basic { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..17) { - 0 => Basic::Qos { - prefetch_size: RandomMethod::random(rng), - prefetch_count: RandomMethod::random(rng), - global: RandomMethod::random(rng), - }, - 1 => Basic::QosOk {}, - 2 => Basic::Consume { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - consumer_tag: RandomMethod::random(rng), - no_local: RandomMethod::random(rng), - no_ack: RandomMethod::random(rng), - exclusive: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - arguments: RandomMethod::random(rng), - }, - 3 => Basic::ConsumeOk { - consumer_tag: RandomMethod::random(rng), - }, - 4 => Basic::Cancel { - consumer_tag: RandomMethod::random(rng), - no_wait: RandomMethod::random(rng), - }, - 5 => Basic::CancelOk { - consumer_tag: RandomMethod::random(rng), - }, - 6 => Basic::Publish { - reserved_1: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - routing_key: RandomMethod::random(rng), - mandatory: RandomMethod::random(rng), - immediate: RandomMethod::random(rng), - }, - 7 => Basic::Return { - reply_code: RandomMethod::random(rng), - reply_text: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - routing_key: RandomMethod::random(rng), - }, - 8 => Basic::Deliver { - consumer_tag: RandomMethod::random(rng), - delivery_tag: RandomMethod::random(rng), - redelivered: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - routing_key: RandomMethod::random(rng), - }, - 9 => Basic::Get { - reserved_1: RandomMethod::random(rng), - queue: RandomMethod::random(rng), - no_ack: RandomMethod::random(rng), - }, - 10 => Basic::GetOk { - delivery_tag: RandomMethod::random(rng), - redelivered: RandomMethod::random(rng), - exchange: RandomMethod::random(rng), - routing_key: RandomMethod::random(rng), - message_count: RandomMethod::random(rng), - }, - 11 => Basic::GetEmpty { - reserved_1: RandomMethod::random(rng), - }, - 12 => Basic::Ack { - delivery_tag: RandomMethod::random(rng), - multiple: RandomMethod::random(rng), - }, - 13 => Basic::Reject { - delivery_tag: RandomMethod::random(rng), - requeue: RandomMethod::random(rng), - }, - 14 => Basic::RecoverAsync { - requeue: RandomMethod::random(rng), - }, - 15 => Basic::Recover { - requeue: RandomMethod::random(rng), - }, - 16 => Basic::RecoverOk {}, - _ => unreachable!(), - } - } - } - impl RandomMethod for Tx { - #[allow(unused_variables)] - fn random(rng: &mut R) -> Self { - match rng.gen_range(0u32..6) { - 0 => Tx::Select {}, - 1 => Tx::SelectOk {}, - 2 => Tx::Commit {}, - 3 => Tx::CommitOk {}, - 4 => Tx::Rollback {}, - 5 => Tx::RollbackOk {}, - _ => unreachable!(), - } - } } } +impl RandomMethod for Connection { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..10) { + 0 => Connection::Start { + version_major: RandomMethod::random(rng), + version_minor: RandomMethod::random(rng), + server_properties: RandomMethod::random(rng), + mechanisms: RandomMethod::random(rng), + locales: RandomMethod::random(rng), + }, + 1 => Connection::StartOk { + client_properties: RandomMethod::random(rng), + mechanism: RandomMethod::random(rng), + response: RandomMethod::random(rng), + locale: RandomMethod::random(rng), + }, + 2 => Connection::Secure { + challenge: RandomMethod::random(rng), + }, + 3 => Connection::SecureOk { + response: RandomMethod::random(rng), + }, + 4 => Connection::Tune { + channel_max: RandomMethod::random(rng), + frame_max: RandomMethod::random(rng), + heartbeat: RandomMethod::random(rng), + }, + 5 => Connection::TuneOk { + channel_max: RandomMethod::random(rng), + frame_max: RandomMethod::random(rng), + heartbeat: RandomMethod::random(rng), + }, + 6 => Connection::Open { + virtual_host: RandomMethod::random(rng), + reserved_1: RandomMethod::random(rng), + reserved_2: RandomMethod::random(rng), + }, + 7 => Connection::OpenOk { + reserved_1: RandomMethod::random(rng), + }, + 8 => Connection::Close { + reply_code: RandomMethod::random(rng), + reply_text: RandomMethod::random(rng), + class_id: RandomMethod::random(rng), + method_id: RandomMethod::random(rng), + }, + 9 => Connection::CloseOk { + }, + _ => unreachable!(), + } + } +} +impl RandomMethod for Channel { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..6) { + 0 => Channel::Open { + reserved_1: RandomMethod::random(rng), + }, + 1 => Channel::OpenOk { + reserved_1: RandomMethod::random(rng), + }, + 2 => Channel::Flow { + active: RandomMethod::random(rng), + }, + 3 => Channel::FlowOk { + active: RandomMethod::random(rng), + }, + 4 => Channel::Close { + reply_code: RandomMethod::random(rng), + reply_text: RandomMethod::random(rng), + class_id: RandomMethod::random(rng), + method_id: RandomMethod::random(rng), + }, + 5 => Channel::CloseOk { + }, + _ => unreachable!(), + } + } +} +impl RandomMethod for Exchange { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..4) { + 0 => Exchange::Declare { + reserved_1: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + r#type: RandomMethod::random(rng), + passive: RandomMethod::random(rng), + durable: RandomMethod::random(rng), + reserved_2: RandomMethod::random(rng), + reserved_3: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + arguments: RandomMethod::random(rng), + }, + 1 => Exchange::DeclareOk { + }, + 2 => Exchange::Delete { + reserved_1: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + if_unused: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + }, + 3 => Exchange::DeleteOk { + }, + _ => unreachable!(), + } + } +} +impl RandomMethod for Queue { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..10) { + 0 => Queue::Declare { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + passive: RandomMethod::random(rng), + durable: RandomMethod::random(rng), + exclusive: RandomMethod::random(rng), + auto_delete: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + arguments: RandomMethod::random(rng), + }, + 1 => Queue::DeclareOk { + queue: RandomMethod::random(rng), + message_count: RandomMethod::random(rng), + consumer_count: RandomMethod::random(rng), + }, + 2 => Queue::Bind { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + routing_key: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + arguments: RandomMethod::random(rng), + }, + 3 => Queue::BindOk { + }, + 4 => Queue::Unbind { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + routing_key: RandomMethod::random(rng), + arguments: RandomMethod::random(rng), + }, + 5 => Queue::UnbindOk { + }, + 6 => Queue::Purge { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + }, + 7 => Queue::PurgeOk { + message_count: RandomMethod::random(rng), + }, + 8 => Queue::Delete { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + if_unused: RandomMethod::random(rng), + if_empty: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + }, + 9 => Queue::DeleteOk { + message_count: RandomMethod::random(rng), + }, + _ => unreachable!(), + } + } +} +impl RandomMethod for Basic { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..17) { + 0 => Basic::Qos { + prefetch_size: RandomMethod::random(rng), + prefetch_count: RandomMethod::random(rng), + global: RandomMethod::random(rng), + }, + 1 => Basic::QosOk { + }, + 2 => Basic::Consume { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + consumer_tag: RandomMethod::random(rng), + no_local: RandomMethod::random(rng), + no_ack: RandomMethod::random(rng), + exclusive: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + arguments: RandomMethod::random(rng), + }, + 3 => Basic::ConsumeOk { + consumer_tag: RandomMethod::random(rng), + }, + 4 => Basic::Cancel { + consumer_tag: RandomMethod::random(rng), + no_wait: RandomMethod::random(rng), + }, + 5 => Basic::CancelOk { + consumer_tag: RandomMethod::random(rng), + }, + 6 => Basic::Publish { + reserved_1: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + routing_key: RandomMethod::random(rng), + mandatory: RandomMethod::random(rng), + immediate: RandomMethod::random(rng), + }, + 7 => Basic::Return { + reply_code: RandomMethod::random(rng), + reply_text: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + routing_key: RandomMethod::random(rng), + }, + 8 => Basic::Deliver { + consumer_tag: RandomMethod::random(rng), + delivery_tag: RandomMethod::random(rng), + redelivered: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + routing_key: RandomMethod::random(rng), + }, + 9 => Basic::Get { + reserved_1: RandomMethod::random(rng), + queue: RandomMethod::random(rng), + no_ack: RandomMethod::random(rng), + }, + 10 => Basic::GetOk { + delivery_tag: RandomMethod::random(rng), + redelivered: RandomMethod::random(rng), + exchange: RandomMethod::random(rng), + routing_key: RandomMethod::random(rng), + message_count: RandomMethod::random(rng), + }, + 11 => Basic::GetEmpty { + reserved_1: RandomMethod::random(rng), + }, + 12 => Basic::Ack { + delivery_tag: RandomMethod::random(rng), + multiple: RandomMethod::random(rng), + }, + 13 => Basic::Reject { + delivery_tag: RandomMethod::random(rng), + requeue: RandomMethod::random(rng), + }, + 14 => Basic::RecoverAsync { + requeue: RandomMethod::random(rng), + }, + 15 => Basic::Recover { + requeue: RandomMethod::random(rng), + }, + 16 => Basic::RecoverOk { + }, + _ => unreachable!(), + } + } +} +impl RandomMethod for Tx { + #[allow(unused_variables)] + fn random(rng: &mut R) -> Self { + match rng.gen_range(0u32..6) { + 0 => Tx::Select { + }, + 1 => Tx::SelectOk { + }, + 2 => Tx::Commit { + }, + 3 => Tx::CommitOk { + }, + 4 => Tx::Rollback { + }, + 5 => Tx::RollbackOk { + }, + _ => unreachable!(), + } + } +} +} diff --git a/amqp_transport/src/classes/parse_helper.rs b/amqp_transport/src/classes/parse_helper.rs index c386c26..05e2320 100644 --- a/amqp_transport/src/classes/parse_helper.rs +++ b/amqp_transport/src/classes/parse_helper.rs @@ -77,23 +77,23 @@ macro_rules! fail { use crate::classes::{FieldValue, TableFieldName}; pub use fail; -pub fn octet(input: &[u8]) -> IResult { +pub fn octet(input: &[u8]) -> IResult<'_, Octet> { u8(input) } -pub fn short(input: &[u8]) -> IResult { +pub fn short(input: &[u8]) -> IResult<'_, Short> { u16(Big)(input) } -pub fn long(input: &[u8]) -> IResult { +pub fn long(input: &[u8]) -> IResult<'_, Long> { u32(Big)(input) } -pub fn longlong(input: &[u8]) -> IResult { +pub fn longlong(input: &[u8]) -> IResult<'_, Longlong> { u64(Big)(input) } -pub fn bit(input: &[u8], amount: usize) -> IResult> { +pub fn bit(input: &[u8], amount: usize) -> IResult<'_, Vec> { let octets = (amount + 7) / 8; let (input, bytes) = take(octets)(input)?; @@ -119,25 +119,25 @@ pub fn bit(input: &[u8], amount: usize) -> IResult> { Ok((input, vec)) } -pub fn shortstr(input: &[u8]) -> IResult { +pub fn shortstr(input: &[u8]) -> IResult<'_, Shortstr> { let (input, len) = u8(input)?; let (input, str_data) = take(usize::from(len))(input)?; let data = String::from_utf8(str_data.into()).map_err(err_other("shortstr"))?; Ok((input, data)) } -pub fn longstr(input: &[u8]) -> IResult { +pub fn longstr(input: &[u8]) -> IResult<'_, Longstr> { let (input, len) = u32(Big)(input)?; let (input, str_data) = take(usize::try_from(len).unwrap())(input)?; let data = str_data.into(); Ok((input, data)) } -pub fn timestamp(input: &[u8]) -> IResult { +pub fn timestamp(input: &[u8]) -> IResult<'_, Timestamp> { u64(Big)(input) } -pub fn table(input: &[u8]) -> IResult
{ +pub fn table(input: &[u8]) -> IResult<'_, Table> { let (input, size) = u32(Big)(input)?; let (table_input, rest_input) = input.split_at(size.try_into().unwrap()); @@ -154,16 +154,16 @@ pub fn table(input: &[u8]) -> IResult
{ Ok((rest_input, table)) } -fn table_value_pair(input: &[u8]) -> IResult<(TableFieldName, FieldValue)> { +fn table_value_pair(input: &[u8]) -> IResult<'_, (TableFieldName, FieldValue)> { let (input, field_name) = shortstr(input)?; let (input, field_value) = field_value(input).map_err(err(format!("field {field_name}")))?; Ok((input, (field_name, field_value))) } -fn field_value(input: &[u8]) -> IResult { +fn field_value(input: &[u8]) -> IResult<'_, FieldValue> { type R<'a> = IResult<'a, FieldValue>; - fn boolean(input: &[u8]) -> R { + fn boolean(input: &[u8]) -> R<'_> { let (input, _) = tag(b"t")(input)?; let (input, bool_byte) = u8(input)?; match bool_byte { @@ -182,37 +182,37 @@ fn field_value(input: &[u8]) -> IResult { }; } - number!(b"b", short_short_int, i8, ShortShortInt, R); - number!(b"B", short_short_uint, u8, ShortShortUInt, R); - number!(b"U", short_int, i16(Big), ShortInt, R); - number!(b"u", short_uint, u16(Big), ShortUInt, R); - number!(b"I", long_int, i32(Big), LongInt, R); - number!(b"i", long_uint, u32(Big), LongUInt, R); - number!(b"L", long_long_int, i64(Big), LongLongInt, R); - number!(b"l", long_long_uint, u64(Big), LongLongUInt, R); - number!(b"f", float, f32(Big), Float, R); - number!(b"d", double, f64(Big), Double, R); + number!(b"b", short_short_int, i8, ShortShortInt, R<'_>); + number!(b"B", short_short_uint, u8, ShortShortUInt, R<'_>); + number!(b"U", short_int, i16(Big), ShortInt, R<'_>); + number!(b"u", short_uint, u16(Big), ShortUInt, R<'_>); + number!(b"I", long_int, i32(Big), LongInt, R<'_>); + number!(b"i", long_uint, u32(Big), LongUInt, R<'_>); + number!(b"L", long_long_int, i64(Big), LongLongInt, R<'_>); + number!(b"l", long_long_uint, u64(Big), LongLongUInt, R<'_>); + number!(b"f", float, f32(Big), Float, R<'_>); + number!(b"d", double, f64(Big), Double, R<'_>); - fn decimal(input: &[u8]) -> R { + fn decimal(input: &[u8]) -> R<'_> { let (input, _) = tag("D")(input)?; let (input, scale) = u8(input)?; let (input, value) = u32(Big)(input)?; Ok((input, FieldValue::DecimalValue(scale, value))) } - fn short_str(input: &[u8]) -> R { + fn short_str(input: &[u8]) -> R<'_> { let (input, _) = tag("s")(input)?; let (input, str) = shortstr(input)?; Ok((input, FieldValue::ShortString(str))) } - fn long_str(input: &[u8]) -> R { + fn long_str(input: &[u8]) -> R<'_> { let (input, _) = tag("S")(input)?; let (input, str) = longstr(input)?; Ok((input, FieldValue::LongString(str))) } - fn field_array(input: &[u8]) -> R { + fn field_array(input: &[u8]) -> R<'_> { let (input, _) = tag("A")(input)?; // todo is it i32? let (input, len) = u32(Big)(input)?; @@ -220,14 +220,14 @@ fn field_value(input: &[u8]) -> IResult { .map(|(input, value)| (input, FieldValue::FieldArray(value))) } - number!(b"T", timestamp, u64(Big), Timestamp, R); + number!(b"T", timestamp, u64(Big), Timestamp, R<'_>); - fn field_table(input: &[u8]) -> R { + fn field_table(input: &[u8]) -> R<'_> { let (input, _) = tag("F")(input)?; table(input).map(|(input, value)| (input, FieldValue::FieldTable(value))) } - fn void(input: &[u8]) -> R { + fn void(input: &[u8]) -> R<'_> { tag("V")(input).map(|(input, _)| (input, FieldValue::Void)) } diff --git a/amqp_transport/src/connection.rs b/amqp_transport/src/connection.rs index 192df99..b27f015 100644 --- a/amqp_transport/src/connection.rs +++ b/amqp_transport/src/connection.rs @@ -27,6 +27,7 @@ const CHANNEL_MAX: u16 = 0; const FRAME_SIZE_MAX: u32 = 0; const HEARTBEAT_DELAY: u16 = 0; +#[allow(dead_code)] pub struct Channel { num: u16, channel_handle: amqp_core::ChannelHandle, diff --git a/amqp_transport/src/lib.rs b/amqp_transport/src/lib.rs index a1a4c57..2fb422f 100644 --- a/amqp_transport/src/lib.rs +++ b/amqp_transport/src/lib.rs @@ -1,4 +1,4 @@ -extern crate core; +#![warn(rust_2018_idioms)] mod classes; mod connection; diff --git a/src/main.rs b/src/main.rs index 24a6203..10a137c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,25 @@ +#![warn(rust_2018_idioms)] + use anyhow::Result; use std::env; +use tracing::Level; use tracing::{info_span, Instrument}; #[tokio::main] async fn main() -> Result<()> { let mut dashboard = false; + let mut level = Level::INFO; for arg in env::args().skip(1) { match arg.as_str() { + "--trace" => level = Level::TRACE, "--dashboard" => dashboard = true, "ignore-this-clippy" => eprintln!("yes please"), _ => {} } } - setup_tracing(); + setup_tracing(level); let global_data = amqp_core::GlobalData::default(); @@ -26,12 +31,12 @@ async fn main() -> Result<()> { amqp_transport::do_thing_i_guess(global_data).await } -fn setup_tracing() { +fn setup_tracing(level: Level) { tracing_subscriber::fmt() .with_level(true) .with_timer(tracing_subscriber::fmt::time::time()) .with_ansi(true) .with_thread_names(true) - .with_env_filter("hyper=info,debug") + .with_max_level(level) .init() } diff --git a/xtask/src/codegen/mod.rs b/xtask/src/codegen/mod.rs index 3f0b449..63f44a5 100644 --- a/xtask/src/codegen/mod.rs +++ b/xtask/src/codegen/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_late_init)] // because of a bad derive macro + mod parser; mod random; mod write; diff --git a/xtask/src/codegen/parser.rs b/xtask/src/codegen/parser.rs index 1dec9b3..6fc0072 100644 --- a/xtask/src/codegen/parser.rs +++ b/xtask/src/codegen/parser.rs @@ -176,7 +176,7 @@ fn function(name: &str, ret_ty: &str, body: F) where F: FnOnce(), { - println!("fn {name}(input: &[u8]) -> IResult<{ret_ty}> {{"); + println!("fn {name}(input: &[u8]) -> IResult<'_, {ret_ty}> {{"); body(); println!("}}"); }