| 119 | |
| 120 | |
| 121 | def decompress(chunk: JsonDict) -> JsonDict: |
| 122 | cache: dict[int, JsonDict] = {} |
| 123 | |
| 124 | def helper(chunk: JsonDict) -> JsonDict: |
| 125 | if not isinstance(chunk, dict): |
| 126 | return chunk # type: ignore[unreachable] #TODO: is this actually unreachable, or are our types wrong? |
| 127 | if ".id" in chunk: |
| 128 | return cache[chunk[".id"]] |
| 129 | |
| 130 | counter = None |
| 131 | if ".cache_id" in chunk: |
| 132 | counter = chunk[".cache_id"] |
| 133 | del chunk[".cache_id"] |
| 134 | |
| 135 | for name in sorted(chunk.keys()): |
| 136 | value = chunk[name] |
| 137 | if isinstance(value, list): |
| 138 | chunk[name] = [helper(child) for child in value] |
| 139 | elif isinstance(value, dict): |
| 140 | chunk[name] = helper(value) |
| 141 | |
| 142 | if counter is not None: |
| 143 | cache[counter] = chunk |
| 144 | |
| 145 | return chunk |
| 146 | |
| 147 | return helper(chunk) |
| 148 | |
| 149 | |
| 150 | def main() -> None: |