Beispiel #1
0
 def parseHeader(header):
     byte1 = upackHex(header[0])
     t = unhexlify(hex((byte1 & 0xf0) >> 4)[2:].zfill(2))
     dub = (byte1 & 0x08) >> 3
     qos = (byte1 & 0x06) >> 1
     retain = byte1 & 0x01
     restLen, idx = decodeRestLen([upackHex(x) for x in header[1:]])
     return t, dub, qos, retain, restLen, idx+1
Beispiel #2
0
 def parseHeader(header):
     byte1 = upackHex(header[0])
     t = unhexlify(hex((byte1 & 0xf0) >> 4)[2:].zfill(2))
     dub = (byte1 & 0x08) >> 3
     qos = (byte1 & 0x06) >> 1
     retain = byte1 & 0x01
     restLen, idx = decodeRestLen([upackHex(x) for x in header[1:]])
     return t, dub, qos, retain, restLen, idx + 1
Beispiel #3
0
 def subscribe(data):
     self.idx += 2
     messageID = upackHex(data[:self.idx])
     topics = []
     allowedQoSs = []
     while data[self.idx:]:
         topic = self.getIncrement(data[self.idx:])
         reqQoS = upackHex(data[self.idx])
         topics.append(topic)
         allowedQoSs.append(reqQoS)
         self.idx += 1
     return messageID, topics, allowedQoSs
Beispiel #4
0
 def subscribe(data):
     self.idx += 2
     messageID = upackHex(data[:self.idx])
     topics = []
     allowedQoSs = []
     while data[self.idx:]:
         topic = self.getIncrement(data[self.idx:])
         reqQoS = upackHex(data[self.idx])
         topics.append(topic)
         allowedQoSs.append(reqQoS)
         self.idx += 1
     return messageID, topics, allowedQoSs
Beispiel #5
0
 def publish(data):
     topic = self.getIncrement(data)
     messageID = 1
     if 1 <= qos <= 2:
         messageID = upackHex(data[self.idx:self.idx + 2])
     pubData = self.getIncrement(data[self.idx:]) if len(data[self.idx:]) else ""
     return messageID, qos, topic, pubData
Beispiel #6
0
 def unsubscribe(data):
     self.idx += 2
     messageID = upackHex(data[:self.idx])
     topics = []
     while data[self.idx:]:
         topic = self.getIncrement(data[self.idx:])
         topics.append(topic)
     return messageID, topics
Beispiel #7
0
        def connect(data):
            proto = self.getIncrement(data)
            protoVersion = upackHex(data[self.idx])
            flags = upackHex(data[self.idx + 1])
            keepAlive = upackHex(data[self.idx + 2:self.idx + 4])

            self.idx += 4
            cliId = self.getIncrement(data[self.idx:])
            will = {"QoS": (flags & 0x18) >> 3, "retain": (flags & 0x20) >> 5, "topic": "", "message": ""}
            if flags & 0x04:
                will["topic"] = self.getIncrement(data[self.idx:])
                will["message"] = self.getIncrement(data[self.idx:])
            name = self.getIncrement(data[self.idx:]) if flags & 0x80 else ""
            passwd = self.getIncrement(data[self.idx:]) if flags & 0x40 else ""
            clean = flags & 0x02

            return cliId, name, passwd, will, keepAlive, clean
Beispiel #8
0
 def unsubscribe(data):
     self.idx += 2
     messageID = upackHex(data[:self.idx])
     topics = []
     while data[self.idx:]:
         topic = self.getIncrement(data[self.idx:])
         topics.append(topic)
     return messageID, topics
Beispiel #9
0
 def publish(data):
     topic = self.getIncrement(data)
     messageID = 1
     if 1 <= qos <= 2:
         messageID = upackHex(data[self.idx:self.idx + 2])
     pubData = self.getIncrement(data[self.idx:]) if len(
         data[self.idx:]) else ""
     return messageID, qos, topic, pubData
Beispiel #10
0
        def connect(data):
            proto = self.getIncrement(data)
            protoVersion = upackHex(data[self.idx])
            flags = upackHex(data[self.idx + 1])
            keepAlive = upackHex(data[self.idx + 2:self.idx + 4])

            self.idx += 4
            cliId = self.getIncrement(data[self.idx:])
            will = {
                "QoS": (flags & 0x18) >> 3,
                "retain": (flags & 0x20) >> 5,
                "topic": "",
                "message": ""
            }
            if flags & 0x04:
                will["topic"] = self.getIncrement(data[self.idx:])
                will["message"] = self.getIncrement(data[self.idx:])
            name = self.getIncrement(data[self.idx:]) if flags & 0x80 else ""
            passwd = self.getIncrement(data[self.idx:]) if flags & 0x40 else ""
            clean = flags & 0x02

            return cliId, name, passwd, will, keepAlive, clean
Beispiel #11
0
 def unsuback(data):
     messageID = upackHex(data[:2])
     return messageID
Beispiel #12
0
 def suback(data):
     messageID = upackHex(data[:2])
     allowedQoSs = []
     for q in data[2:]:
         allowedQoSs.append(upackHex(q))
     return messageID, allowedQoSs
Beispiel #13
0
 def pubcomp(data):
     messageID = upackHex(data[:2])
     return messageID
Beispiel #14
0
 def pubrel(data):
     messageID = upackHex(data[:2])
     return messageID
Beispiel #15
0
 def unsuback(data):
     messageID = upackHex(data[:2])
     return messageID
Beispiel #16
0
 def suback(data):
     messageID = upackHex(data[:2])
     allowedQoSs = []
     for q in data[2:]:
         allowedQoSs.append(upackHex(q))
     return messageID, allowedQoSs
Beispiel #17
0
 def pubcomp(data):
     messageID = upackHex(data[:2])
     return messageID
Beispiel #18
0
 def pubrel(data):
     messageID = upackHex(data[:2])
     return messageID