rlp

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

This package implements a basic encoder/decoder for Ethereum's Recursive-Length Prefix (RLP) Serialization. For a detailed description of RLP, see Ethereum's page: https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(input Item) []byte
Example
item := List(
	String("foo"),
	List(String("bar"), String("baz")),
)
item, _ = Decode(Encode(item))

var (
	first  = item.At(0).String()
	second = item.At(1).At(0).String()
	third  = item.At(1).At(1).String()
)
fmt.Println(first, second, third)
Output:

foo bar baz

Types

type Item

type Item struct {
	// contains filtered or unexported fields
}

Instead of using standard data types and reflection this package chooses to encode Items. Set d or l but not both. l is a list of Item for arbitrarily nested lists. d is the data payload for the item.

func Byte

func Byte(b byte) Item

func Bytes

func Bytes(b []byte) Item

func Decode

func Decode(input []byte) (Item, error)

func Int

func Int(n int) Item

func List

func List(items ...Item) Item

func Secp256k1PublicKey

func Secp256k1PublicKey(pubk *secp256k1.PublicKey) Item

Uncompressed secpk256k1 public key

func String

func String(s string) Item

func Time

func Time(t time.Time) Item

func Uint16

func Uint16(n uint16) Item

func Uint64

func Uint64(n uint64) Item

func (Item) At

func (i Item) At(pos int) Item

func (Item) Bytes

func (i Item) Bytes() []byte

func (Item) Bytes32

func (i Item) Bytes32() ([32]byte, error)

func (Item) Bytes65

func (i Item) Bytes65() ([65]byte, error)

func (Item) Hash

func (i Item) Hash() ([32]byte, error)

func (Item) IP

func (i Item) IP() (net.IP, error)

func (Item) List

func (i Item) List() []Item

func (Item) Secp256k1PublicKey

func (i Item) Secp256k1PublicKey() (*secp256k1.PublicKey, error)

func (Item) String

func (i Item) String() string

func (Item) Time

func (i Item) Time() time.Time

func (Item) Uint16

func (i Item) Uint16() uint16

func (Item) Uint64

func (i Item) Uint64() uint64

Jump to

Keyboard shortcuts

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