def test_read_write_nonorigin(self): outstream = io.BytesIO() Coord(1000000, 2000000, -3000000).write(outstream) instream = io.BytesIO(outstream.getvalue()) coord = Coord.read(instream) self.assertEqual(coord, Coord(1000000, 2000000, -3000000))
def read(iostream): version = int.from_bytes(iostream.read(1), byteorder=BYTE_ORDER, signed=False) if version == 1: coord = Coord.read(iostream) distance = int.from_bytes(iostream.read(4), byteorder=BYTE_ORDER, signed=False) return UnitRequest(coord, distance) else: raise Exception(f'Unsupported version number: {version}')
def read(iostream): version = int.from_bytes(iostream.read(1), byteorder=BYTE_ORDER, signed=False) if version == 1: unit_id = int.from_bytes(iostream.read(4), byteorder=BYTE_ORDER, signed=False) user_id = int.from_bytes(iostream.read(4), byteorder=BYTE_ORDER, signed=False) game_id = int.from_bytes(iostream.read(4), byteorder=BYTE_ORDER, signed=False) coord = Coord.read(iostream) return UnitInfo(unit_id, user_id, game_id, coord) else: raise Exception(f'Unsupported serialization version: {version}')