"""Obiekt ARRAY silnika PIK — pliki .ARR i .SAV. Format (little-endian, bez nagłówka): uint32 count count × { uint32 type; type==1 ? int32 : (uint32 len; bytes[len]) } type 1 = INTEGER, type 2 = STRING (cp1250, bez terminatora). """ from __future__ import annotations import struct from pathlib import Path ENCODING = "cp1250" TYPE_INT = 1 TYPE_STR = 2 TYPE_BOOL = 3 TYPE_FLOAT = 4 Value = int | str class ArrError(ValueError): """Plik .ARR nie trzyma się formatu.""" def loads(data: bytes) -> list[Value]: if len(data) < 4: raise ArrError(f"plik ma {len(data)} B, minimum to 4 B (samo count)") (count,) = struct.unpack_from(" bytes: parts = [struct.pack(" list[Value]: return loads(Path(path).read_bytes()) def write(path: str | Path, values: list[Value]) -> None: Path(path).write_bytes(dumps(values))