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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::{frame::parsing::traits::ParsableInput, protocol::*, types::*};
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AMQPChannel {
Global,
Id(ShortUInt),
}
impl AMQPChannel {
pub fn get_id(self) -> ShortUInt {
match self {
AMQPChannel::Global => 0,
AMQPChannel::Id(id) => id,
}
}
}
impl From<ShortUInt> for AMQPChannel {
fn from(id: ShortUInt) -> AMQPChannel {
match id {
0 => AMQPChannel::Global,
id => AMQPChannel::Id(id),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AMQPFrameType {
ProtocolHeader,
Method,
Header,
Body,
Heartbeat,
}
#[derive(Clone, Debug, PartialEq)]
pub enum AMQPFrame {
ProtocolHeader(ProtocolVersion),
Method(ShortUInt, AMQPClass),
Header(ShortUInt, ShortUInt, Box<AMQPContentHeader>),
Body(ShortUInt, Vec<u8>),
Heartbeat(ShortUInt),
}
impl AMQPFrame {
pub fn is_header(&self) -> bool {
if let AMQPFrame::Header(..) = self {
true
} else {
false
}
}
}
impl fmt::Display for AMQPFrame {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AMQPFrame::ProtocolHeader(version) => {
f.write_fmt(format_args!("AMQPFrame::ProtocolHeader({})", version))
}
AMQPFrame::Method(_, klass) => {
f.write_fmt(format_args!("AMQPFrame::Method({:?})", klass))
}
AMQPFrame::Header(..) => f.write_str("AMQPFrame::Header"),
AMQPFrame::Body(..) => f.write_str("AMQPFrame::Body"),
AMQPFrame::Heartbeat(_) => f.write_str("AMQPFrame::Heartbeat"),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ProtocolVersion {
pub major: u8,
pub minor: u8,
pub revision: u8,
}
impl ProtocolVersion {
pub fn amqp_0_9_1() -> Self {
Self {
major: metadata::MAJOR_VERSION,
minor: metadata::MINOR_VERSION,
revision: metadata::REVISION,
}
}
}
impl fmt::Display for ProtocolVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_fmt(format_args!(
"{}.{}.{}",
self.major, self.minor, self.revision
))
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AMQPRawFrame<I: ParsableInput> {
pub frame_type: AMQPFrameType,
pub channel_id: ShortUInt,
pub payload: I,
}
#[derive(Clone, Debug, PartialEq)]
pub struct AMQPContentHeader {
pub class_id: ShortUInt,
pub weight: ShortUInt,
pub body_size: LongLongUInt,
pub properties: basic::AMQPProperties,
}