1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use internal::*;

use amq_protocol_types::*;
use serde_json::from_str;

use std::collections::BTreeMap;

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQProtocolDefinition {
    pub name:          ShortString,
    pub major_version: ShortShortUInt,
    pub minor_version: ShortShortUInt,
    pub revision:      ShortShortUInt,
    pub port:          LongUInt,
    pub copyright:     LongString,
    pub domains:       BTreeMap<ShortString, AMQPType>,
    pub constants:     Vec<AMQPConstant>,
    pub soft_errors:   Vec<AMQPConstant>,
    pub hard_errors:   Vec<AMQPConstant>,
    pub classes:       Vec<AMQPClass>,
}

impl AMQProtocolDefinition {
    pub fn load() -> AMQProtocolDefinition {
        let specs = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/specs/amqp-rabbitmq-0.9.1.json"));

        from_str::<_AMQProtocolDefinition>(specs).expect("Failed to parse AMQP specs file").into_specs()
    }
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQPConstant {
    pub name:      ShortString,
    pub value:     ShortUInt,
    #[serde(rename="type")]
    pub amqp_type: AMQPType,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQPClass {
    pub id:             ShortUInt,
    pub methods:        Vec<AMQPMethod>,
    pub name:           ShortString,
    pub properties:     Vec<AMQPProperty>,
    pub has_properties: Boolean,
    pub is_connection:  Boolean,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQPMethod {
    pub id:            ShortUInt,
    pub arguments:     Vec<AMQPArgument>,
    pub has_arguments: Boolean,
    pub has_flags:     Boolean,
    pub name:          ShortString,
    pub synchronous:   Boolean,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum AMQPArgument {
    Value(AMQPValueArgument),
    Flags(Vec<AMQPFlagArgument>),
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQPValueArgument {
    #[serde(rename="type")]
    pub amqp_type:     AMQPType,
    pub name:          ShortString,
    pub default_value: Option<AMQPValue>,
    pub domain:        Option<ShortString>,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQPFlagArgument {
    pub name:          ShortString,
    pub default_value: Boolean,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct AMQPProperty {
    #[serde(rename="type")]
    pub amqp_type: AMQPType,
    pub name:      ShortString,
}