rlp

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 7 Imported by: 1

README

GoDoc Coverage Status

Recursive Length Prefix encoding (RLP)

See: https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp

This is a very lightweight implementation of rlp decoding & encoding, depending on no external library.

a typical transaction: RLP([nonce, gasPrice, gasLimit, to, value, data, v, r, s])

Encoding an array of values

This encoder supports a number of value types, including integer values, big.Int, byte arrays and strings.

import "github.com/KarpelesLab/rlp"

buf, err := rlp.Encode(nonce, gasPrice, 21000, "0x123456...", valueBig, []byte{})

Decoding

When decoding, all values will be decoded as []byte. Decode() will return a []any that can have values that are either []byte or another []any (recursive).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRlpMinusValue     = errors.New("rlp: negative values are not encodable")
	ErrStringPrefix      = errors.New("rlp: strings must start with 0x")
	ErrNonCanonicalSize  = errors.New("rlp: non-canonical length encoding")
	ErrNonCanonicalValue = errors.New("rlp: single byte < 0x80 must be encoded without length prefix")
)

Functions

func Decode

func Decode(buf []byte) ([]any, error)

Decode returns an array of values for the given RLP array.

func DecodeOne

func DecodeOne(buf []byte) (any, []byte, error)

DecodeOne decodes a single RLP entry from buf and returns the decoded value along with the remaining bytes. The value is either []byte (for strings) or []any (for lists).

func DecodeUint64

func DecodeUint64(buf []byte) uint64

DecodeUint64 returns a uint64 value for a 0~8 bytes long value, and will panic if the buffer is longer than that

func Encode

func Encode(in ...any) ([]byte, error)

Encode encodes a number of arguments into a RLP array

func EncodeValue

func EncodeValue(v any) ([]byte, error)

EncodeValue encodes a single value into rlp format

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL