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
def getLTriad(self) -> int: return Binary.readLTriad(self.get(3))
from struct import pack, unpack import re from pyraklib.Binary import Binary #data = (pack("N", 1)[0:3]) #data = pack('<i', 1)[:3] #data = data[::-1] #Little endian triad #print(data) #print(unpack('>i', b'\x00' + data)[0]) #print(unpack('<i', data + b'\x00')[0]) from pyraklib.protocol.EncapsulatedPacket import EncapsulatedPacket from pyraklib.protocol.UNCONNECTED_PING import UNCONNECTED_PING from pyraklib.protocol.UNCONNECTED_PONG import UNCONNECTED_PONG data = Binary.writeLTriad(32) print(Binary.readLTriad(data)) data = Binary.writeByte(32) print(Binary.readByte(data)) data = Binary.writeShort(256) print(Binary.readShort(data)) data = Binary.writeInt(32) print(Binary.readInt(data)) data = Binary.writeLong(32) print(Binary.readLong(data)) data = Binary.writeFloat(32.54) print(Binary.readFloat(data))