Deserialize the state from redis/disk. data and fp are mutually exclusive, but one must be provided. Args: data: The serialized state data. fp: The file pointer to the serialized state data. Returns: The deserialized state. Rais
(
cls, data: bytes | None = None, fp: BinaryIO | None = None
)
| 2193 | |
| 2194 | @classmethod |
| 2195 | def _deserialize( |
| 2196 | cls, data: bytes | None = None, fp: BinaryIO | None = None |
| 2197 | ) -> BaseState: |
| 2198 | """Deserialize the state from redis/disk. |
| 2199 | |
| 2200 | data and fp are mutually exclusive, but one must be provided. |
| 2201 | |
| 2202 | Args: |
| 2203 | data: The serialized state data. |
| 2204 | fp: The file pointer to the serialized state data. |
| 2205 | |
| 2206 | Returns: |
| 2207 | The deserialized state. |
| 2208 | |
| 2209 | Raises: |
| 2210 | ValueError: If both data and fp are provided, or neither are provided. |
| 2211 | StateSchemaMismatchError: If the state schema does not match the expected schema. |
| 2212 | """ |
| 2213 | if data is not None and fp is None: |
| 2214 | (substate_schema, state) = pickle.loads(data) |
| 2215 | elif fp is not None and data is None: |
| 2216 | (substate_schema, state) = pickle.load(fp) |
| 2217 | else: |
| 2218 | msg = "Only one of `data` or `fp` must be provided" |
| 2219 | raise ValueError(msg) |
| 2220 | if substate_schema != state._to_schema(): |
| 2221 | raise StateSchemaMismatchError |
| 2222 | return state |
| 2223 | |
| 2224 | |
| 2225 | def _serialize_type(type_: Any) -> str: |