def read_node(source: BinarySource) -> Dict: node = { "name": source.read_string(), "heal": source.read_bool(), "node_type": source.read_byte(), } node_type = node["node_type"] if node_type == 0: pass elif node_type == 1: node["dock_index"] = source.read_byte() node["connected_area_asset_id"] = source.read_uint() node["connected_dock_index"] = source.read_byte() node["dock_type"] = source.read_byte() node["dock_weakness_index"] = source.read_byte() source.skip(3) elif node_type == 2: node["pickup_index"] = source.read_byte() elif node_type == 3: node["destination_world_asset_id"] = source.read_uint() node["destination_area_asset_id"] = source.read_uint() node["teleporter_instance_id"] = source.read_uint() elif node_type == 4: node["event_index"] = source.read_byte() else: raise Exception("Unknown node type: {}".format(node_type)) return node
def test_read_a(): b = io.BytesIO(b"\x05aaax\x00?\x80\x00\x00TP\x06@") # type: BinaryIO source = BinarySource(b) assert source.read_byte() == 5 assert source.read_string() == "aaax" assert source.read_float() == 1 source.skip(1) assert source.read_bool() assert source.read_short() == 1600