예제 #1
0
def test_pack():
    from pyec.packet.varint import pack

    assert pack(5030) == b'NM'
    assert pack(32) == b'A'
    assert pack(512) == b'\x08\x01'
    assert pack(5123) == b'P\x07'
예제 #2
0
def test_pack():
	from pyec.packet.varint import pack

	assert pack(5030) == b'NM'
	assert   pack(32) == b'A'
	assert  pack(512) == b'\x08\x01'
	assert pack(5123) == b'P\x07'
예제 #3
0
def test_round_trip():
    from pyec.packet.varint import pack, unpack_bytes
    import random

    for _ in range(20):
        x = random.randrange(100000)
        assert unpack_bytes(pack(x))[0] == x
예제 #4
0
def test_round_trip():
	from pyec.packet.varint import pack, unpack_bytes
	import random

	for _ in range(20):
		x = random.randrange(100000)
		assert unpack_bytes(pack(x))[0] == x
예제 #5
0
파일: packet.py 프로젝트: tuomas56/pyec
	def serialize(self):
		"""Packets serialize to the format:
			pid + data
		Where pid is the ld-varint-encoded packet id.
		The data is composed of fields."""
		pid = PacketMeta.REGISTRY.get_id(self.__class__)
		data = []
		for field in self._fields:
			f = self.__class__.__dict__[field]
			val = getattr(self, field)
			data.append(f._serialize(val))
		data = b''.join(data)
		return pack(len(pid)) + pid.encode() + data
예제 #6
0
    def serialize(self):
        """Packets serialize to the format:
			pid + data
		Where pid is the ld-varint-encoded packet id.
		The data is composed of fields."""
        pid = PacketMeta.REGISTRY.get_id(self.__class__)
        data = []
        for field in self._fields:
            f = self.__class__.__dict__[field]
            val = getattr(self, field)
            data.append(f._serialize(val))
        data = b''.join(data)
        return pack(len(pid)) + pid.encode() + data
예제 #7
0
파일: packet.py 프로젝트: tuomas56/pyec
	def _serialize(self, inst):
		data = self._ld_serialize(inst)
		return pack(len(data)) + data
예제 #8
0
파일: packet.py 프로젝트: tuomas56/pyec
	def _serialize(self, inst):
		return pack(inst)
예제 #9
0
 def _serialize(self, inst):
     data = self._ld_serialize(inst)
     return pack(len(data)) + data
예제 #10
0
 def _serialize(self, inst):
     return pack(inst)