FrameSerializerTrait   F
last analyzed

Complexity

Total Complexity 67

Size/Duplication

Total Lines 395
Duplicated Lines 45.82 %

Coupling/Cohesion

Components 1
Dependencies 38

Importance

Changes 0
Metric Value
dl 181
loc 395
rs 3.04
c 0
b 0
f 0
wmc 67
lcom 1
cbo 38

2 Methods

Rating   Name   Duplication   Size   Complexity  
F serialize() 181 374 66
A packX01Payload() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like FrameSerializerTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FrameSerializerTrait, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Serializer;
4
5
use PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPProtocolException;
6
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Access;
7
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Basic;
8
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\BodyFrame;
9
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Channel;
10
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Confirm;
11
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Connection;
12
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Exchange;
13
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\HeartbeatFrame;
14
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\OutgoingFrame;
15
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Queue;
16
use PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Protocol\Tx;
17
18
/**
19
 * Class FrameSerializerTrait
20
 *
21
 * @property TableInterface tableSerializer
22
 * @author Aleksey I. Kuleshov YOU GLOBAL LIMITED
23
 * @package PHPDaemon\Clients\AMQP\Driver\Protocol\v091\Serializer
24
 */
25
trait FrameSerializerTrait
26
{
27
    use ScalarSerializerTrait;
28
29
    /**
30
     * @param OutgoingFrame $frame
31
     * @return string
32
     * @throws \PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPProtocolException
33
     * @throws \InvalidArgumentException
34
     */
35
    public function serialize(OutgoingFrame $frame)
36
    {
37
38
        switch (true) {
39
            case $frame instanceof HeartbeatFrame:
40
                return "\x08\x00\x00\x00\x00\x00\x00\xce";
41
42
            case $frame instanceof BodyFrame:
43
                return "\x03" . \pack('nN', $frame->frameChannelId, \strlen($frame->content)) . $frame->content . "\xce";
44
45
            case $frame instanceof Connection\ConnectionStartOkFrame:
46
                $payload = "\x00\x0a\x00\x0b"
47
                    . $this->tableSerializer->serialize($frame->clientProperties)
48
                    . $this->serializeShortString($frame->mechanism)
49
                    . $this->serializeLongString($frame->response)
50
                    . $this->serializeShortString($frame->locale);
51
52
                return $this->packX01Payload($frame, $payload);
53
54
            case $frame instanceof Connection\ConnectionSecureOkFrame:
55
                $payload = "\x00\x0a\x00\x15"
56
                    . $this->serializeLongString($frame->response);
57
                return $this->packX01Payload($frame, $payload);
58
59
            case $frame instanceof Connection\ConnectionTuneOkFrame:
60
                $payload = "\x00\x0a\x00\x1f"
61
                    . \pack('nNn', $frame->channelMax, $frame->frameMax, $frame->heartbeat);
62
                return $this->packX01Payload($frame, $payload);
63
64
            case $frame instanceof Connection\ConnectionOpenFrame:
65
                $payload = "\x00\x0a\x00\x28"
66
                    . $this->serializeShortString($frame->virtualHost)
67
                    . $this->serializeShortString($frame->capabilities)
68
                    . ($frame->insist ? "\x01" : "\x00");
69
70
                return $this->packX01Payload($frame, $payload);
71
72 View Code Duplication
            case $frame instanceof Connection\ConnectionCloseFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
                $payload = "\x00\x0a\x00\x32"
74
                    . \pack('n', $frame->replyCode)
75
                    . $this->serializeShortString($frame->replyText)
76
                    . \pack('nn', $frame->classId, $frame->methodId);
77
78
                return $this->packX01Payload($frame, $payload);
79
80
            case $frame instanceof Connection\ConnectionCloseOkFrame:
81
                return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x0a\x00\x33\xce";
82
83
            case $frame instanceof Channel\ChannelOpenFrame:
84
                $payload = "\x00\x14\x00\x0a"
85
                    . $this->serializeShortString($frame->outOfBand);
86
87
                return $this->packX01Payload($frame, $payload);
88
89 View Code Duplication
            case $frame instanceof Channel\ChannelFlowFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
                $payload = "\x00\x14\x00\x14"
91
                    . ($frame->active ? "\x01" : "\x00");
92
93
                return $this->packX01Payload($frame, $payload);
94
95 View Code Duplication
            case $frame instanceof Channel\ChannelFlowOkFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
                $payload = "\x00\x14\x00\x15"
97
                    . ($frame->active ? "\x01" : "\x00");
98
99
                return $this->packX01Payload($frame, $payload);
100
101 View Code Duplication
            case $frame instanceof Channel\ChannelCloseFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
                $payload = "\x00\x14\x00\x28"
103
                    . \pack('n', $frame->replyCode)
104
                    . $this->serializeShortString($frame->replyText)
105
                    . \pack('nn', $frame->classId, $frame->methodId);
106
107
                return $this->packX01Payload($frame, $payload);
108
109
            case $frame instanceof Channel\ChannelCloseOkFrame:
110
                return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x14\x00\x29\xce";
111
112
            case $frame instanceof Access\AccessRequestFrame:
113
                $payload = "\x00\x1e\x00\x0a"
114
                    . $this->serializeShortString($frame->realm)
115
                    . \chr(
116
                        $frame->exclusive
117
                        | $frame->passive << 1
118
                        | $frame->active << 2
119
                        | $frame->write << 3
120
                        | $frame->read << 4
121
                    );
122
123
                return $this->packX01Payload($frame, $payload);
124
125 View Code Duplication
            case $frame instanceof Exchange\ExchangeDeclareFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
                $payload = "\x00\x28\x00\x0a"
127
                    . \pack('n', $frame->reserved1)
128
                    . $this->serializeShortString($frame->exchange)
129
                    . $this->serializeShortString($frame->type)
130
                    . \chr(
131
                        $frame->passive
132
                        | $frame->durable << 1
133
                        | $frame->autoDelete << 2
134
                        | $frame->internal << 3
135
                        | $frame->nowait << 4
136
                    )
137
                    . $this->tableSerializer->serialize($frame->arguments);
138
139
                return $this->packX01Payload($frame, $payload);
140
141 View Code Duplication
            case $frame instanceof Exchange\ExchangeDeleteFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
                $payload = "\x00\x28\x00\x14"
143
                    . \pack('n', $frame->reserved1)
144
                    . $this->serializeShortString($frame->exchange)
145
                    . \chr(
146
                        $frame->ifUnused
147
                        | $frame->nowait << 1
148
                    );
149
150
                return $this->packX01Payload($frame, $payload);
151
152 View Code Duplication
            case $frame instanceof Exchange\ExchangeBindFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
                $payload = "\x00\x28\x00\x1e"
154
                    . \pack('n', $frame->reserved1)
155
                    . $this->serializeShortString($frame->destination)
156
                    . $this->serializeShortString($frame->source)
157
                    . $this->serializeShortString($frame->routingKey)
158
                    . ($frame->nowait ? "\x01" : "\x00")
159
                    . $this->tableSerializer->serialize($frame->arguments);
160
161
                return $this->packX01Payload($frame, $payload);
162
163 View Code Duplication
            case $frame instanceof Exchange\ExchangeUnbindFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
                $payload = "\x00\x28\x00\x28"
165
                    . \pack('n', $frame->reserved1)
166
                    . $this->serializeShortString($frame->destination)
167
                    . $this->serializeShortString($frame->source)
168
                    . $this->serializeShortString($frame->routingKey)
169
                    . ($frame->nowait ? "\x01" : "\x00")
170
                    . $this->tableSerializer->serialize($frame->arguments);
171
172
                return $this->packX01Payload($frame, $payload);
173
174 View Code Duplication
            case $frame instanceof Queue\QueueDeclareFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
                $payload = "\x00\x32\x00\x0a"
176
                    . \pack('n', $frame->reserved1)
177
                    . $this->serializeShortString($frame->queue)
178
                    . \chr(
179
                        $frame->passive
180
                        | $frame->durable << 1
181
                        | $frame->exclusive << 2
182
                        | $frame->autoDelete << 3
183
                        | $frame->nowait << 4
184
                    )
185
                    . $this->tableSerializer->serialize($frame->arguments);
186
187
                return $this->packX01Payload($frame, $payload);
188
189 View Code Duplication
            case $frame instanceof Queue\QueueBindFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
190
                $payload = "\x00\x32\x00\x14"
191
                    . \pack('n', $frame->reserved1)
192
                    . $this->serializeShortString($frame->queue)
193
                    . $this->serializeShortString($frame->exchange)
194
                    . $this->serializeShortString($frame->routingKey)
195
                    . ($frame->nowait ? "\x01" : "\x00")
196
                    . $this->tableSerializer->serialize($frame->arguments);
197
198
                return $this->packX01Payload($frame, $payload);
199
200 View Code Duplication
            case $frame instanceof Queue\QueuePurgeFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
201
                $payload = "\x00\x32\x00\x1e"
202
                    . \pack('n', $frame->reserved1)
203
                    . $this->serializeShortString($frame->queue)
204
                    . ($frame->nowait ? "\x01" : "\x00");
205
206
                return $this->packX01Payload($frame, $payload);
207
208 View Code Duplication
            case $frame instanceof Queue\QueueDeleteFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
                $payload = "\x00\x32\x00\x28"
210
                    . \pack('n', $frame->reserved1)
211
                    . $this->serializeShortString($frame->queue)
212
                    . \chr(
213
                        $frame->ifUnused
214
                        | $frame->ifEmpty << 1
215
                        | $frame->nowait << 2
216
                    );
217
218
                return $this->packX01Payload($frame, $payload);
219
220 View Code Duplication
            case $frame instanceof Queue\QueueUnbindFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
221
                $payload = "\x00\x32\x00\x32"
222
                    . \pack('n', $frame->reserved1)
223
                    . $this->serializeShortString($frame->queue)
224
                    . $this->serializeShortString($frame->exchange)
225
                    . $this->serializeShortString($frame->routingKey)
226
                    . $this->tableSerializer->serialize($frame->arguments);
227
228
                return $this->packX01Payload($frame, $payload);
229
230
            case $frame instanceof Basic\BasicHeaderFrame:
231
                $flags = 0;
232
                $properties = '';
233
234
                if (null !== $frame->contentType) {
235
                    $flags |= 32768;
236
                    $properties .= $this->serializeShortString($frame->contentType);
237
                }
238
239
                if (null !== $frame->contentEncoding) {
240
                    $flags |= 16384;
241
                    $properties .= $this->serializeShortString($frame->contentEncoding);
242
                }
243
244
                if (null !== $frame->headers) {
245
                    $flags |= 8192;
246
                    $properties .= $this->tableSerializer->serialize($frame->headers);
247
                }
248
249 View Code Duplication
                if (null !== $frame->deliveryMode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
                    $flags |= 4096;
251
                    $properties .= \pack('c', $frame->deliveryMode);
252
                }
253
254 View Code Duplication
                if (null !== $frame->priority) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
255
                    $flags |= 2048;
256
                    $properties .= \pack('c', $frame->priority);
257
                }
258
259
                if (null !== $frame->correlationId) {
260
                    $flags |= 1024;
261
                    $properties .= $this->serializeShortString($frame->correlationId);
262
                }
263
264
                if (null !== $frame->replyTo) {
265
                    $flags |= 512;
266
                    $properties .= $this->serializeShortString($frame->replyTo);
267
                }
268
269
                if (null !== $frame->expiration) {
270
                    $flags |= 256;
271
                    $properties .= $this->serializeShortString($frame->expiration);
272
                }
273
274
                if (null !== $frame->messageId) {
275
                    $flags |= 128;
276
                    $properties .= $this->serializeShortString($frame->messageId);
277
                }
278
279
                if (null !== $frame->timestamp) {
280
                    $flags |= 64;
281
                    $properties .= \pack('J', $frame->timestamp);
282
                }
283
284
                if (null !== $frame->type) {
285
                    $flags |= 32;
286
                    $properties .= $this->serializeShortString($frame->type);
287
                }
288
289
                if (null !== $frame->userId) {
290
                    $flags |= 16;
291
                    $properties .= $this->serializeShortString($frame->userId);
292
                }
293
294
                if (null !== $frame->appId) {
295
                    $flags |= 8;
296
                    $properties .= $this->serializeShortString($frame->appId);
297
                }
298
299
                if (null !== $frame->clusterId) {
300
                    $flags |= 4;
301
                    $properties .= $this->serializeShortString($frame->clusterId);
302
                }
303
304
                $payload = "\x00\x3c\x00\x00"
305
                    . \pack('Jn', $frame->contentLength, $flags)
306
                    . $properties;
307
308
                return "\x02" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce";
309
310
            case $frame instanceof Basic\BasicQosFrame:
311
                $payload = "\x00\x3c\x00\x0a"
312
                    . \pack('Nn', $frame->prefetchSize, $frame->prefetchCount)
313
                    . ($frame->global ? "\x01" : "\x00");
314
315
                return $this->packX01Payload($frame, $payload);
316
317 View Code Duplication
            case $frame instanceof Basic\BasicConsumeFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
318
                $payload = "\x00\x3c\x00\x14"
319
                    . \pack('n', $frame->reserved1)
320
                    . $this->serializeShortString($frame->queue)
321
                    . $this->serializeShortString($frame->consumerTag)
322
                    . \chr(
323
                        $frame->noLocal
324
                        | $frame->noAck << 1
325
                        | $frame->exclusive << 2
326
                        | $frame->nowait << 3
327
                    )
328
                    . $this->tableSerializer->serialize($frame->arguments);
329
330
                return $this->packX01Payload($frame, $payload);
331
332
            case $frame instanceof Basic\BasicCancelFrame:
333
                $payload = "\x00\x3c\x00\x1e"
334
                    . $this->serializeShortString($frame->consumerTag)
335
                    . ($frame->nowait ? "\x01" : "\x00");
336
337
                return $this->packX01Payload($frame, $payload);
338
339 View Code Duplication
            case $frame instanceof Basic\BasicPublishFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
340
                $payload = "\x00\x3c\x00\x28"
341
                    . \pack('n', $frame->reserved1)
342
                    . $this->serializeShortString($frame->exchange)
343
                    . $this->serializeShortString($frame->routingKey)
344
                    . \chr(
345
                        $frame->mandatory
346
                        | $frame->immediate << 1
347
                    );
348
349
                return $this->packX01Payload($frame, $payload);
350
351 View Code Duplication
            case $frame instanceof Basic\BasicGetFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
352
                $payload = "\x00\x3c\x00\x46"
353
                    . \pack('n', $frame->reserved1)
354
                    . $this->serializeShortString($frame->queue)
355
                    . ($frame->noAck ? "\x01" : "\x00");
356
357
                return $this->packX01Payload($frame, $payload);
358
359 View Code Duplication
            case $frame instanceof Basic\BasicAckFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360
                $payload = "\x00\x3c\x00\x50"
361
                    . \pack('J', $frame->deliveryTag)
362
                    . ($frame->multiple ? "\x01" : "\x00");
363
364
                return $this->packX01Payload($frame, $payload);
365
366 View Code Duplication
            case $frame instanceof Basic\BasicRejectFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
367
                $payload = "\x00\x3c\x00\x5a"
368
                    . \pack('J', $frame->deliveryTag)
369
                    . ($frame->requeue ? "\x01" : "\x00");
370
371
                return $this->packX01Payload($frame, $payload);
372
373
            case $frame instanceof Basic\BasicRecoverFrame:
374
                $payload = "\x00\x3c\x00\x6e"
375
                    . ($frame->requeue ? "\x01" : "\x00");
376
377
                return $this->packX01Payload($frame, $payload);
378
379 View Code Duplication
            case $frame instanceof Basic\BasicNackFrame:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
380
                $payload = "\x00\x3c\x00\x78"
381
                    . \pack('J', $frame->deliveryTag)
382
                    . \chr(
383
                        $frame->multiple
384
                        | $frame->requeue << 1
385
                    );
386
387
                return $this->packX01Payload($frame, $payload);
388
389
            case $frame instanceof Tx\TxSelectFrame:
390
                return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x5a\x00\x0a\xce";
391
392
            case $frame instanceof Tx\TxCommitFrame:
393
                return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x5a\x00\x14\xce";
394
395
            case $frame instanceof Tx\TxRollbackFrame:
396
                return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x5a\x00\x1e\xce";
397
398
            case $frame instanceof Confirm\ConfirmSelectFrame:
399
                $payload = "\x00\x55\x00\x0a"
400
                    . ($frame->nowait ? "\x01" : "\x00");
401
402
                return $this->packX01Payload($frame, $payload);
403
404
        }
405
406
        throw new AMQPProtocolException(
407
            sprintf('Frame %s not implemented yet', get_class($frame)));
408
    }
409
410
    /**
411
     * @param $frame
412
     * @param string $payload
413
     * @return string
414
     */
415
    public function packX01Payload($frame, $payload)
416
    {
417
        return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce";
418
    }
419
}
420