1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace unreal4u\MQTT\Protocol; |
6
|
|
|
|
7
|
|
|
use OutOfRangeException; |
8
|
|
|
use unreal4u\MQTT\Internals\ClientInterface; |
9
|
|
|
use unreal4u\MQTT\Internals\PacketIdentifierFunctionality; |
10
|
|
|
use unreal4u\MQTT\Internals\ProtocolBase; |
11
|
|
|
use unreal4u\MQTT\Internals\ReadableContent; |
12
|
|
|
use unreal4u\MQTT\Internals\ReadableContentInterface; |
13
|
|
|
use unreal4u\MQTT\Internals\WritableContent; |
14
|
|
|
use unreal4u\MQTT\Internals\WritableContentInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A PUBACK Packet is the response to a PUBLISH Packet with QoS level 1. |
18
|
|
|
* |
19
|
|
|
* QoS lvl1: |
20
|
|
|
* First packet: PUBLISH |
21
|
|
|
* Second packet: PUBACK |
22
|
|
|
* |
23
|
|
|
* @see https://go.gliffy.com/go/publish/12498076 |
24
|
|
|
*/ |
25
|
|
|
final class PubAck extends ProtocolBase implements ReadableContentInterface, WritableContentInterface |
26
|
|
|
{ |
27
|
|
|
use ReadableContent; |
28
|
|
|
use /** @noinspection TraitsPropertiesConflictsInspection */ |
29
|
|
|
WritableContent; |
30
|
|
|
use PacketIdentifierFunctionality; |
31
|
|
|
|
32
|
|
|
private const CONTROL_PACKET_VALUE = 4; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $rawMQTTHeaders |
36
|
|
|
* @param ClientInterface $client |
37
|
|
|
* @return ReadableContentInterface |
38
|
|
|
* @throws OutOfRangeException |
39
|
|
|
*/ |
40
|
1 |
|
public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface |
41
|
|
|
{ |
42
|
1 |
|
$this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders); |
43
|
1 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
* @throws OutOfRangeException |
49
|
|
|
*/ |
50
|
1 |
|
public function createVariableHeader(): string |
51
|
|
|
{ |
52
|
1 |
|
return $this->getPacketIdentifierBinaryRepresentation(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Creates the actual payload to be sent |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
1 |
|
public function createPayload(): string |
60
|
|
|
{ |
61
|
1 |
|
return ''; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
*/ |
67
|
1 |
|
public function expectAnswer(string $brokerBitStream, ClientInterface $client): ReadableContentInterface |
68
|
|
|
{ |
69
|
1 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Some responses won't expect an answer back, others do in some situations |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
1 |
|
public function shouldExpectAnswer(): bool |
77
|
|
|
{ |
78
|
1 |
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
|
|
public function getOriginControlPacket(): int |
85
|
|
|
{ |
86
|
|
|
return Publish::getControlPacketValue(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|