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

Add functionality to extract payload structure without decoding it #17

Closed
Wollac opened this issue Jun 27, 2024 · 3 comments · Fixed by #18
Closed

Add functionality to extract payload structure without decoding it #17

Wollac opened this issue Jun 27, 2024 · 3 comments · Fixed by #18

Comments

@Wollac
Copy link
Contributor

Wollac commented Jun 27, 2024

For certain use cases, the type of an RLP payload is not known in advance, but depends on its structure.

An example of this is the MPT node, which can be either a branch or a leaf node depending on the number of items in the list. Here, it would be helpful to have a function that extracts the payload structure without having to specify its type.

When implemented in the application, this adds quite a bit of error-prone boilerplate code (see for example here: decode in alloy-trie), and having it in the RLP library would be beneficial.

Such a function might look something like the following

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

fn decode_raw<'a>(buf: &mut &'a [u8]) -> Result<Payload<'a>>;

I can provide a PR with this feature, if this seems relevant for this crate.

@DaniPopes
Copy link
Member

SGTM
cc @rkrasiuk @Rjected

@rkrasiuk
Copy link
Member

sgtm as well, current interface is indeed rather footgun'y

@Rjected
Copy link

Rjected commented Jun 27, 2024

Yeah this would be nice

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 a pull request may close this issue.

4 participants