Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extract structured payload #18

Merged
merged 9 commits into from
Jun 28, 2024

Conversation

Wollac
Copy link
Contributor

@Wollac Wollac commented Jun 28, 2024

Motivation

For certain use cases, like MPT nodes, the type of an RLP payload is not known in advance, but depends on its structure.
This PR adds functionality that extracts the payload structure without having to specify its type.
This fixes #17.

Solution

This PR adds Header::decode_raw for this, which returns the following typed enum, that can then be used to determine the payload components and then recursively decode them:

pub enum PayloadView<'a> {
    String(&'a [u8]),
    List(Vec<&'a [u8]>),
}

PR Checklist

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

crates/rlp/src/header.rs Outdated Show resolved Hide resolved
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@DaniPopes DaniPopes merged commit cd9a3ff into alloy-rs:main Jun 28, 2024
18 checks passed
@Wollac Wollac deleted the feat/extract-payload branch June 28, 2024 22:25
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.

Add functionality to extract payload structure without decoding it
2 participants