rlp

package
v0.0.0-...-1f8a15b Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

rlp

TERMINOLOGY:

RLP string = "Blob" // this is so we don't conflict with existing go name for String
RLP list = "List" // luckily we can keep using list name since go doesn't use it
RLP single byte number = "Decimal" // for numbers from 1-127. a special case

Documentation

Index

Constants

View Source
const ParseAnnouncementsErrorPrefix = "parse announcement payload"
View Source
const ParseHashErrorPrefix = "parse hash payload"

Variables

View Source
var (
	ErrBase          = fmt.Errorf("rlp")
	ErrParse         = fmt.Errorf("%w parse", ErrBase)
	ErrDecode        = fmt.Errorf("%w decode", ErrBase)
	ErrUnexpectedEOF = fmt.Errorf("%w EOF", ErrBase)
)

Functions

func AnnouncementsLen

func AnnouncementsLen(types []byte, sizes []uint32, hashes []byte) int

func BeInt

func BeInt(payload []byte, pos, length int) (int, error)

BeInt parses Big Endian representation of an integer from given payload at given position

func BlobLength

func BlobLength(dst *int, src []byte) error

func Bytes

func Bytes(dst *[]byte, src []byte) error

func BytesExact

func BytesExact(dst *[]byte, src []byte) error

func EncodeAnnouncements

func EncodeAnnouncements(types []byte, sizes []uint32, hashes []byte, encodeBuf []byte) int

EIP-5793: eth/68 - Add tx type to tx announcement

func EncodeByteArrayAsRlp

func EncodeByteArrayAsRlp(raw []byte, w io.Writer, prefixBuf []byte) (int, error)

func EncodeHash

func EncodeHash(h, to []byte) int

EncodeHash assumes that `to` buffer is already 32bytes long

func EncodeHashes

func EncodeHashes(hashes []byte, encodeBuf []byte) int

func EncodeListPrefix

func EncodeListPrefix(dataLen int, to []byte) int

func EncodeString

func EncodeString(s []byte, to []byte) int

func EncodeU32

func EncodeU32(i uint32, to []byte) int

func EncodeU64

func EncodeU64(i uint64, to []byte) int

func GenerateStructLen

func GenerateStructLen(buffer []byte, l int) int

func HashesLen

func HashesLen(hashes []byte) int

func IsEmpty

func IsEmpty(dst *bool, src []byte) error

func IsRLPError

func IsRLPError(err error) bool

func List

func List(payload []byte, pos int) (dataPos, dataLen int, err error)

func ListPrefixLen

func ListPrefixLen(dataLen int) int

func ParseAnnouncements

func ParseAnnouncements(payload []byte, pos int) ([]byte, []uint32, []byte, int, error)

func ParseHash

func ParseHash(payload []byte, pos int, hashbuf []byte) (int, error)

func Prefix

func Prefix(payload []byte, pos int) (dataPos int, dataLen int, isList bool, err error)

Prefix parses RLP Prefix from given payload at given position. It returns the offset and length of the RLP element as well as the indication of whether it is a list of string

func ReadElem

func ReadElem[T any](d *Decoder, fn func(*T, []byte) error, receiver *T) error

func Skip

func Skip(dst *int, src []byte) error

func String

func String(payload []byte, pos int) (dataPos, dataLen int, err error)

func StringLen

func StringLen(s []byte) int

func StringOfLen

func StringOfLen(payload []byte, pos, expectedLen int) (dataPos int, err error)

func U256

func U256(payload []byte, pos int, x *uint256.Int) (int, error)

U256 parses uint256 number from given payload at given position

func U256Len

func U256Len(z *uint256.Int) int

func U32

func U32(payload []byte, pos int) (int, uint32, error)

U32 parses uint64 number from given payload at given position

func U32Len

func U32Len(i uint32) int

func U64

func U64(payload []byte, pos int) (int, uint64, error)

U64 parses uint64 number from given payload at given position

func U64Len

func U64Len(i uint64) int

func Uint256

func Uint256(dst *uint256.Int, src []byte) error

func Uint64

func Uint64(dst *uint64, src []byte) error

func Unmarshal

func Unmarshal(data []byte, val any) error

Types

type Decoder

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

func NewDecoder

func NewDecoder(buf []byte) *Decoder

func (*Decoder) Bytes

func (d *Decoder) Bytes() []byte

func (*Decoder) Consumed

func (d *Decoder) Consumed() []byte

func (*Decoder) Elem

