rlp

package
v0.39.15 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ByteRangeStart        = 0x00 // not in use, here only for inclusivity
	ByteRangeEnd          = 0x7f
	ShortStringRangeStart = 0x80
	ShortStringRangeEnd   = 0xb7
	LongStringRangeStart  = 0xb8
	LongStringRangeEnd    = 0xbf
	ShortListRangeStart   = 0xc0
	ShortListRangeEnd     = 0xf7
	LongListRangeStart    = 0xf8
	LongListRangeEnd      = 0xff // not in use, here only for inclusivity
	MaxShortLengthAllowed = 55
	MaxLongLengthAllowed  = math.MaxInt64
)

Variables

View Source
var (
	ErrEmptyInput        = errors.New("input data is empty")
	ErrInvalidStartIndex = errors.New("invalid start index")
	ErrIncompleteInput   = errors.New("incomplete input! not enough bytes to read")
	ErrNonCanonicalInput = errors.New("non-canonical encoded input")
	ErrDataSizeTooLarge  = errors.New("data size is larger than what is supported")
	ErrListSizeMismatch  = errors.New("list size doesn't match the size of items")
	ErrTypeMismatch      = errors.New("type extracted from input doesn't match the function")
)

Functions

func DecodeList

func DecodeList(inp []byte, startIndex int) (encodedItems [][]byte, bytesRead int, err error)

DecodeList decodes a RLP-encoded list given the startIndex it returns a list of encodedItems, number of bytes that were read and err if any

func DecodeString

func DecodeString(inp []byte, startIndex int) (str []byte, bytesRead int, err error)

DecodeString decodes a RLP-encoded string given the startIndex it returns decoded string, number of bytes that were read and err if any

func ReadSize

func ReadSize(inp []byte, startIndex int) (isString bool, dataStartIndex, dataSize int, err error)

ReadSize looks at the first byte at startIndex to decode the type and reads as many bytes as needed to determine the data byte size, it returns a flag if the type is string, start index of data part in the input, number of bytes that has to be read for data (from start index of data) and error if any.

it only supports RLP canonical form. RLP canonical form requires:

  • if string is 0-55 bytes long (first byte is [0x80, 0xb7]), string length can't be 1 while string <= 0x7f
  • if string is more than 55 bytes long (first byte is [0xb8, 0xbf]), string length can't be <= 55
  • if string is more than 55 bytes long (first byte is [0xb8, 0xbf]), string length can't be encoded with leading 0s
  • if list payload is more than 55 bytes long (first byte is [0xf8, 0xff]), list payload length can't be <= 55
  • if list payload is more than 55 bytes long (first byte is [0xf8, 0xff]), list payload length can't be encoded with leading 0s

Types

This section is empty.

Jump to

Keyboard shortcuts

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