|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace unreal4u\MQTT\Protocol; |
|
6
|
|
|
|
|
7
|
|
|
use unreal4u\MQTT\Application\EmptyReadableResponse; |
|
8
|
|
|
use unreal4u\MQTT\Internals\ClientInterface; |
|
9
|
|
|
use unreal4u\MQTT\Internals\ProtocolBase; |
|
10
|
|
|
use unreal4u\MQTT\Internals\ReadableContent; |
|
11
|
|
|
use unreal4u\MQTT\Internals\ReadableContentInterface; |
|
12
|
|
|
use unreal4u\MQTT\Internals\WritableContent; |
|
13
|
|
|
use unreal4u\MQTT\Internals\WritableContentInterface; |
|
14
|
|
|
use unreal4u\MQTT\Utilities; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The PUBCOMP Packet is the response to a PUBREL Packet. |
|
18
|
|
|
* |
|
19
|
|
|
* It is the fourth and final packet of the QoS 2 protocol exchange. |
|
20
|
|
|
*/ |
|
21
|
|
|
final class PubComp extends ProtocolBase implements ReadableContentInterface, WritableContentInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use ReadableContent, WritableContent; |
|
24
|
|
|
|
|
25
|
|
|
public $packetIdentifier = 0; |
|
26
|
|
|
|
|
27
|
|
|
const CONTROL_PACKET_VALUE = 7; |
|
28
|
|
|
|
|
29
|
|
|
public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface |
|
30
|
|
|
{ |
|
31
|
|
|
$this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders); |
|
32
|
|
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Creates the variable header that each method has |
|
37
|
|
|
* @return string |
|
38
|
|
|
* @throws \OutOfRangeException |
|
39
|
|
|
*/ |
|
40
|
|
|
public function createVariableHeader(): string |
|
41
|
|
|
{ |
|
42
|
|
|
return Utilities::convertNumberToBinaryString($this->packetIdentifier); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Creates the actual payload to be sent |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function createPayload(): string |
|
50
|
|
|
{ |
|
51
|
|
|
// TODO: Implement createPayload() method. |
|
52
|
|
|
return ''; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public function expectAnswer(string $data, ClientInterface $client): ReadableContentInterface |
|
59
|
|
|
{ |
|
60
|
|
|
return new EmptyReadableResponse($this->logger); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Some responses won't expect an answer back, others do in some situations |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function shouldExpectAnswer(): bool |
|
68
|
|
|
{ |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @inheritdoc |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getOriginControlPacket(): int |
|
76
|
|
|
{ |
|
77
|
|
|
return PubRel::getControlPacketValue(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|