rlp

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 7 Imported by: 1

README

GoDoc

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/ModChain/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")
)

Functions

func Decode

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

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

func DecodeUint64 added in v0.1.3

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