From 6f45a5287194702947bb81401c452dee32e0a235 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:42:16 +0100 Subject: [PATCH] move generated code --- amqp_codegen/src/main.rs | 13 + amqp_transport/src/classes/connection.rs | 24 -- amqp_transport/src/classes/generated.rs | 354 +++++++++++++++++++++++ amqp_transport/src/classes/mod.rs | 346 +--------------------- 4 files changed, 369 insertions(+), 368 deletions(-) delete mode 100644 amqp_transport/src/classes/connection.rs create mode 100644 amqp_transport/src/classes/generated.rs diff --git a/amqp_codegen/src/main.rs b/amqp_codegen/src/main.rs index f33223a..6158fba 100644 --- a/amqp_codegen/src/main.rs +++ b/amqp_codegen/src/main.rs @@ -104,6 +104,19 @@ fn domain_defs(amqp: &Amqp) -> Result<()> { } fn class_defs(amqp: &Amqp) -> Result<()> { + println!("pub enum Class {{"); + for class in &amqp.classes { + let class_name = class.name.to_upper_camel_case(); + println!(" {class_name}({class_name}),"); + } + println!("}}\n"); + + println!( + "pub enum TableValue {{ + + " + ); + for class in &amqp.classes { let enum_name = class.name.to_upper_camel_case(); println!("/// Index {}, handler = {}", class.index, class.handler); diff --git a/amqp_transport/src/classes/connection.rs b/amqp_transport/src/classes/connection.rs deleted file mode 100644 index 759cbe6..0000000 --- a/amqp_transport/src/classes/connection.rs +++ /dev/null @@ -1,24 +0,0 @@ -type Octet = u8; -type PeerProperties = (); -type LongStr = String; - -pub enum Connection { - Start { - version_major: Option, - version_minor: Option, - server_properties: PeerProperties, - mechanisms: LongStr, - locales: LongStr, - }, - StartOk, - Secure, - SecureOk, - Tune, - TuneOk, - Open, - OpenOk, - Close, - CloseOk, - Blocked, - Unblocked, -} diff --git a/amqp_transport/src/classes/generated.rs b/amqp_transport/src/classes/generated.rs new file mode 100644 index 0000000..5346807 --- /dev/null +++ b/amqp_transport/src/classes/generated.rs @@ -0,0 +1,354 @@ +use std::collections::HashMap; + +type ClassId = u16; + +type ConsumerTag = String; + +type DeliveryTag = u64; + +/// must be shorter than 127, must match `^[a-zA-Z0-9-_.:]*$` +type ExchangeName = String; + +type MethodId = u16; + +type NoAck = u8; + +type NoLocal = u8; + +type NoWait = u8; + +/// must be shorter than 127 +type Path = String; + +type PeerProperties = HashMap)>; + +/// must be shorter than 127, must match `^[a-zA-Z0-9-_.:]*$` +type QueueName = String; + +type Redelivered = u8; + +type MessageCount = u32; + +type ReplyCode = u16; + +type ReplyText = String; + +type Bit = u8; + +type Octet = u8; + +type Short = u16; + +type Long = u32; + +type Longlong = u64; + +type Shortstr = String; + +type Longstr = String; + +type Timestamp = u64; + +type Table = HashMap)>; + +pub enum Class { + Connection(Connection), + Channel(Channel), + Exchange(Exchange), + Queue(Queue), + Basic(Basic), + Tx(Tx), +} + +/// Index 10, handler = connection +pub enum Connection { + /// Index 10 + Start { + version_major: Option, + version_minor: Option, + server_properties: Option, + mechanisms: Longstr, + locales: Longstr, + }, + /// Index 11 + StartOk { + client_properties: Option, + mechanism: Shortstr, + response: Longstr, + locale: Shortstr, + }, + /// Index 20 + Secure { + challenge: Option, + }, + /// Index 21 + SecureOk { + response: Longstr, + }, + /// Index 30 + Tune { + channel_max: Option, + frame_max: Option, + heartbeat: Option, + }, + /// Index 31 + TuneOk { + /// must be less than the tune field of the method channel-max + channel_max: Short, + frame_max: Option, + heartbeat: Option, + }, + /// Index 40 + Open { + virtual_host: Path, + reserved_1: Option, + reserved_2: Option, + }, + /// Index 41 + OpenOk { + reserved_1: Option, + }, + /// Index 50 + Close { + reply_code: ReplyCode, + reply_text: ReplyText, + class_id: Option, + method_id: Option, + }, + /// Index 51 + CloseOk, + /// Index 60 + Blocked { + reason: Option, + }, + /// Index 61 + Unblocked, +} +/// Index 20, handler = channel +pub enum Channel { + /// Index 10 + Open { + reserved_1: Option, + }, + /// Index 11 + OpenOk { + reserved_1: Option, + }, + /// Index 20 + Flow { + active: Option, + }, + /// Index 21 + FlowOk { + active: Option, + }, + /// Index 40 + Close { + reply_code: ReplyCode, + reply_text: ReplyText, + class_id: Option, + method_id: Option, + }, + /// Index 41 + CloseOk, +} +/// Index 40, handler = channel +pub enum Exchange { + /// Index 10 + Declare { + reserved_1: Option, + exchange: ExchangeName, + r#type: Option, + passive: Option, + durable: Option, + reserved_2: Option, + reserved_3: Option, + no_wait: Option, + arguments: Option, + }, + /// Index 11 + DeclareOk, + /// Index 20 + Delete { + reserved_1: Option, + exchange: ExchangeName, + if_unused: Option, + no_wait: Option, + }, + /// Index 21 + DeleteOk, +} +/// Index 50, handler = channel +pub enum Queue { + /// Index 10 + Declare { + reserved_1: Option, + queue: Option, + passive: Option, + durable: Option, + exclusive: Option, + auto_delete: Option, + no_wait: Option, + arguments: Option
, + }, + /// Index 11 + DeclareOk { + queue: QueueName, + message_count: Option, + consumer_count: Option, + }, + /// Index 20 + Bind { + reserved_1: Option, + queue: Option, + exchange: Option, + routing_key: Option, + no_wait: Option, + arguments: Option
, + }, + /// Index 21 + BindOk, + /// Index 50 + Unbind { + reserved_1: Option, + queue: Option, + exchange: Option, + routing_key: Option, + arguments: Option
, + }, + /// Index 51 + UnbindOk, + /// Index 30 + Purge { + reserved_1: Option, + queue: Option, + no_wait: Option, + }, + /// Index 31 + PurgeOk { + message_count: Option, + }, + /// Index 40 + Delete { + reserved_1: Option, + queue: Option, + if_unused: Option, + if_empty: Option, + no_wait: Option, + }, + /// Index 41 + DeleteOk { + message_count: Option, + }, +} +/// Index 60, handler = channel +pub enum Basic { + /// Index 10 + Qos { + prefetch_size: Option, + prefetch_count: Option, + global: Option, + }, + /// Index 11 + QosOk, + /// Index 20 + Consume { + reserved_1: Option, + queue: Option, + consumer_tag: Option, + no_local: Option, + no_ack: Option, + exclusive: Option, + no_wait: Option, + arguments: Option
, + }, + /// Index 21 + ConsumeOk { + consumer_tag: Option, + }, + /// Index 30 + Cancel { + consumer_tag: Option, + no_wait: Option, + }, + /// Index 31 + CancelOk { + consumer_tag: Option, + }, + /// Index 40 + Publish { + reserved_1: Option, + exchange: Option, + routing_key: Option, + mandatory: Option, + immediate: Option, + }, + /// Index 50 + Return { + reply_code: ReplyCode, + reply_text: ReplyText, + exchange: Option, + routing_key: Option, + }, + /// Index 60 + Deliver { + consumer_tag: Option, + delivery_tag: Option, + redelivered: Option, + exchange: Option, + routing_key: Option, + }, + /// Index 70 + Get { + reserved_1: Option, + queue: Option, + no_ack: Option, + }, + /// Index 71 + GetOk { + delivery_tag: Option, + redelivered: Option, + exchange: Option, + routing_key: Option, + message_count: Option, + }, + /// Index 72 + GetEmpty { + reserved_1: Option, + }, + /// Index 80 + Ack { + delivery_tag: Option, + multiple: Option, + }, + /// Index 90 + Reject { + delivery_tag: Option, + requeue: Option, + }, + /// Index 100 + RecoverAsync { + requeue: Option, + }, + /// Index 110 + Recover { + requeue: Option, + }, + /// Index 111 + RecoverOk, +} +/// Index 90, handler = channel +pub enum Tx { + /// Index 10 + Select, + /// Index 11 + SelectOk, + /// Index 20 + Commit, + /// Index 21 + CommitOk, + /// Index 30 + Rollback, + /// Index 31 + RollbackOk, +} diff --git a/amqp_transport/src/classes/mod.rs b/amqp_transport/src/classes/mod.rs index 7127c85..915cf7d 100644 --- a/amqp_transport/src/classes/mod.rs +++ b/amqp_transport/src/classes/mod.rs @@ -1,345 +1,3 @@ -use std::collections::HashMap; +mod generated; -type ClassId = u16; - -type ConsumerTag = String; - -type DeliveryTag = u64; - -/// must be shorter than 127, must match `^[a-zA-Z0-9-_.:]*$` -type ExchangeName = String; - -type MethodId = u16; - -type NoAck = u8; - -type NoLocal = u8; - -type NoWait = u8; - -/// must be shorter than 127 -type Path = String; - -type PeerProperties = HashMap)>; - -/// must be shorter than 127, must match `^[a-zA-Z0-9-_.:]*$` -type QueueName = String; - -type Redelivered = u8; - -type MessageCount = u32; - -type ReplyCode = u16; - -type ReplyText = String; - -type Bit = u8; - -type Octet = u8; - -type Short = u16; - -type Long = u32; - -type Longlong = u64; - -type Shortstr = String; - -type Longstr = String; - -type Timestamp = u64; - -type Table = HashMap)>; - -/// Index 10, handler = connection -pub enum Connection { - /// Index 10 - Start { - version_major: Option, - version_minor: Option, - server_properties: Option, - mechanisms: Longstr, - locales: Longstr, - }, - /// Index 11 - StartOk { - client_properties: Option, - mechanism: Shortstr, - response: Longstr, - locale: Shortstr, - }, - /// Index 20 - Secure { - challenge: Option, - }, - /// Index 21 - SecureOk { - response: Longstr, - }, - /// Index 30 - Tune { - channel_max: Option, - frame_max: Option, - heartbeat: Option, - }, - /// Index 31 - TuneOk { - /// must be less than the tune field of the method channel-max - channel_max: Short, - frame_max: Option, - heartbeat: Option, - }, - /// Index 40 - Open { - virtual_host: Path, - reserved_1: Option, - reserved_2: Option, - }, - /// Index 41 - OpenOk { - reserved_1: Option, - }, - /// Index 50 - Close { - reply_code: ReplyCode, - reply_text: ReplyText, - class_id: Option, - method_id: Option, - }, - /// Index 51 - CloseOk, - /// Index 60 - Blocked { - reason: Option, - }, - /// Index 61 - Unblocked, -} -/// Index 20, handler = channel -pub enum Channel { - /// Index 10 - Open { - reserved_1: Option, - }, - /// Index 11 - OpenOk { - reserved_1: Option, - }, - /// Index 20 - Flow { - active: Option, - }, - /// Index 21 - FlowOk { - active: Option, - }, - /// Index 40 - Close { - reply_code: ReplyCode, - reply_text: ReplyText, - class_id: Option, - method_id: Option, - }, - /// Index 41 - CloseOk, -} -/// Index 40, handler = channel -pub enum Exchange { - /// Index 10 - Declare { - reserved_1: Option, - exchange: ExchangeName, - r#type: Option, - passive: Option, - durable: Option, - reserved_2: Option, - reserved_3: Option, - no_wait: Option, - arguments: Option
, - }, - /// Index 11 - DeclareOk, - /// Index 20 - Delete { - reserved_1: Option, - exchange: ExchangeName, - if_unused: Option, - no_wait: Option, - }, - /// Index 21 - DeleteOk, -} -/// Index 50, handler = channel -pub enum Queue { - /// Index 10 - Declare { - reserved_1: Option, - queue: Option, - passive: Option, - durable: Option, - exclusive: Option, - auto_delete: Option, - no_wait: Option, - arguments: Option
, - }, - /// Index 11 - DeclareOk { - queue: QueueName, - message_count: Option, - consumer_count: Option, - }, - /// Index 20 - Bind { - reserved_1: Option, - queue: Option, - exchange: Option, - routing_key: Option, - no_wait: Option, - arguments: Option
, - }, - /// Index 21 - BindOk, - /// Index 50 - Unbind { - reserved_1: Option, - queue: Option, - exchange: Option, - routing_key: Option, - arguments: Option
, - }, - /// Index 51 - UnbindOk, - /// Index 30 - Purge { - reserved_1: Option, - queue: Option, - no_wait: Option, - }, - /// Index 31 - PurgeOk { - message_count: Option, - }, - /// Index 40 - Delete { - reserved_1: Option, - queue: Option, - if_unused: Option, - if_empty: Option, - no_wait: Option, - }, - /// Index 41 - DeleteOk { - message_count: Option, - }, -} -/// Index 60, handler = channel -pub enum Basic { - /// Index 10 - Qos { - prefetch_size: Option, - prefetch_count: Option, - global: Option, - }, - /// Index 11 - QosOk, - /// Index 20 - Consume { - reserved_1: Option, - queue: Option, - consumer_tag: Option, - no_local: Option, - no_ack: Option, - exclusive: Option, - no_wait: Option, - arguments: Option
, - }, - /// Index 21 - ConsumeOk { - consumer_tag: Option, - }, - /// Index 30 - Cancel { - consumer_tag: Option, - no_wait: Option, - }, - /// Index 31 - CancelOk { - consumer_tag: Option, - }, - /// Index 40 - Publish { - reserved_1: Option, - exchange: Option, - routing_key: Option, - mandatory: Option, - immediate: Option, - }, - /// Index 50 - Return { - reply_code: ReplyCode, - reply_text: ReplyText, - exchange: Option, - routing_key: Option, - }, - /// Index 60 - Deliver { - consumer_tag: Option, - delivery_tag: Option, - redelivered: Option, - exchange: Option, - routing_key: Option, - }, - /// Index 70 - Get { - reserved_1: Option, - queue: Option, - no_ack: Option, - }, - /// Index 71 - GetOk { - delivery_tag: Option, - redelivered: Option, - exchange: Option, - routing_key: Option, - message_count: Option, - }, - /// Index 72 - GetEmpty { - reserved_1: Option, - }, - /// Index 80 - Ack { - delivery_tag: Option, - multiple: Option, - }, - /// Index 90 - Reject { - delivery_tag: Option, - requeue: Option, - }, - /// Index 100 - RecoverAsync { - requeue: Option, - }, - /// Index 110 - Recover { - requeue: Option, - }, - /// Index 111 - RecoverOk, -} -/// Index 90, handler = channel -pub enum Tx { - /// Index 10 - Select, - /// Index 11 - SelectOk, - /// Index 20 - Commit, - /// Index 21 - CommitOk, - /// Index 30 - Rollback, - /// Index 31 - RollbackOk, -} +static TABLE_VALUES: &[(char, &str)] = &[[]];