Esempio n. 1
0
    def toBinary(self, internal = False):
        payload = bytearray()
        if self.hasSplit:
            payload += (Binary.writeByte((self.reliability << 5) | 0b00010000))
        else :
            payload += (Binary.writeByte(self.reliability << 5))

        if internal:
            payload += (Binary.writeInt(len(self.buffer)))
            payload += (Binary.writeInt(self.identifierACK))
        else:
            payload += (Binary.writeShort(len(self.buffer) << 3))

        if self.reliability > 0:
            if (self.reliability > 2 or self.reliability == 2) and self.reliability is not 5:
                payload += (Binary.writeLTriad(self.messageIndex))
            if (self.reliability < 4 or self.reliability == 4) and self.reliability is not 2:
                payload += (Binary.writeLTriad(self.orderIndex))
                payload += (Binary.writeByte(self.orderChannel))

        if self.hasSplit:
            payload += (Binary.writeInt(self.splitCount))
            payload += (Binary.writeShort(self.splitID))
            payload += (Binary.writeInt(self.splitIndex))

        payload += (self.buffer)

        return payload
Esempio n. 2
0
    def _encode(self):
        super().clean()
        payload = bytearray()
        self.seqNums = sorted(self.seqNums)
        count = len(self.seqNums)
        records = 0

        if count > 0:
            pointer = 1
            start = self.seqNums[0]
            last = self.seqNums[0]

            while pointer < count:
                pointer += 1
                if pointer == count:
                    break
                current = self.seqNums[pointer]
                diff = current - last
                if diff == 1:
                    last = current
                elif diff > 1:
                    if start == last:
                        payload += bytes("\x01", "UTF-8")
                        payload += (Binary.writeLTriad(start))
                        start = last = current
                    else:
                        payload += bytes("\x01", "UTF-8")
                        payload += (Binary.writeLTriad(start))
                        payload += (Binary.writeLTriad(last))
                        start = last = current
                    records = +1

            if start == last:
                payload += bytes("\x01", "UTF-8")
                payload += (Binary.writeLTriad(start))
                start = last = current
            else:
                payload += bytes("\x01", "UTF-8")
                payload += (Binary.writeLTriad(start))
                payload += (Binary.writeLTriad(last))
                start = last = current

        self.putByte(self.getPID(), False)
        self.putShort(records)
        self.put(payload)
Esempio n. 3
0
    def _encode(self):
        super().clean()
        payload = bytearray()
        self.seqNums = sorted(self.seqNums)
        count = len(self.seqNums)
        records = 0

        if count > 0:
            pointer = 1
            start = self.seqNums[0]
            last = self.seqNums[0]

            while pointer < count:
                pointer += 1
                if pointer == count: break
                current = self.seqNums[pointer]
                diff = current - last
                if diff == 1:
                    last = current
                elif diff > 1:
                    if start == last:
                        payload += bytes("\x01", "UTF-8")
                        payload += (Binary.writeLTriad(start))
                        start = last = current
                    else:
                        payload += bytes("\x01", "UTF-8")
                        payload += (Binary.writeLTriad(start))
                        payload += (Binary.writeLTriad(last))
                        start = last = current
                    records =+ 1

            if start == last:
                payload += bytes("\x01", "UTF-8")
                payload += (Binary.writeLTriad(start))
                start = last = current
            else:
                payload += bytes("\x01", "UTF-8")
                payload += (Binary.writeLTriad(start))
                payload += (Binary.writeLTriad(last))
                start = last = current

        self.putByte(self.getPID(), False)
        self.putShort(records)
        self.put(payload)
Esempio n. 4
0
 def putLTriad(self, t: int):
     self.buffer += Binary.writeLTriad(t)
Esempio n. 5
0
 def putLTriad(self, t: int):
     self.buffer += Binary.writeLTriad(t)
Esempio n. 6
0
import socket
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)