|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
|
7
|
|
|
Transport\Protocol as ProtocolInterface, |
|
8
|
|
|
Transport\Protocol\Version, |
|
9
|
|
|
Transport\Protocol\Connection as ConnectionInterface, |
|
10
|
|
|
Transport\Protocol\Channel as ChannelInterface, |
|
11
|
|
|
Transport\Protocol\Exchange as ExchangeInterface, |
|
12
|
|
|
Transport\Protocol\Queue as QueueInterface, |
|
13
|
|
|
Transport\Protocol\Basic as BasicInterface, |
|
14
|
|
|
Transport\Protocol\Transaction as TransactionInterface, |
|
15
|
|
|
Transport\Protocol\ArgumentTranslator, |
|
16
|
|
|
Transport\Frame\Method, |
|
17
|
|
|
Transport\Frame\Visitor\ChunkArguments, |
|
18
|
|
|
Transport\Frame\Value\UnsignedOctet, |
|
19
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
|
20
|
|
|
Transport\Frame\Value\UnsignedLongLongInteger, |
|
21
|
|
|
Transport\Frame\Value\Timestamp, |
|
22
|
|
|
Transport\Frame\Value\Table, |
|
23
|
|
|
Transport\Frame\Value\ShortString, |
|
24
|
|
|
Transport\Frame\Value, |
|
25
|
|
|
Exception\VersionNotUsable, |
|
26
|
|
|
}; |
|
27
|
|
|
use Innmind\Stream\Readable; |
|
28
|
|
|
use Innmind\Immutable\{ |
|
29
|
|
|
StreamInterface, |
|
30
|
|
|
Stream, |
|
31
|
|
|
}; |
|
32
|
|
|
|
|
33
|
|
|
final class Protocol implements ProtocolInterface |
|
34
|
|
|
{ |
|
35
|
|
|
private $version; |
|
36
|
|
|
private $read; |
|
37
|
|
|
private $connection; |
|
38
|
|
|
private $channel; |
|
39
|
|
|
private $exchange; |
|
40
|
|
|
private $queue; |
|
41
|
|
|
private $basic; |
|
42
|
|
|
private $transaction; |
|
43
|
|
|
|
|
44
|
238 |
|
public function __construct(ArgumentTranslator $translator) |
|
45
|
|
|
{ |
|
46
|
238 |
|
$this->version = new Version(0, 9, 1); |
|
47
|
238 |
|
$this->read = new Reader; |
|
48
|
238 |
|
$this->connection = new Connection; |
|
49
|
238 |
|
$this->channel = new Channel; |
|
50
|
238 |
|
$this->exchange = new Exchange($translator); |
|
51
|
238 |
|
$this->queue = new Queue($translator); |
|
52
|
238 |
|
$this->basic = new Basic($translator); |
|
53
|
238 |
|
$this->transaction = new Transaction; |
|
54
|
238 |
|
} |
|
55
|
|
|
|
|
56
|
92 |
|
public function version(): Version |
|
57
|
|
|
{ |
|
58
|
92 |
|
return $this->version; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
8 |
|
public function use(Version $version): ProtocolInterface |
|
62
|
|
|
{ |
|
63
|
8 |
|
if (!$version->compatibleWith($this->version)) { |
|
64
|
4 |
|
throw new VersionNotUsable($version); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
4 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
92 |
|
public function read(Method $method, Readable $arguments): StreamInterface |
|
74
|
|
|
{ |
|
75
|
92 |
|
return ($this->read)($method, $arguments); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
36 |
|
public function readHeader(Readable $payload): StreamInterface |
|
82
|
|
|
{ |
|
83
|
36 |
|
$chunk = new ChunkArguments( |
|
84
|
36 |
|
UnsignedLongLongInteger::class, |
|
85
|
36 |
|
UnsignedShortInteger::class |
|
86
|
|
|
); |
|
87
|
36 |
|
[$bodySize, $flags] = $chunk($payload); |
|
88
|
|
|
|
|
89
|
36 |
|
$flagBits = $flags->original()->value(); |
|
90
|
36 |
|
$toChunk = []; |
|
91
|
|
|
|
|
92
|
36 |
|
if ($flagBits & (1 << 15)) { |
|
93
|
6 |
|
$toChunk[] = ShortString::class; //content type |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
36 |
|
if ($flagBits & (1 << 14)) { |
|
97
|
6 |
|
$toChunk[] = ShortString::class; //content encoding |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
36 |
|
if ($flagBits & (1 << 13)) { |
|
101
|
6 |
|
$toChunk[] = Table::class; //headers |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
36 |
|
if ($flagBits & (1 << 12)) { |
|
105
|
6 |
|
$toChunk[] = UnsignedOctet::class; //delivery mode |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
36 |
|
if ($flagBits & (1 << 11)) { |
|
109
|
6 |
|
$toChunk[] = UnsignedOctet::class; //priority |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
36 |
|
if ($flagBits & (1 << 10)) { |
|
113
|
6 |
|
$toChunk[] = ShortString::class; //correlation id |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
36 |
|
if ($flagBits & (1 << 9)) { |
|
117
|
6 |
|
$toChunk[] = ShortString::class; //reply to |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
36 |
|
if ($flagBits & (1 << 8)) { |
|
121
|
6 |
|
$toChunk[] = ShortString::class; //expiration |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
36 |
|
if ($flagBits & (1 << 7)) { |
|
125
|
6 |
|
$toChunk[] = ShortString::class; //id |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
36 |
|
if ($flagBits & (1 << 6)) { |
|
129
|
6 |
|
$toChunk[] = Timestamp::class; //timestamp |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
36 |
|
if ($flagBits & (1 << 5)) { |
|
133
|
6 |
|
$toChunk[] = ShortString::class; //type |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
36 |
|
if ($flagBits & (1 << 4)) { |
|
137
|
6 |
|
$toChunk[] = ShortString::class; //user id |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
36 |
|
if ($flagBits & (1 << 3)) { |
|
141
|
6 |
|
$toChunk[] = ShortString::class; //app id |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
36 |
|
return Stream::of( |
|
145
|
36 |
|
Value::class, |
|
146
|
36 |
|
$bodySize, |
|
147
|
36 |
|
$flags, |
|
148
|
36 |
|
...(new ChunkArguments(...$toChunk))($payload) |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
196 |
|
public function method(string $name): Method |
|
153
|
|
|
{ |
|
154
|
196 |
|
return Methods::get($name); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
92 |
|
public function connection(): ConnectionInterface |
|
158
|
|
|
{ |
|
159
|
92 |
|
return $this->connection; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
86 |
|
public function channel(): ChannelInterface |
|
163
|
|
|
{ |
|
164
|
86 |
|
return $this->channel; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
6 |
|
public function exchange(): ExchangeInterface |
|
168
|
|
|
{ |
|
169
|
6 |
|
return $this->exchange; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
50 |
|
public function queue(): QueueInterface |
|
173
|
|
|
{ |
|
174
|
50 |
|
return $this->queue; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
48 |
|
public function basic(): BasicInterface |
|
178
|
|
|
{ |
|
179
|
48 |
|
return $this->basic; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
8 |
|
public function transaction(): TransactionInterface |
|
183
|
|
|
{ |
|
184
|
8 |
|
return $this->transaction; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|