コード例 #1
0
ファイル: Zip.py プロジェクト: pyzwave/pyzwave
 def deserialize(cls, stream: BitStreamReader):
     """Deserialize ZIP Maintenance Report"""
     retval = {}
     while stream.bytesLeft():
         imeType = IMEType(stream.byte())
         length = stream.byte()
         imeVal = stream.value(length)
         typeCls = IME_MAPPING.get(imeType, IMEUnknownValue)
         retval[imeType] = typeCls.load(BitStreamReader(imeVal))
     return retval
コード例 #2
0
ファイル: AssociationGrpInfo.py プロジェクト: pyzwave/pyzwave
 def parse_commandClass(stream: BitStreamReader):  # pylint: disable=invalid-name
     """Parse attribute commandClass"""
     retval = []
     length = stream.byte()
     i = 0
     while i < length:
         commandClass = stream.byte()
         # TODO: Handle command classes with 2 bytes
         command = stream.byte()
         retval.append([commandClass, command])
         i += 2
     return retval
コード例 #3
0
 def deserialize(stream: BitStreamReader):
     """Deserialize a bitstream into a Message object"""
     if stream.bytesLeft() < 2:
         return UnknownMessage(0x0000)
     cmdClass = stream.byte()
     cmd = stream.byte()
     hid = cmdClass << 8 | (cmd & 0xFF)
     MsgCls = ZWaveMessage.get(hid, None)  # pylint: disable=invalid-name
     if MsgCls:
         msg = MsgCls()
         msg.parseAttributes(stream)
     else:
         msg = UnknownMessage(hid)
     return msg
コード例 #4
0
def test_IPv6_t():
    # pylint: disable=line-too-long
    pkt = b"X\x01\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\xa8\x00\xee\xea\xec\xfa\xf9"
    stream = BitStreamReader(pkt)
    assert stream.byte() == 88
    assert stream.byte() == 1
    assert stream.bits(5) == 0
    assert stream.bit() == 0
    assert stream.bits(2) == 0
    assert stream.byte() == 6
    ipv6 = IPv6.deserialize(stream)
    assert ipv6 == ipaddress.ip_address("::ffff:c0a8:ee")
    streamWriter = BitStreamWriter()
    ipv6.serialize(streamWriter)
    assert (
        streamWriter ==
        b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\xa8\x00\xee")
コード例 #5
0
ファイル: NodeProvisioning.py プロジェクト: pyzwave/pyzwave
 def deserialize(cls, stream: BitStreamReader):
     """Deserialize metadata extension"""
     retval = {}
     while stream.bytesLeft():
         metadataType = stream.bits(7)
         _critical = stream.bit()
         length = stream.byte()
         retval[metadataType] = stream.value(length)
     return retval
コード例 #6
0
ファイル: Mailbox.py プロジェクト: pyzwave/pyzwave
 def parse_queueHandle(stream: BitStreamReader):  # pylint: disable=invalid-name
     """Parse queueHandle from raw bitstream"""
     # According to the docs queueHandle should be an uint8_t value
     # just like the other similar messages. But for unknown reason zipgateway
     # sends this like an ipv6 address (at least version 7.11.01)
     print("Node failing", stream.remaining(advance=False))
     if stream.bytesLeft() == 16:
         stream.advance(8 * 15)
     return stream.byte()
コード例 #7
0
ファイル: Zip.py プロジェクト: pyzwave/pyzwave
 def deserialize(cls, stream: BitStreamReader):
     """Deserialize header extension from stream"""
     retval = {}
     extLength = stream.byte() - 1
     reader = BitStreamReader(stream.value(extLength))
     while reader.bytesLeft() > 0:
         option = ZIPPacketOption()
         option.parseAttributes(reader)
         retval[option.optionType] = option.optionData
     return retval
コード例 #8
0
ファイル: Zip.py プロジェクト: pyzwave/pyzwave
 def parse_optionData(self, stream: BitStreamReader):  # pylint: disable=invalid-name
     """Parse attribute optionData"""
     clsType = ZIPPacketOptionData
     length = stream.byte()
     data = stream.value(length)
     if self.optionType == ZIPPacketOptionType.MAINTENANCE_REPORT:
         clsType = ZIPPacketOptionMaintenanceReport
     elif self.optionType == ZIPPacketOptionType.ENCAPSULATION_FORMAT_INFORMATION:
         clsType = ZIPPacketOptionEncapsulationFormatInfo
     elif self.optionType == ZIPPacketOptionType.EXPECTED_DELAY:
         clsType = ZIPPacketOptionExpectedDelay
     cls = clsType()
     if hasattr(cls, "parseAttributes"):
         cls.parseAttributes(BitStreamReader(data))
     elif hasattr(cls, "__setstate__"):
         data = clsType.deserialize(BitStreamReader(data))
         cls.__setstate__(data)
     else:
         value = clsType.deserialize(BitStreamReader(data))
         return clsType(value)
     return cls
コード例 #9
0
def test_BitStreamReader_eof(streamReader: BitStreamReader):
    streamReader.remaining()
    assert streamReader.bytesLeft() == 0
    with pytest.raises(EOFError):
        streamReader.byte()
コード例 #10
0
ファイル: Supervision.py プロジェクト: pyzwave/pyzwave
 def parse_command(stream: BitStreamReader):  # pylint: disable=invalid-name
     """Parse the length prefixed command"""
     length = stream.byte()
     return Message.decode(stream.value(length))