r""" >>> import io >>> read_bytes4(io.BytesIO(b"\x00\x00\x00\x00abc")) b'' >>> read_bytes4(io.BytesIO(b"\x03\x00\x00\x00abcdef")) b'abc' >>> read_bytes4(io.BytesIO(b"\x00\x00\x00\x03abcdef")) Traceback (most recent call last): ... ValueError: expected 50331648 byt
(f)
| 498 | |
| 499 | |
| 500 | def read_bytes4(f): |
| 501 | r""" |
| 502 | >>> import io |
| 503 | >>> read_bytes4(io.BytesIO(b"\x00\x00\x00\x00abc")) |
| 504 | b'' |
| 505 | >>> read_bytes4(io.BytesIO(b"\x03\x00\x00\x00abcdef")) |
| 506 | b'abc' |
| 507 | >>> read_bytes4(io.BytesIO(b"\x00\x00\x00\x03abcdef")) |
| 508 | Traceback (most recent call last): |
| 509 | ... |
| 510 | ValueError: expected 50331648 bytes in a bytes4, but only 6 remain |
| 511 | """ |
| 512 | |
| 513 | n = read_uint4(f) |
| 514 | assert n >= 0 |
| 515 | if n > sys.maxsize: |
| 516 | raise ValueError("bytes4 byte count > sys.maxsize: %d" % n) |
| 517 | data = f.read(n) |
| 518 | if len(data) == n: |
| 519 | return data |
| 520 | raise ValueError("expected %d bytes in a bytes4, but only %d remain" % |
| 521 | (n, len(data))) |
| 522 | |
| 523 | bytes4 = ArgumentDescriptor( |
| 524 | name="bytes4", |
nothing calls this directly
no test coverage detected