Skip to content

feat: add function to decode an entire slice - #23

Merged
DaniPopes merged 11 commits into
alloy-rs:mainfrom
Wollac:feat/decode-full
Aug 5, 2024
Merged

feat: add function to decode an entire slice#23
DaniPopes merged 11 commits into
alloy-rs:mainfrom
Wollac:feat/decode-full

Conversation

@Wollac

@Wollac Wollac commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

This PR fixes #21 by adding the public function decode_exact described above. It also introduces a new error type, since none of the existing ones fit.
This PR can be closed without merging if the decode_exact function is deemed unnecessary in the context of this crate.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes
  • Updated CHANGELOG.md

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delay, only now enabled notifications on this...

Comment thread crates/rlp/src/error.rs Outdated
Comment on lines +15 to +16
/// Additional trailing bytes found after decoding.
TrailingBytes,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be expressed with the Unexptectedlength variant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that this is currently returned when the payload length doesn't match the array size or other payload length issues, I didn't think it would be a good fit for this since decode_exact() doesn't look at the payload, but rather the entire RLP encoded data. However, if this is just me, I can definitely adjust `UnexpectedLength' to better account for both cases...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be ok with the new variant however this is unfortunately a breaking change because the enum is not marked as #[non_exhaustive]. So for now I would prefer the other option and adding a TODO for the new variant

Comment thread crates/rlp/src/decode.rs Outdated
Comment thread CHANGELOG.md

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is reasonable and useful imo

any objections @Rjected @DaniPopes ?

@DaniPopes DaniPopes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@DaniPopes
DaniPopes merged commit 2ba859b into alloy-rs:main Aug 5, 2024
@Wollac
Wollac deleted the feat/decode-full branch October 2, 2024 08:11
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.

Decode an entire slice

3 participants