(self, read_context)
| 446 | raise TypeError(f"Field {self.field_name!r} has unsupported array target serializer {type(self.target_serializer)!r}") |
| 447 | |
| 448 | def read(self, read_context): |
| 449 | from pyfory.collection import ( |
| 450 | COLL_HAS_NULL, |
| 451 | COLL_IS_DECL_ELEMENT_TYPE, |
| 452 | COLL_IS_SAME_TYPE, |
| 453 | COLL_TRACKING_REF, |
| 454 | ) |
| 455 | from pyfory.error import TypeNotCompatibleError |
| 456 | |
| 457 | length = read_context.read_var_uint32() |
| 458 | if length == 0: |
| 459 | return self._empty_target() |
| 460 | collect_flag = read_context.read_int8() |
| 461 | if (collect_flag & (COLL_HAS_NULL | COLL_TRACKING_REF)) != 0: |
| 462 | raise TypeNotCompatibleError( |
| 463 | f"Field {self.field_name!r} cannot read nullable or ref-tracked list elements as array<T>", |
| 464 | ) |
| 465 | if (collect_flag & (COLL_IS_SAME_TYPE | COLL_IS_DECL_ELEMENT_TYPE)) != (COLL_IS_SAME_TYPE | COLL_IS_DECL_ELEMENT_TYPE): |
| 466 | raise TypeNotCompatibleError( |
| 467 | f"Field {self.field_name!r} requires declared same-type list elements for array<T> compatible read", |
| 468 | ) |
| 469 | |
| 470 | read_context.check_readable_bytes(length) |
| 471 | target = self._new_target(length) |
| 472 | append = None if np is not None and _is_numpy_1d_array_serializer(self.target_serializer) else target.append |
| 473 | for index in range(length): |
| 474 | item = read_context.read_no_ref(serializer=self.elem_serializer) |
| 475 | try: |
| 476 | if append is None: |
| 477 | target[index] = item |
| 478 | else: |
| 479 | append(item) |
| 480 | except (TypeError, ValueError, OverflowError) as exc: |
| 481 | raise type(exc)(f"{self.field_name}[{index}] invalid for {type(target).__name__}: {exc}") from exc |
| 482 | return target |
nothing calls this directly
no test coverage detected