"""Binary key-value decoding shared by both readers of ``appinfo.vdf``. ``steam_installer.appinfo_cache`` (every app) and ``steam_backlog_enforcer._appinfo_cache`` (selected apps) read the same v29 layout; this module holds the parts they have in common: the string table and the nested key-value blocks. It raises ``AppinfoFormatError`` (a ``ValueError``) and each reader keeps the exception type its callers already handle. """ from __future__ import annotations import struct from typing import Any, Final MAGIC: Final = 0x07564429 HEADER: Final = 60 # KV type bytes: a nested block, a NUL-terminated string, end of block. _BLOCK: Final = 0 _STRING: Final = 1 _END: Final = 8 # Fixed-width value types: KV type byte -> struct format. _SCALARS: Final = {2: " list[str]: """The NUL-terminated strings (u32 count first) that keys index into.""" (count,) = struct.unpack_from(" tuple[dict[str, Any], int]: """Decode one key-value block at *pos*; return it and the next position. Every scalar comes back as a string, as Steam's text VDF prints it. """ out: dict[str, Any] = {} while True: kind = buf[pos] pos += 1 if kind == _END: return out, pos (index,) = struct.unpack_from("