校验场景字典的结构合法性。 Parameters ---------- data: 待校验的对象。 Returns ------- list[str] 错误描述列表;空列表表示合法。
(data: Any)
| 173 | |
| 174 | @staticmethod |
| 175 | def validate(data: Any) -> List[str]: |
| 176 | """校验场景字典的结构合法性。 |
| 177 | |
| 178 | Parameters |
| 179 | ---------- |
| 180 | data: |
| 181 | 待校验的对象。 |
| 182 | |
| 183 | Returns |
| 184 | ------- |
| 185 | list[str] |
| 186 | 错误描述列表;空列表表示合法。 |
| 187 | """ |
| 188 | errors: List[str] = [] |
| 189 | if not isinstance(data, dict): |
| 190 | return ["顶层结构必须为对象(dict)"] |
| 191 | |
| 192 | version = data.get("version") |
| 193 | if version is None: |
| 194 | errors.append("缺少 'version' 字段") |
| 195 | elif str(version) != SCENARIO_VERSION: |
| 196 | errors.append(f"版本不兼容: 期望 '{SCENARIO_VERSION}',收到 '{version}'") |
| 197 | |
| 198 | for field, expected_type in [ |
| 199 | ("ground_station_count", int), |
| 200 | ("leo_satellite_count", int), |
| 201 | ]: |
| 202 | val = data.get(field) |
| 203 | if val is None: |
| 204 | errors.append(f"缺少必填字段 '{field}'") |
| 205 | elif not isinstance(val, int) or val < 0: |
| 206 | errors.append(f"字段 '{field}' 必须为非负整数,收到: {val!r}") |
| 207 | |
| 208 | return errors |
| 209 | |
| 210 | # ── 序列化辅助 ────────────────────────────────────────────────────────── |
| 211 |