(self, write_context, value)
| 170 | return builder(case_id, value) |
| 171 | |
| 172 | def _write_typing_union(self, write_context, value): |
| 173 | active_index = None |
| 174 | active_serializer = None |
| 175 | active_type = None |
| 176 | |
| 177 | for i, (alt_type, serializer) in enumerate(self._alternative_serializers): |
| 178 | if isinstance(value, alt_type): |
| 179 | active_index = i |
| 180 | active_serializer = serializer |
| 181 | active_type = alt_type |
| 182 | break |
| 183 | |
| 184 | if active_index is None: |
| 185 | raise TypeError(f"Value {value} of type {type(value)} doesn't match any alternative in Union{self._alternative_types}") |
| 186 | |
| 187 | write_context.write_var_uint32(active_index) |
| 188 | typeinfo = self.type_resolver.get_type_info(active_type) |
| 189 | self.type_resolver.write_type_info(write_context, typeinfo) |
| 190 | active_serializer.write(write_context, value) |
| 191 | |
| 192 | def _read_typing_union(self, read_context): |
| 193 | stored_index = read_context.read_var_uint32() |
no test coverage detected