Try it Live
Run RLP examples in the interactive playground
RLP Utilities
Helper methods for creating, measuring, flattening, and comparing RLP data structures.Overview
Utility functions provide convenient ways to work with RLP data:- from - Create RLP data from various inputs
- getEncodedLength - Calculate encoded size without encoding
- flatten - Extract all bytes from nested structures
- equals - Deep equality comparison
from
Create RLP data structure from various inputs with automatic type detection.Behavior
Thefrom method normalizes various input types into RLP data structures:
- Uint8Array → Creates bytes data
- BrandedRlp → Returns unchanged (idempotent)
- Array → Creates list data (doesn’t recursively convert items)
Use Cases
Normalizing Input:getEncodedLength
Calculate the byte length of RLP-encoded data without actually encoding it.Algorithm
Calculates encoded size using RLP rules without allocating buffers: For Uint8Array:Performance Benefits
Measuring without encoding saves allocation and copying:flatten
Recursively extract all bytes data from nested lists (depth-first traversal).Algorithm
Depth-first traversal that collects all bytes data:Use Cases
Extract Transaction Fields:equals
Deep equality comparison for RLP data structures.Algorithm
Recursive comparison with type checking:Use Cases
Deduplication:Utility Combinations
Combine utilities for powerful operations: Measure Flattened Size:Related
- Types - RLP type system and guards
- Encoding - Encode RLP data
- Decoding - Decode RLP data
- BrandedRlp - Functional API

