1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace unreal4u\MQTT\Protocol; |
6
|
|
|
|
7
|
|
|
use unreal4u\MQTT\Internals\ClientInterface; |
8
|
|
|
use unreal4u\MQTT\Internals\ProtocolBase; |
9
|
|
|
use unreal4u\MQTT\Internals\ReadableContent; |
10
|
|
|
use unreal4u\MQTT\Internals\ReadableContentInterface; |
11
|
|
|
use unreal4u\MQTT\Internals\WritableContent; |
12
|
|
|
use unreal4u\MQTT\Internals\WritableContentInterface; |
13
|
|
|
use unreal4u\MQTT\Utilities; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class PubAck |
17
|
|
|
* @package unreal4u\MQTT\Protocol |
18
|
|
|
*/ |
19
|
|
|
final class PubAck extends ProtocolBase implements ReadableContentInterface, WritableContentInterface |
20
|
|
|
{ |
21
|
|
|
use ReadableContent, WritableContent; |
22
|
|
|
|
23
|
|
|
public $packetIdentifier = 0; |
24
|
|
|
|
25
|
|
|
const CONTROL_PACKET_VALUE = 4; |
26
|
|
|
|
27
|
|
|
public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface |
28
|
|
|
{ |
29
|
|
|
$this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders); |
30
|
|
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
* @throws \LogicException |
36
|
|
|
*/ |
37
|
|
|
public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool |
38
|
|
|
{ |
39
|
|
|
/** @var Publish $originalRequest */ |
40
|
|
|
if ($this->packetIdentifier !== $originalRequest->packetIdentifier) { |
41
|
|
|
throw new \LogicException('Packet identifiers to not match!'); |
42
|
|
|
} |
43
|
|
|
return true; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function createVariableHeader(): string |
47
|
|
|
{ |
48
|
|
|
return Utilities::convertNumberToBinaryString($this->packetIdentifier); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Creates the actual payload to be sent |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function createPayload(): string |
56
|
|
|
{ |
57
|
|
|
return ''; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
|
|
public function expectAnswer(string $data, ClientInterface $client): ReadableContentInterface |
64
|
|
|
{ |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Some responses won't expect an answer back, others do in some situations |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function shouldExpectAnswer(): bool |
73
|
|
|
{ |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|