MQTT Control Packet Out
This class is used to construct MQTT control packets to be sent to the broker. It provides methods to add bytes, strings and payloads to the packet. The packet is constructed as a bytearray and the write method sends the complete packet. The first byte is the control packet type and flags, the following bytes hold the remaining packet length. The remaining length is calculated as the number of bytes in the packet excluding the control byte and length bytes. The packet is constructed in the order of the MQTT protocol specification.
| Method | __init__ |
Construct MQTT Control Packet out |
| Method | add |
Add a byte to the packet |
| Method | add |
Add a payload to the packet |
| Method | add |
Add a string to the packet |
| Method | add |
Add a 16 bit unsigned integer to the packet |
| Async Method | write |
Write the complete packet |
| Instance Variable | _buffer |
Undocumented |
| Instance Variable | _header |
Undocumented |
Construct MQTT Control Packet out
Set up first byte as control packet type and flags. Initialise second byte (length) to 0
| Parameters | |
| pkt | MQTT Control Packet type |
| flags | Packet control flags |
Add a payload to the packet
The payload is added as a UTF-8 encoded byte string.
| Parameters | |
| s | the payload to add to the packet |
Add a string to the packet
The string is added as a UTF-8 encoded byte string. The length of the string is added as a 16 bit unsigned integer.
| Parameters | |
| s | the string to add to the packet |