1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace unreal4u\MQTT\Protocol; |
6
|
|
|
|
7
|
|
|
use LogicException; |
8
|
|
|
use OutOfRangeException; |
9
|
|
|
use unreal4u\MQTT\Application\EmptyReadableResponse; |
10
|
|
|
use unreal4u\MQTT\Internals\ClientInterface; |
11
|
|
|
use unreal4u\MQTT\Internals\PacketIdentifierFunctionality; |
12
|
|
|
use unreal4u\MQTT\Internals\ProtocolBase; |
13
|
|
|
use unreal4u\MQTT\Internals\ReadableContent; |
14
|
|
|
use unreal4u\MQTT\Internals\ReadableContentInterface; |
15
|
|
|
use unreal4u\MQTT\Internals\WritableContent; |
16
|
|
|
use unreal4u\MQTT\Internals\WritableContentInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The PUBCOMP Packet is the response to a PUBREL Packet. |
20
|
|
|
* |
21
|
|
|
* It is the fourth and final packet of the QoS 2 protocol exchange. |
22
|
|
|
* |
23
|
|
|
* QoS lvl2: |
24
|
|
|
* First packet: PUBLISH |
25
|
|
|
* Second packet: PUBREC |
26
|
|
|
* Third packet: PUBREL |
27
|
|
|
* Fourth packet: PUBCOMP |
28
|
|
|
* |
29
|
|
|
* @see https://go.gliffy.com/go/publish/12498076 |
30
|
|
|
*/ |
31
|
|
|
final class PubComp extends ProtocolBase implements ReadableContentInterface, WritableContentInterface |
32
|
|
|
{ |
33
|
1 |
|
use ReadableContent; |
34
|
|
|
use /** @noinspection TraitsPropertiesConflictsInspection */ |
35
|
1 |
|
WritableContent; |
36
|
1 |
|
use PacketIdentifierFunctionality; |
37
|
|
|
|
38
|
|
|
private const CONTROL_PACKET_VALUE = 7; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $rawMQTTHeaders |
42
|
|
|
* @param ClientInterface $client |
43
|
|
|
* @return ReadableContentInterface |
44
|
|
|
* @throws OutOfRangeException |
45
|
|
|
*/ |
46
|
2 |
|
public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface |
47
|
|
|
{ |
48
|
2 |
|
$this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders); |
49
|
2 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
* @throws LogicException |
55
|
|
|
*/ |
56
|
2 |
|
public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool |
57
|
|
|
{ |
58
|
2 |
|
return $this->controlPacketIdentifiers($originalRequest); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Creates the variable header that each method has |
63
|
|
|
* @return string |
64
|
|
|
* @throws OutOfRangeException |
65
|
|
|
*/ |
66
|
1 |
|
public function createVariableHeader(): string |
67
|
|
|
{ |
68
|
1 |
|
return $this->getPacketIdentifierBinaryRepresentation(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Creates the actual payload to be sent |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
1 |
|
public function createPayload(): string |
76
|
|
|
{ |
77
|
1 |
|
return ''; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritdoc |
82
|
|
|
*/ |
83
|
1 |
|
public function expectAnswer(string $brokerBitStream, ClientInterface $client): ReadableContentInterface |
84
|
|
|
{ |
85
|
1 |
|
return new EmptyReadableResponse($this->logger); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Some responses won't expect an answer back, others do in some situations |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
1 |
|
public function shouldExpectAnswer(): bool |
93
|
|
|
{ |
94
|
1 |
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritdoc |
99
|
|
|
*/ |
100
|
1 |
|
public function getOriginControlPacket(): int |
101
|
|
|
{ |
102
|
1 |
|
return PubRel::getControlPacketValue(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|