Change univese representation from bytes to int

This commit is contained in:
Kai Vogelgesang 2019-10-16 23:57:34 +02:00
parent 7e1ae78aab
commit c878fded69
6 changed files with 20 additions and 20 deletions

View File

@ -11,17 +11,17 @@ class DataPacketFramingLayer:
STREAM_TERMINATED = 1 << 6
PREVIEW_DATA = 1 << 7
PACK_FORMAT = '! H 4s 64s B 2s B B 2s'
PACK_FORMAT = '! H 4s 64s B H B B H'
HEADER_SIZE = struct.calcsize(PACK_FORMAT)
def __init__(self, length: int, source_name: str, priority: int, synchronization_address: bytes,
sequence_number: int, options: Options, universe: bytes):
def __init__(self, length: int, source_name: str, priority: int, synchronization_address: int,
sequence_number: int, options: Options, universe: int):
assert 0 <= length <= 0x0FFF
assert len(source_name) <= 64
assert 0 <= priority <= 200
assert len(synchronization_address) == 2
assert 0 <= synchronization_address <= 63999
assert 0 <= sequence_number <= 0xFF
assert len(universe) == 2
assert 1 <= universe <= 63999
self.length = length
self.source_name = source_name

View File

@ -4,13 +4,13 @@ from Proto.Vector import VECTOR
class SynchronizationPacketFramingLayer:
PACK_FORMAT = '! H 4s B 2s 2x'
PACK_FORMAT = '! H 4s B H 2x'
HEADER_SIZE = struct.calcsize(PACK_FORMAT)
def __init__(self, length: int, sequence_number: int, synchronization_address: bytes):
def __init__(self, length: int, sequence_number: int, synchronization_address: int):
assert 0 <= length <= 0xFFF
assert 0 <= sequence_number <= 0xFF
assert len(synchronization_address) == 2
assert 1 <= synchronization_address <= 63999
self.length = length
self.sequence_number = sequence_number

View File

@ -8,13 +8,13 @@ class UniverseDiscoveryLayer:
PACK_FORMAT = '! H 4s B B'
HEADER_SIZE = struct.calcsize(PACK_FORMAT)
def __init__(self, length: int, page: int, last_page: int, universe_list: List[bytes]):
def __init__(self, length: int, page: int, last_page: int, universe_list: List[int]):
assert 0 <= length <= 0xFFF
assert 0 <= page <= 0xFF
assert 0 <= last_page <= 0xFF
assert len(universe_list) <= 512
for universe in universe_list:
assert len(universe) == 2
assert 1 <= universe <= 63999
self.length = length
self.page = page
@ -31,7 +31,7 @@ class UniverseDiscoveryLayer:
self.last_page
)
buffer += b''.join(self.universe_list)
buffer += struct.pack(f'! {len(self.universe_list)}H', *self.universe_list)
return buffer
@ -53,6 +53,6 @@ class UniverseDiscoveryLayer:
assert len(buffer) >= offset + length
for i in range(universe_list_offset, offset + length, 2):
universe_list.append(buffer[i:i+2])
universe_list.extend(struct.unpack_from('!H', buffer, i))
return cls(length, page, last_page, universe_list)

View File

@ -3,15 +3,15 @@ from Proto.Vector import VECTOR
class DataPacket:
def __init__(self, cid: bytes, source_name: str, priority: int, synchronization_address: bytes,
sequence_number: int, options: DataPacketFramingLayer.Options, universe: bytes,
def __init__(self, cid: bytes, source_name: str, priority: int, synchronization_address: int,
sequence_number: int, options: DataPacketFramingLayer.Options, universe: int,
property_values: bytes):
assert len(cid) == 16
assert len(source_name) <= 64
assert 0 <= priority <= 100
assert len(synchronization_address) == 2
assert 0 <= synchronization_address <= 63999
assert 0 <= sequence_number <= 0xFF
assert len(universe) == 2
assert 1 <= universe <= 63999
assert 1 <= len(property_values) <= 513
self.cid = cid

View File

@ -3,10 +3,10 @@ from Proto.Vector import VECTOR
class SynchronizationPacket:
def __init__(self, cid: bytes, sequence_number: int, synchronization_address: bytes):
def __init__(self, cid: bytes, sequence_number: int, synchronization_address: int):
assert len(cid) == 16
assert 0 <= sequence_number <= 0xFF
assert len(synchronization_address) == 2
assert 1 <= synchronization_address <= 63999
self.cid = cid
self.sequence_number = sequence_number

View File

@ -5,14 +5,14 @@ from Proto.Vector import VECTOR
class UniverseDiscoveryPacket:
def __init__(self, cid: bytes, source_name: str, page: int, last_page: int, universe_list: List[bytes]):
def __init__(self, cid: bytes, source_name: str, page: int, last_page: int, universe_list: List[int]):
assert len(cid) == 16
assert len(source_name) <= 64
assert 0 <= page <= 0xFF
assert 0 <= last_page <= 0xFF
assert len(universe_list) <= 512
for universe in universe_list:
assert len(universe) == 2
assert 1 <= universe <= 63999
self.cid = cid
self.source_name = source_name