alloy-rs / rlp

Fast implementation of Ethereum RLP serialization
Apache License 2.0
77 stars 16 forks source link

feat: extract structured payload #18

Closed Wollac closed 1 week ago

Wollac commented 1 week ago

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