Documentation
¶
Index ¶
- Variables
- func Decode(src []byte, dst Decoder) (int, error)
- func Encode(src Encoder) ([]byte, error)
- type BigInt
- type Bytes
- type Decoder
- type Encoder
- type List
- type RLP
- func (r RLP) BigInt() (v *BigInt, err error)
- func (r RLP) Bytes() (v Bytes, err error)
- func (r RLP) Decode(dst Decoder) error
- func (r *RLP) DecodeRLP(data []byte) (int, error)
- func (r RLP) EncodeRLP() ([]byte, error)
- func (r RLP) IsList() bool
- func (r RLP) IsString() bool
- func (r RLP) Length() int
- func (r RLP) List() (l TypedList[RLP], err error)
- func (r RLP) String() (v String, err error)
- func (r RLP) Uint() (v Uint, err error)
- type String
- type TypedList
- type Uint
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type BigInt ¶ added in v0.4.0
BigInt is a big.Int type that can be encoded and decoded to/from RLP.
type Bytes ¶ added in v0.4.0
type Bytes []byte
Bytes is a byte slice type that can be encoded and decoded to/from RLP.
type Decoder ¶ added in v0.4.0
type Decoder interface {
// DecodeRLP decodes the RLP data and stores the result in the value, and
// returns the number of bytes read. The data may be longer than the encoded
// value, in which case the remaining data is ignored.
DecodeRLP([]byte) (int, error)
}
Decoder is the interface implemented by types that can unmarshal themselves from RLP.
type Encoder ¶ added in v0.4.0
type Encoder interface {
// EncodeRLP returns the RLP encoding of the value.
EncodeRLP() ([]byte, error)
}
Encoder is the interface implemented by types that can marshal themselves into RLP.
type List ¶ added in v0.4.0
type List []any
List represents a list of RLP items.
List items must implement the Encoder interface if the list is being encoded, or the Decoder interface if the list is being decoded. Otherwise, the encoding or decoding will fail.
During decoding, the data is decoded into existing items if they are already in the list. Otherwise, the items are decoded into RLP types.
type RLP ¶
type RLP []byte
RLP is a raw RLP encoded data that can be decoded into any other type later.
func DecodeLazy ¶ added in v0.4.0
DecodeLazy performs lazy decoding of RLP encoded data. It returns an RLP type that provides methods for further decoding, the number of bytes read and an error, if any.
This method may be useful when the exact format of the data is not known.
func (RLP) BigInt ¶ added in v0.4.0
BigInt attempts to decode itself as a big.Int. If the decoding is successful, it returns the decoded big.Int.
func (RLP) Bytes ¶
Bytes attempts to decode itself as a byte slice. If the decoding is successful, it returns the decoded byte slice.
func (RLP) IsList ¶
IsList returns true if the encoded data is an RLP list. If the RLP data is empty, it returns false.
func (RLP) IsString ¶
IsString returns true if the encoded data is an RLP string. Do not confuse this with the Go string type; an RLP string could be decoded as a string, byte slice, uint64, or big.Int. If the RLP data is empty, it returns false.
func (RLP) Length ¶
Length returns the length of the string or number of items in the list. If the item is invalid, it returns 0.
func (RLP) List ¶ added in v0.4.0
List attempts to decode itself as a list. If the decoding is successful, it returns the decoded list.
type String ¶ added in v0.4.0
type String string
String is a string type that can be encoded and decoded to/from RLP.
type TypedList ¶ added in v0.4.0
type TypedList[T any] []*T
TypedList represents a RLP list of a specific type.
The T type must implement the Encoder interface if the list is being encoded, or the Decoder interface if the list is being decoded. Otherwise, the encoding or decoding will fail.
During decoding, the data is decoded into existing items if they are already in the list. If the list is shorter than the data, new items are appended to the list.
func (*TypedList[T]) Add ¶ added in v0.4.0
func (l *TypedList[T]) Add(items ...*T)
Add appends the given items to the list.
func (TypedList[T]) Get ¶ added in v0.4.0
func (l TypedList[T]) Get() []*T
Get returns the slice of items.
type Uint ¶ added in v0.4.0
type Uint uint64
Uint is an uint64 type that can be encoded and decoded to/from RLP.