Mqtt311MessageProcessor
extends Mqtt31MessageProcessor
in package
This message processor implements the MQTT protocol version 3.1.1.
Table of Contents
- QOS_AT_LEAST_ONCE = 1
- QOS_AT_MOST_ONCE = 0
- QOS_EXACTLY_ONCE = 2
- $logger : LoggerInterface
- $clientId : string
- __construct() : mixed
- BaseMessageProcessor constructor.
- buildConnectMessage() : string
- Builds a connect message from the given connection settings, taking the protocol specifics into account.
- buildDisconnectMessage() : string
- Builds a disconnect message.
- buildPingRequestMessage() : string
- Builds a ping request message.
- buildPingResponseMessage() : string
- Builds a ping response message.
- buildPublishAcknowledgementMessage() : string
- Builds a publish acknowledgement for the given message identifier.
- buildPublishCompleteMessage() : string
- Builds a publish complete message for the given message identifier.
- buildPublishMessage() : string
- Builds a publish message based on the given parameters.
- buildPublishReceivedMessage() : string
- Builds a publish received message for the given message identifier.
- buildPublishReleaseMessage() : string
- Builds a publish release message for the given message identifier.
- buildSubscribeMessage() : string
- Builds a subscribe message from the given parameters.
- buildUnsubscribeMessage() : string
- Builds an unsubscribe message from the given parameters.
- handleConnectAcknowledgement() : void
- Handles the connect acknowledgement received from the broker. Exits normally if the connection could be established successfully according to the response. Throws an exception if the broker responded with an error.
- parseAndValidateMessage() : Message|null
- Parses and validates the given message based on its message type and contents.
- tryFindMessageInBuffer() : bool
- Try to parse a message from the incoming buffer. If a message could be parsed successfully, the given message parameter is set to the parsed message and the result is true.
- buildConnectionFlags() : int
- Builds the connection flags from the inputs and settings.
- buildLengthPrefixedString() : string
- Creates a string which is prefixed with its own length as bytes.
- decodeMessageId() : int
- Converts the given string to a number, assuming it is an MSB encoded message id.
- encodeMessageId() : string
- Encodes the given message identifier as string.
- encodeMessageLength() : string
- Encodes the length of a message as string, so it can be transmitted over the wire.
- getEncodedProtocolNameAndVersion() : string
- Returns the encoded protocol name and version, ready to be sent as part of the CONNECT message.
- parseAndValidatePingAcknowledgementMessage() : Message
- Parses a received ping acknowledgement.
- parseAndValidatePingRequestMessage() : Message
- Parses a received ping request.
- parseAndValidatePublishAcknowledgementMessage() : Message
- Parses a received publish acknowledgement. The data contains the whole message except the fixed header with command and length. The message structure is:
- parseAndValidatePublishCompleteMessage() : Message
- Parses a received publish confirmation message. The data contains the whole message except the fixed header with command and length. The message structure is:
- parseAndValidatePublishMessage() : Message|null
- Parses a received published message. The data contains the whole message except the fixed header with command and length. The message structure is:
- parseAndValidatePublishReceiptMessage() : Message
- Parses a received publish receipt. The data contains the whole message except the fixed header with command and length. The message structure is:
- parseAndValidatePublishReleaseMessage() : Message
- Parses a received publish release message. The data contains the whole message except the fixed header with command and length. The message structure is:
- parseAndValidateSubscribeAcknowledgementMessage() : Message
- Parses a received subscription acknowledgement. The data contains the whole message except the fixed header with command and length. The message structure is:
- parseAndValidateUnsubscribeAcknowledgementMessage() : Message
- Parses a received unsubscribe acknowledgement. The data contains the whole message except the fixed header with command and length. The message structure is:
- pop() : string
- Pops the first $limit bytes from the given buffer and returns them.
- tryDecodeMessage() : bool
- Attempt to decode the given message. If successful, the result is true and the reference parameters are set accordingly. Otherwise, false is returned and the reference parameters remain untouched.
- isPublishMessageWithNullCharacter() : bool
- Determines if the given message is a PUBLISH message and contains the unicode null character U+0000.
Constants
QOS_AT_LEAST_ONCE
public
mixed
QOS_AT_LEAST_ONCE
= 1
QOS_AT_MOST_ONCE
public
mixed
QOS_AT_MOST_ONCE
= 0
QOS_EXACTLY_ONCE
public
mixed
QOS_EXACTLY_ONCE
= 2
Properties
$logger
protected
LoggerInterface
$logger
$clientId
private
string
$clientId
Methods
__construct()
BaseMessageProcessor constructor.
public
__construct(LoggerInterface $logger) : mixed
Parameters
- $logger : LoggerInterface
Return values
mixed —buildConnectMessage()
Builds a connect message from the given connection settings, taking the protocol specifics into account.
public
buildConnectMessage(ConnectionSettings $connectionSettings[, bool $useCleanSession = false ]) : string
Parameters
- $connectionSettings : ConnectionSettings
- $useCleanSession : bool = false
Return values
string —buildDisconnectMessage()
Builds a disconnect message.
public
buildDisconnectMessage() : string
Return values
string —buildPingRequestMessage()
Builds a ping request message.
public
buildPingRequestMessage() : string
Return values
string —buildPingResponseMessage()
Builds a ping response message.
public
buildPingResponseMessage() : string
Return values
string —buildPublishAcknowledgementMessage()
Builds a publish acknowledgement for the given message identifier.
public
buildPublishAcknowledgementMessage(int $messageId) : string
Parameters
- $messageId : int
Return values
string —buildPublishCompleteMessage()
Builds a publish complete message for the given message identifier.
public
buildPublishCompleteMessage(int $messageId) : string
Parameters
- $messageId : int
Return values
string —buildPublishMessage()
Builds a publish message based on the given parameters.
public
buildPublishMessage(string $topic, string $message, int $qualityOfService, bool $retain[, int $messageId = null ][, bool $isDuplicate = false ]) : string
Parameters
- $topic : string
- $message : string
- $qualityOfService : int
- $retain : bool
- $messageId : int = null
- $isDuplicate : bool = false
Return values
string —buildPublishReceivedMessage()
Builds a publish received message for the given message identifier.
public
buildPublishReceivedMessage(int $messageId) : string
Parameters
- $messageId : int
Return values
string —buildPublishReleaseMessage()
Builds a publish release message for the given message identifier.
public
buildPublishReleaseMessage(int $messageId) : string
Parameters
- $messageId : int
Return values
string —buildSubscribeMessage()
Builds a subscribe message from the given parameters.
public
buildSubscribeMessage(int $messageId, array<string|int, mixed> $subscriptions[, bool $isDuplicate = false ]) : string
Parameters
- $messageId : int
- $subscriptions : array<string|int, mixed>
- $isDuplicate : bool = false
Return values
string —buildUnsubscribeMessage()
Builds an unsubscribe message from the given parameters.
public
buildUnsubscribeMessage(int $messageId, array<string|int, mixed> $topics[, bool $isDuplicate = false ]) : string
Parameters
- $messageId : int
- $topics : array<string|int, mixed>
- $isDuplicate : bool = false
Return values
string —handleConnectAcknowledgement()
Handles the connect acknowledgement received from the broker. Exits normally if the connection could be established successfully according to the response. Throws an exception if the broker responded with an error.
public
handleConnectAcknowledgement(string $message) : void
Parameters
- $message : string
Return values
void —parseAndValidateMessage()
Parses and validates the given message based on its message type and contents.
public
parseAndValidateMessage(string $message) : Message|null
Parameters
- $message : string
Return values
Message|null —tryFindMessageInBuffer()
Try to parse a message from the incoming buffer. If a message could be parsed successfully, the given message parameter is set to the parsed message and the result is true.
public
tryFindMessageInBuffer(string $buffer, int $bufferLength[, string &$message = null ][, int &$requiredBytes = -1 ]) : bool
Parameters
- $buffer : string
- $bufferLength : int
- $message : string = null
- $requiredBytes : int = -1
Return values
bool —buildConnectionFlags()
Builds the connection flags from the inputs and settings.
protected
buildConnectionFlags(ConnectionSettings $connectionSettings[, bool $useCleanSession = false ]) : int
The bit structure of the connection flags is as follows: 0 - reserved 1 - clean session flag 2 - last will flag 3 - QoS flag (1) 4 - QoS flag (2) 5 - retain last will flag 6 - password flag 7 - username flag
Parameters
- $connectionSettings : ConnectionSettings
- $useCleanSession : bool = false
Tags
Return values
int —buildLengthPrefixedString()
Creates a string which is prefixed with its own length as bytes.
protected
buildLengthPrefixedString(string $data) : string
This means a string like 'hello world' will become
\x00\x0bhello world
where \x00\0x0b is the hex representation of 00000000 00001011 = 11
Parameters
- $data : string
Return values
string —decodeMessageId()
Converts the given string to a number, assuming it is an MSB encoded message id.
protected
decodeMessageId(string $encodedMessageId) : int
MSB means preceding characters have higher value.
Parameters
- $encodedMessageId : string
Return values
int —encodeMessageId()
Encodes the given message identifier as string.
protected
encodeMessageId(int $messageId) : string
Parameters
- $messageId : int
Return values
string —encodeMessageLength()
Encodes the length of a message as string, so it can be transmitted over the wire.
protected
encodeMessageLength(int $length) : string
Parameters
- $length : int
Return values
string —getEncodedProtocolNameAndVersion()
Returns the encoded protocol name and version, ready to be sent as part of the CONNECT message.
protected
getEncodedProtocolNameAndVersion() : string
Return values
string —parseAndValidatePingAcknowledgementMessage()
Parses a received ping acknowledgement.
protected
parseAndValidatePingAcknowledgementMessage() : Message
Return values
Message —parseAndValidatePingRequestMessage()
Parses a received ping request.
protected
parseAndValidatePingRequestMessage() : Message
Return values
Message —parseAndValidatePublishAcknowledgementMessage()
Parses a received publish acknowledgement. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidatePublishAcknowledgementMessage(string $data) : Message
[message-identifier]
Parameters
- $data : string
Tags
Return values
Message —parseAndValidatePublishCompleteMessage()
Parses a received publish confirmation message. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidatePublishCompleteMessage(string $data) : Message
[message-identifier]
Parameters
- $data : string
Tags
Return values
Message —parseAndValidatePublishMessage()
Parses a received published message. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidatePublishMessage(string $data, int $qualityOfServiceLevel) : Message|null
[topic-length:topic:message]+
Parameters
- $data : string
- $qualityOfServiceLevel : int
Return values
Message|null —parseAndValidatePublishReceiptMessage()
Parses a received publish receipt. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidatePublishReceiptMessage(string $data) : Message
[message-identifier]
Parameters
- $data : string
Tags
Return values
Message —parseAndValidatePublishReleaseMessage()
Parses a received publish release message. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidatePublishReleaseMessage(string $data) : Message
[message-identifier]
Parameters
- $data : string
Tags
Return values
Message —parseAndValidateSubscribeAcknowledgementMessage()
Parses a received subscription acknowledgement. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidateSubscribeAcknowledgementMessage(string $data) : Message
Parameters
- $data : string
Return values
Message —parseAndValidateUnsubscribeAcknowledgementMessage()
Parses a received unsubscribe acknowledgement. The data contains the whole message except the fixed header with command and length. The message structure is:
protected
parseAndValidateUnsubscribeAcknowledgementMessage(string $data) : Message
[message-identifier]
Parameters
- $data : string
Tags
Return values
Message —pop()
Pops the first $limit bytes from the given buffer and returns them.
protected
pop(string &$buffer, int $limit) : string
Parameters
- $buffer : string
- $limit : int
Return values
string —tryDecodeMessage()
Attempt to decode the given message. If successful, the result is true and the reference parameters are set accordingly. Otherwise, false is returned and the reference parameters remain untouched.
protected
tryDecodeMessage(string $message[, int|null &$command = null ][, int|null &$qualityOfService = null ][, string|null &$data = null ]) : bool
Parameters
- $message : string
- $command : int|null = null
- $qualityOfService : int|null = null
- $data : string|null = null
Return values
bool —isPublishMessageWithNullCharacter()
Determines if the given message is a PUBLISH message and contains the unicode null character U+0000.
private
isPublishMessageWithNullCharacter(Message $message) : bool
Parameters
- $message : Message