Skip to content

fix: accept memoryview in decode and decode_lazy - #160

Open
nikolauspschuetz wants to merge 1 commit into
ApeWorX:mainfrom
nikolauspschuetz:fix/decode-memoryview
Open

fix: accept memoryview in decode and decode_lazy#160
nikolauspschuetz wants to merge 1 commit into
ApeWorX:mainfrom
nikolauspschuetz:fix/decode-memoryview

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

Closes #115.

rlp.decode rejected memoryview objects — is_bytes (from eth_utils) only accepts bytes/bytearray, so rlp.decode(memoryview(encoded)) raised DecodingError: Can only decode RLP bytes, got type memoryview.

Simply widening the type check is not enough in the pure-Python backend: the codec concatenates slices of the input (prefix + item, rlp[i:i+1] + len_prefix), and memoryview does not support +, so decode_lazy(memoryview(...)) raised TypeError: unsupported operand type(s) for +: 'memoryview' and 'memoryview'.

Fix: normalize a memoryview input to bytes at the top of both decode and decode_lazy, mirroring the existing bytearray handling. This makes memoryview a first-class input like bytearray (which already worked in both paths), works for both the pure-Python and rusty_rlp backends, and round-trips for nested lists and with a sedes.

Tests: added tests/core/test_memoryview.py, mirroring test_bytearray.py (covers decode, decode_lazy, and a nested list). All three fail on main and pass with this change.

rlp.decode rejected memoryview objects (is_bytes only accepts bytes and
bytearray), and rlp.decode_lazy raised a TypeError because the lazy codec
concatenates slices of the input (memoryview does not support +).

Normalize a memoryview input to bytes at the top of both entry points,
mirroring the existing bytearray handling, so memoryview is a first-class
input like bytearray.

Closes ApeWorX#115
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review July 22, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rlp.decode does not allow memoryview objects

1 participant