コード例 #1
0
    def fromBinary(binary, internal=False, offset=None):
        if isinstance(binary, str):
            binary = bytes(binary, "UTF-8")
        packet = EncapsulatedPacket()
        flags = binary[0]
        packet.reliability = (flags & 0b11100000) >> 5
        packet.hasSplit = (flags & 0b00010000) > 0
        if internal:
            length = Binary.readInt(binary[1:5])
            packet.identifierACK = Binary.readInt(binary[5:9])
            offset = 9
        else:
            length = int(Binary.readShort(binary[1:3]) / 8)
            offset = 3
            packet.identifierACK = None

        if packet.reliability > 0:
            if (packet.reliability > 2 or packet.reliability
                    == 2) and packet.reliability is not 5:
                packet.messageIndex = Binary.readLTriad(binary[offset:offset +
                                                               3])
                offset += 3

            if (packet.reliability < 4 or packet.reliability
                    == 4) and packet.reliability is not 2:
                packet.orderIndex = Binary.readLTriad(binary[offset:offset +
                                                             3])
                offset += 3
                packet.orderChannel = Binary.readByte(binary[offset:offset +
                                                             1])
                offset += 1

        if packet.hasSplit:
            packet.splitCount = Binary.readInt(binary[offset:offset + 4])
            offset += 4
            packet.splitID = Binary.readShort(binary[offset:offset + 2])
            offset += 2
            packet.splitIndex = binary.readInt(binary[offset:offset + 4])
            offset += 4

        packet.buffer = binary[offset:offset + length]
        offset += length

        return packet, offset
コード例 #2
0
ファイル: Packet.py プロジェクト: Mrmistik39/PyMp2
 def getLTriad(self) -> int:
     return Binary.readLTriad(self.get(3))