class documentation

class MQTTPacketOut:

Constructor: MQTTPacketOut(pkt_type, flags)

View In Hierarchy

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_byte Add a byte to the packet
Method add_payload Add a payload to the packet
Method add_str Add a string to the packet
Method add_uint16 Add a 16 bit unsigned integer to the packet
Async Method write_buff Write the complete packet
Instance Variable _buffer Undocumented
Instance Variable _header Undocumented
def __init__(self, pkt_type, flags=0):

Construct MQTT Control Packet out

Set up first byte as control packet type and flags. Initialise second byte (length) to 0

Parameters
pkt_typeMQTT Control Packet type
flagsPacket control flags
def add_byte(self, b):

Add a byte to the packet

Parameters
bthe byte to add to the packet
def add_payload(self, s):

Add a payload to the packet

The payload is added as a UTF-8 encoded byte string.

Parameters
sthe payload to add to the packet
def add_str(self, s):

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
sthe string to add to the packet
def add_uint16(self, i):

Add a 16 bit unsigned integer to the packet

Parameters
ithe integer to add to the packet
async def write_buff(self, writer):

Write the complete packet

The first byte is the control packet type and flags, the following bytes are the remaining length of the packet.

See MQTT spec 2.2.3 for remaining length bytes generation psuedo code.

Parameters
writerthe write stream
Returns
True if write successful else False
_buffer =

Undocumented

_header =

Undocumented