r""" >>> import io, struct, sys >>> read_bytearray8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc")) bytearray(b'') >>> read_bytearray8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef")) bytearray(b'abc') >>> bigsize8 = struct.pack(" >> read_by
(f)
| 567 | |
| 568 | |
| 569 | def read_bytearray8(f): |
| 570 | r""" |
| 571 | >>> import io, struct, sys |
| 572 | >>> read_bytearray8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc")) |
| 573 | bytearray(b'') |
| 574 | >>> read_bytearray8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef")) |
| 575 | bytearray(b'abc') |
| 576 | >>> bigsize8 = struct.pack("<Q", sys.maxsize//3) |
| 577 | >>> read_bytearray8(io.BytesIO(bigsize8 + b"abcdef")) #doctest: +ELLIPSIS |
| 578 | Traceback (most recent call last): |
| 579 | ... |
| 580 | ValueError: expected ... bytes in a bytearray8, but only 6 remain |
| 581 | """ |
| 582 | |
| 583 | n = read_uint8(f) |
| 584 | assert n >= 0 |
| 585 | if n > sys.maxsize: |
| 586 | raise ValueError("bytearray8 byte count > sys.maxsize: %d" % n) |
| 587 | data = f.read(n) |
| 588 | if len(data) == n: |
| 589 | return bytearray(data) |
| 590 | raise ValueError("expected %d bytes in a bytearray8, but only %d remain" % |
| 591 | (n, len(data))) |
| 592 | |
| 593 | bytearray8 = ArgumentDescriptor( |
| 594 | name="bytearray8", |
nothing calls this directly
no test coverage detected