rlp

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data []byte

Data is an individual RLP Data element - or an "RLP string"

func MustWrapHex

func MustWrapHex(s string) Data

MustWrapHex panics if hex decoding fails

func WrapAddress

func WrapAddress(a *ethtypes.Address0xHex) Data

WrapAddress wraps an address, or writes empty data if the address is nil

func WrapHex

func WrapHex(s string) (Data, error)

WrapHex converts a hex encoded string (with or without 0x prefix) to an RLP Data element for encoding

func WrapInt

func WrapInt(i *big.Int) Data

WrapString converts a positive integer to an RLP Data element for encoding

func WrapString

func WrapString(s string) Data

WrapString converts a plain string to an RLP Data element for encoding

func (Data) Address added in v1.1.14

func (r Data) Address() *ethtypes.Address0xHex

func (Data) BytesNotNil added in v1.1.14

func (r Data) BytesNotNil() []byte

func (Data) Encode

func (r Data) Encode() []byte

Encode encodes this individual RLP Data element

func (Data) Int

func (r Data) Int() *big.Int

Int is a convenience function to convert the bytes within an RLP Data element to an integer (big endian encoding)

func (Data) IntOrZero added in v1.1.14

func (r Data) IntOrZero() *big.Int

func (Data) IsList

func (r Data) IsList() bool

IsList is false for individual RLP Data elements

func (Data) ToData added in v1.1.14

func (r Data) ToData() Data

type Element

type Element interface {
	// When true the Element can safely be cast to List, and when false the Element can safely be cast to Data
	IsList() bool
	// Encode converts the element to a byte array
	Encode() []byte
	// Safe function that will give an entry as data, to use the nil-safe functions on it to get the value (will be treated as nil data for list)
	ToData() Data
}

Element is an interface implemented by both Data and List elements

func Decode

func Decode(rlpData []byte) (Element, int, error)

Decode will decode an RLP element at the beginning of the byte slice. An error is returned if problems are found in the RLP encoding

The position of the first byte after the RLP element is returned. This will be the length of the byte slice, if the RLP element filled the entire slice. Otherwise, the position can be used to find/decode additional data (RLP or otherwise) in the byte slice.

The element returned will be one of: - nil if passed an empty byte array - Data if the RLP stream contains a data element in the first position - List if the RLP stream contains a list in the first position

type List

type List []Element

List is a list of RLP elements, which could be either Data or List elements

func (List) Encode

func (l List) Encode() []byte

Encode encodes the RLP List to a byte array, including recursing into child arrays

func (List) IsList

func (l List) IsList() bool

IsList returns true for list elements

func (List) ToData added in v1.1.14

func (l List) ToData() Data

Jump to

Keyboard shortcuts

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