Skip to content

Commit

Permalink
hide 'ticket'
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed Apr 5, 2019
1 parent 9733831 commit 7892b75
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion codegen/src/internal.rs
Expand Up @@ -163,7 +163,7 @@ impl _AMQPMethod {
fn arguments_to_specs(&self, domains: &BTreeMap<ShortString, AMQPType>) -> Vec<AMQPArgument> {
let mut arguments = Vec::new();
let mut flags : Option<Vec<AMQPFlagArgument>> = None;
for argument in &self.arguments {
for argument in self.arguments.iter().filter(|arg| arg.name != "ticket") {
let amqp_type = argument.get_type(domains);
if amqp_type == AMQPType::Boolean {
let mut flgs = flags.take().unwrap_or_else(Vec::new);
Expand Down
3 changes: 3 additions & 0 deletions protocol/Cargo.toml
Expand Up @@ -14,6 +14,9 @@ build = "build.rs"
[lib]
name = "amq_protocol"

[build-dependencies]
serde_json = "^1.0"

[build-dependencies.amq-protocol-codegen]
version = "^1.4.0"
path = "../codegen"
Expand Down
5 changes: 4 additions & 1 deletion protocol/build.rs
@@ -1,10 +1,13 @@
use amq_protocol_codegen::{CodeGenerator, HandlebarsAMQPExtension};
use serde_json::{from_str, Value};

use std::env;

fn main() {
let out_dir = env::var("OUT_DIR").expect("OUT_DIR is not defined");
let template = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/protocol.rs"));
let extra = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/protocol-extra.json"));
let data = from_str::<Value>(extra).expect("Failed to parse extra file");

CodeGenerator::simple_codegen(&out_dir, "protocol", "protocol", template, "protocol");
CodeGenerator::simple_codegen_with_data(&out_dir, "protocol", "protocol", template, "protocol", Some(data));
}
75 changes: 75 additions & 0 deletions protocol/templates/protocol-extra.json
@@ -0,0 +1,75 @@
{
"access": {
"request-ok": {
"metadata": {
"has_ticket": true
}
}
},
"exchange": {
"declare": {
"metadata": {
"has_ticket": true
}
},
"delete": {
"metadata": {
"has_ticket": true
}
},
"bind": {
"metadata": {
"has_ticket": true
}
},
"unbind": {
"metadata": {
"has_ticket": true
}
}
},
"queue": {
"declare": {
"metadata": {
"has_ticket": true
}
},
"bind": {
"metadata": {
"has_ticket": true
}
},
"purge": {
"metadata": {
"has_ticket": true
}
},
"delete": {
"metadata": {
"has_ticket": true
}
},
"unbind": {
"metadata": {
"has_ticket": true
}
}
},
"basic": {
"consume": {
"metadata": {
"has_ticket": true
}
},
"publish": {
"metadata": {
"has_ticket": true
}
},
"get": {
"metadata": {
"has_ticket": true
}
}
}
}
6 changes: 6 additions & 0 deletions protocol/templates/protocol.rs
Expand Up @@ -198,6 +198,9 @@ pub mod {{snake class.name}} {
}

named_attr!(#[doc = "Parse {{method.name}} (Generated)"], pub parse_{{snake method.name}}<{{camel method.name}}>, do_parse!(
{{#if method.metadata.has_ticket ~}}
parse_short_uint >>
{{/if ~}}
{{#each_argument method.arguments as |argument| ~}}
{{#if argument_is_value ~}}
{{snake argument.name}}: parse_{{snake_type argument.type}} >>
Expand Down Expand Up @@ -236,6 +239,9 @@ pub mod {{snake class.name}} {
{{/if ~}}
do_gen!(input,
gen_id({{method.id}})
{{#if method.metadata.has_ticket ~}}
>> gen_short_uint(0)
{{/if ~}}
{{#each_argument method.arguments as |argument| ~}}
{{#if argument_is_value ~}}
>> gen_{{snake_type argument.type}}(method.{{snake argument.name}}.as_gen_ref())
Expand Down

0 comments on commit 7892b75

Please sign in to comment.