func (d *Decoder) Elem() ([]byte, Token, error)

func (*Decoder) ElemDec

func (d *Decoder) ElemDec() (*Decoder, Token, error)

func (*Decoder) Empty

func (d *Decoder) Empty() bool

func (*Decoder) ForList

func (d *Decoder) ForList(fn func(*Decoder) error) error

func (*Decoder) Fork

func (d *Decoder) Fork() *Decoder

func (*Decoder) Offset

func (d *Decoder) Offset() int

func (*Decoder) PeekByte

func (d *Decoder) PeekByte() (n byte, err error)

func (*Decoder) PeekToken

func (d *Decoder) PeekToken() (Token, error)

func (*Decoder) RawElem

func (d *Decoder) RawElem() ([]byte, Token, error)

func (*Decoder) RawElemDec

func (d *Decoder) RawElemDec() (*Decoder, Token, error)

func (*Decoder) ReadByte

func (d *Decoder) ReadByte() (n byte, err error)

func (*Decoder) Rebase

func (d *Decoder) Rebase()

func (*Decoder) String

func (d *Decoder) String() string

func (*Decoder) Underlying

func (d *Decoder) Underlying() []byte

type Encoder

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

func NewEncoder

func NewEncoder(buf []byte) *Encoder

func (*Encoder) Buffer

func (e *Encoder) Buffer() []byte

Buffer returns the underlying buffer

func (*Encoder) Byte

func (e *Encoder) Byte(p byte) *Encoder

func (*Encoder) Bytes

func (e *Encoder) Bytes(p []byte) *Encoder

func (*Encoder) List

func (e *Encoder) List(items ...EncoderFunc) *Encoder

List will attempt to write the list of encoder funcs to the buf

func (*Encoder) LongList

func (e *Encoder) LongList(items ...EncoderFunc) *Encoder

LongList will assume that your list payload is more than 55 bytes long, and do no validation as such

func (*Encoder) LongString

func (e *Encoder) LongString(str []byte) *Encoder

String will assume your string is greater than 55 bytes long, and do no validation as such

func (*Encoder) ShortList

func (e *Encoder) ShortList(items ...EncoderFunc) *Encoder

ShortList actually calls List

func (*Encoder) ShortString

func (e *Encoder) ShortString(str []byte) *Encoder

String will assume your string is less than 56 bytes long, and do no validation as such

func (*Encoder) Str

func (e *Encoder) Str(str []byte) *Encoder

Str will write a string correctly

type EncoderFunc

type EncoderFunc = func(i *Encoder) *Encoder

type RlpEncodedBytes

type RlpEncodedBytes []byte

func (RlpEncodedBytes) DoubleRLPLen

func (b RlpEncodedBytes) DoubleRLPLen() int

func (RlpEncodedBytes) RawBytes

func (b RlpEncodedBytes) RawBytes() []byte

func (RlpEncodedBytes) ToDoubleRLP

func (b RlpEncodedBytes) ToDoubleRLP(w io.Writer, prefixBuf []byte) error

type RlpSerializable

type RlpSerializable interface {
	ToDoubleRLP(io.Writer, []byte) error
	DoubleRLPLen() int
	RawBytes() []byte
}

RlpSerializable is a value that can be double-RLP coded.

type RlpSerializableBytes

type RlpSerializableBytes []byte

func (RlpSerializableBytes) DoubleRLPLen

func (b RlpSerializableBytes) DoubleRLPLen() int

func (RlpSerializableBytes) RawBytes

func (b RlpSerializableBytes) RawBytes() []byte

func (RlpSerializableBytes) ToDoubleRLP

func (b RlpSerializableBytes) ToDoubleRLP(w io.Writer, prefixBuf []byte) error

type Token

type Token int32
const (
	TokenDecimal   Token = 0x00
	TokenShortBlob Token = 0x80
	TokenLongBlob  Token = 0xb7
	TokenShortList Token = 0xc0
	TokenLongList  Token = 0xf7

	TokenUnknown Token = 0xff01
	TokenEOF     Token = 0xdead
)

func (Token) Diff

func (T Token) Diff(n byte) byte

func (Token) IsBlobType

func (T Token) IsBlobType() bool

func (Token) IsListType

func (T Token) IsListType() bool

func (Token) Plus

func (T Token) Plus(n byte) byte

func (Token) String

func (T Token) String() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalRLP(data []byte) error
}

Jump to

Keyboard shortcuts

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