sszutils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrListTooBig           = fmt.Errorf("list length is higher than max value")
	ErrUnexpectedEOF        = fmt.Errorf("unexpected end of SSZ")
	ErrOffset               = fmt.Errorf("incorrect offset")
	ErrInvalidValueRange    = fmt.Errorf("invalid value range")
	ErrInvalidUnionVariant  = fmt.Errorf("invalid union variant")
	ErrVectorLength         = fmt.Errorf("incorrect vector length")
	ErrNotImplemented       = fmt.Errorf("not implemented")
	ErrBitlistNotTerminated = fmt.Errorf("bitlist misses mandatory termination bit")
)

Functions

func AppendZeroPadding

func AppendZeroPadding(buf []byte, count int) []byte

AppendZeroPadding appends the specified number of zero bytes to buf

func CalculateLimit

func CalculateLimit(maxCapacity, numItems, size uint64) uint64

func ExpandSlice added in v1.1.1

func ExpandSlice[T any](src []T, size int) []T

ExpandSlice expands a slice to a byte slice

func GetOffsetSlice added in v1.2.0

func GetOffsetSlice(size int) []uint32

func MarshalBool

func MarshalBool(dst []byte, b bool) []byte

MarshalBool marshals a boolean to dst

func MarshalOffset

func MarshalOffset(dst []byte, offset int) []byte

MarshalOffset marshals an offset to dst

func MarshalUint8

func MarshalUint8(dst []byte, i uint8) []byte

MarshalUint8 marshals a little endian uint8 to dst

func MarshalUint16

func MarshalUint16(dst []byte, i uint16) []byte

MarshalUint16 marshals a little endian uint16 to dst

func MarshalUint32

func MarshalUint32(dst []byte, i uint32) []byte

MarshalUint32 marshals a little endian uint32 to dst

func MarshalUint64

func MarshalUint64(dst []byte, i uint64) []byte

MarshalUint64 marshals a little endian uint64 to dst

func NextPowerOfTwo added in v1.1.1

func NextPowerOfTwo(v uint64) uint

func PutOffsetSlice added in v1.2.0

func PutOffsetSlice(slice []uint32)

func ReadOffset

func ReadOffset(buf []byte) uint64

ReadOffset reads an offset from buf

func ResolveSpecValueWithDefault added in v1.2.0

func ResolveSpecValueWithDefault(ds DynamicSpecs, name string, defaultValue uint64) (uint64, error)

func UnmarshalBool

func UnmarshalBool(src []byte) bool

UnmarshalBool unmarshals a boolean from the src input

func UnmarshallUint8

func UnmarshallUint8(src []byte) uint8

UnmarshallUint8 unmarshals a little endian uint8 from the src input

func UnmarshallUint16

func UnmarshallUint16(src []byte) uint16

UnmarshallUint16 unmarshals a little endian uint16 from the src input

func UnmarshallUint32

func UnmarshallUint32(src []byte) uint32

UnmarshallUint32 unmarshals a little endian uint32 from the src input

func UnmarshallUint64

func UnmarshallUint64(src []byte) uint64

UnmarshallUint64 unmarshals a little endian uint64 from the src input

func UpdateOffset

func UpdateOffset(dst []byte, offset int)

UpdateOffset updates the offset in dst

func ZeroBytes

func ZeroBytes() []byte

Types

type BufferDecoder added in v1.2.0

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

func NewBufferDecoder added in v1.2.0

func NewBufferDecoder(buffer []byte) *BufferDecoder

func (*BufferDecoder) DecodeBool added in v1.2.0

func (e *BufferDecoder) DecodeBool() (bool, error)

func (*BufferDecoder) DecodeBytes added in v1.2.0

func (e *BufferDecoder) DecodeBytes(buf []byte) ([]byte, error)

func (*BufferDecoder) DecodeBytesBuf added in v1.2.0

func (e *BufferDecoder) DecodeBytesBuf(len int) ([]byte, error)

func (*BufferDecoder) DecodeOffset added in v1.2.0

func (e *BufferDecoder) DecodeOffset() (uint32, error)

func (*BufferDecoder) DecodeOffsetAt added in v1.2.0

func (e *BufferDecoder) DecodeOffsetAt(pos int) uint32

func (*BufferDecoder) DecodeUint8 added in v1.2.0

func (e *BufferDecoder) DecodeUint8() (uint8, error)

func (*BufferDecoder) DecodeUint16 added in v1.2.0

func (e *BufferDecoder) DecodeUint16() (uint16, error)

func (*BufferDecoder) DecodeUint32 added in v1.2.0

func (e *BufferDecoder) DecodeUint32() (uint32, error)

func (*BufferDecoder) DecodeUint64 added in v1.2.0

func (e *BufferDecoder) DecodeUint64() (uint64, error)

func (*BufferDecoder) GetLength added in v1.2.0

func (e *BufferDecoder) GetLength() int

func (*BufferDecoder) GetPosition added in v1.2.0

func (e *BufferDecoder) GetPosition() int

func (*BufferDecoder) PopLimit added in v1.2.0

func (e *BufferDecoder) PopLimit() int

func (*BufferDecoder) PushLimit added in v1.2.0

func (e *BufferDecoder) PushLimit(limit int)

func (*BufferDecoder) Seekable added in v1.2.0

func (e *BufferDecoder) Seekable() bool

func (*BufferDecoder) SkipBytes added in v1.2.0

func (e *BufferDecoder) SkipBytes(n int)

type BufferEncoder added in v1.2.0

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

func NewBufferEncoder added in v1.2.0

func NewBufferEncoder(buffer []byte) *BufferEncoder

NewBufferEncoder creates a new BufferEncoder using the provided buffer. The buffer should have sufficient capacity for the expected output.

func (*BufferEncoder) EncodeBool added in v1.2.0

func (e *BufferEncoder) EncodeBool(v bool)

func (*BufferEncoder) EncodeBytes added in v1.2.0

func (e *BufferEncoder) EncodeBytes(v []byte)

func (*BufferEncoder) EncodeOffset added in v1.2.0

func (e *BufferEncoder) EncodeOffset(v uint32)

func (*BufferEncoder) EncodeOffsetAt added in v1.2.0

func (e *BufferEncoder) EncodeOffsetAt(pos int, v uint32)

func (*BufferEncoder) EncodeUint8 added in v1.2.0

func (e *BufferEncoder) EncodeUint8(v uint8)

func (*BufferEncoder) EncodeUint16 added in v1.2.0

func (e *BufferEncoder) EncodeUint16(v uint16)

func (*BufferEncoder) EncodeUint32 added in v1.2.0

func (e *BufferEncoder) EncodeUint32(v uint32)

func (*BufferEncoder) EncodeUint64 added in v1.2.0

func (e *BufferEncoder) EncodeUint64(v uint64)

func (*BufferEncoder) EncodeZeroPadding added in v1.2.0

func (e *BufferEncoder) EncodeZeroPadding(n int)

func (*BufferEncoder) GetBuffer added in v1.2.0

func (e *BufferEncoder) GetBuffer() []byte

func (*BufferEncoder) GetPosition added in v1.2.0

func (e *BufferEncoder) GetPosition() int

func (*BufferEncoder) Seekable added in v1.2.0

func (e *BufferEncoder) Seekable() bool

func (*BufferEncoder) SetBuffer added in v1.2.0

func (e *BufferEncoder) SetBuffer(buffer []byte)

type Decoder added in v1.2.0

type Decoder interface {
	Seekable() bool   // can use DecodeOffsetAt() and SkipBytes()
	GetPosition() int // return current position
	GetLength() int   // return remaining length
	PushLimit(limit int)
	PopLimit() int
	DecodeBool() (bool, error)
	DecodeUint8() (uint8, error)
	DecodeUint16() (uint16, error)
	DecodeUint32() (uint32, error)
	DecodeUint64() (uint64, error)
	DecodeBytes(buf []byte) ([]byte, error)
	DecodeBytesBuf(len int) ([]byte, error)
	DecodeOffset() (uint32, error)
	DecodeOffsetAt(pos int) uint32
	SkipBytes(n int)
}

type DynamicDecoder added in v1.2.0

type DynamicDecoder interface {
	UnmarshalSSZDecoder(ds DynamicSpecs, decoder Decoder) error
}

DynamicDecoder is the interface implemented by types that can unmarshal using dynamic SSZ and a decoder

type DynamicEncoder added in v1.2.0

type DynamicEncoder interface {
	MarshalSSZEncoder(ds DynamicSpecs, encoder Encoder) error
}

DynamicEncoder is the interface implemented by types that can marshal themselves using dynamic SSZ and an encoder

type DynamicHashRoot

type DynamicHashRoot interface {
	HashTreeRootWithDyn(ds DynamicSpecs, hh HashWalker) error
}

type DynamicMarshaler

type DynamicMarshaler interface {
	MarshalSSZDyn(ds DynamicSpecs, buf []byte) ([]byte, error)
}

DynamicMarshaler is the interface implemented by types that can marshal themselves using dynamic SSZ

type DynamicSizer

type DynamicSizer interface {
	SizeSSZDyn(ds DynamicSpecs) int
}

DynamicSizer is the interface implemented by types that can calculate their own SSZ size dynamically

type DynamicSpecs added in v1.1.0

type DynamicSpecs interface {
	ResolveSpecValue(name string) (bool, uint64, error)
}

DynamicSsz is the interface for a dynamic SSZ encoder/decoder

type DynamicUnmarshaler

type DynamicUnmarshaler interface {
	UnmarshalSSZDyn(ds DynamicSpecs, buf []byte) error
}

DynamicUnmarshaler is the interface implemented by types that can unmarshal using dynamic SSZ

type Encoder added in v1.2.0

type Encoder interface {
	Seekable() bool // can use EncodeOffsetAt()
	GetPosition() int
	GetBuffer() []byte       // return the output buffer (or a temp buffer if Seekable() is false)
	SetBuffer(buffer []byte) // set new output buffer (or write the buffer to the stream if Seekable() is false)
	EncodeBool(v bool)
	EncodeUint8(v uint8)
	EncodeUint16(v uint16)
	EncodeUint32(v uint32)
	EncodeUint64(v uint64)
	EncodeBytes(v []byte)
	EncodeOffset(v uint32)
	EncodeOffsetAt(pos int, v uint32)
	EncodeZeroPadding(n int)
}

type FastsszHashRoot

type FastsszHashRoot interface {
	HashTreeRoot() ([32]byte, error)
}

type FastsszMarshaler

type FastsszMarshaler interface {
	MarshalSSZTo(dst []byte) ([]byte, error)
	MarshalSSZ() ([]byte, error)
	SizeSSZ() int
}

FastsszMarshaler is the interface implemented by types that can marshal themselves into valid SZZ using fastssz.

type FastsszUnmarshaler

type FastsszUnmarshaler interface {
	UnmarshalSSZ(buf []byte) error
}

FastsszUnmarshaler is the interface implemented by types that can unmarshal a SSZ description of themselves

type HashWalker

type HashWalker interface {
	// Hash returns the latest hash generated during merkleize
	Hash() []byte

	// Methods for appending single values
	AppendBool(b bool)
	AppendUint8(i uint8)
	AppendUint16(i uint16)
	AppendUint32(i uint32)
	AppendUint64(i uint64)
	AppendBytes32(b []byte)

	// Methods for putting values into the buffer
	PutUint64Array(b []uint64, maxCapacity ...uint64)
	PutUint64(i uint64)
	PutUint32(i uint32)
	PutUint16(i uint16)
	PutUint8(i uint8)
	PutBitlist(bb []byte, maxSize uint64)
	PutProgressiveBitlist(bb []byte)
	PutBool(b bool)
	PutBytes(b []byte)

	// Buffer manipulation methods
	FillUpTo32()
	Append(i []byte)
	Index() int

	// temporary buffer methods
	WithTemp(func(tmp []byte) []byte)

	// Merkleization methods
	Merkleize(indx int)
	MerkleizeWithMixin(indx int, num, limit uint64)
	MerkleizeProgressive(indx int)
	MerkleizeProgressiveWithMixin(indx int, num uint64)
	MerkleizeProgressiveWithActiveFields(indx int, activeFields []byte)

	// HashRoot methods
	HashRoot() ([32]byte, error)
}

HashWalker is our own interface that mirrors fastssz.HashWalker This allows us to avoid importing fastssz directly while still being compatible with types that implement HashTreeRootWith

type StreamDecoder added in v1.2.0

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

func NewStreamDecoder added in v1.2.0

func NewStreamDecoder(reader io.Reader, totalLen int) *StreamDecoder

func (*StreamDecoder) DecodeBool added in v1.2.0

func (e *StreamDecoder) DecodeBool() (bool, error)

func (*StreamDecoder) DecodeBytes added in v1.2.0

func (e *StreamDecoder) DecodeBytes(buf []byte) ([]byte, error)

func (*StreamDecoder) DecodeBytesBuf added in v1.2.0

func (e *StreamDecoder) DecodeBytesBuf(l int) ([]byte, error)

func (*StreamDecoder) DecodeOffset added in v1.2.0

func (e *StreamDecoder) DecodeOffset() (uint32, error)

func (*StreamDecoder) DecodeOffsetAt added in v1.2.0

func (e *StreamDecoder) DecodeOffsetAt(pos int) uint32

func (*StreamDecoder) DecodeUint8 added in v1.2.0

func (e *StreamDecoder) DecodeUint8() (uint8, error)

func (*StreamDecoder) DecodeUint16 added in v1.2.0

func (e *StreamDecoder) DecodeUint16() (uint16, error)

func (*StreamDecoder) DecodeUint32 added in v1.2.0

func (e *StreamDecoder) DecodeUint32() (uint32, error)

func (*StreamDecoder) DecodeUint64 added in v1.2.0

func (e *StreamDecoder) DecodeUint64() (uint64, error)

func (*StreamDecoder) GetLength added in v1.2.0

func (e *StreamDecoder) GetLength() int

func (*StreamDecoder) GetPosition added in v1.2.0

func (e *StreamDecoder) GetPosition() int

func (*StreamDecoder) PopLimit added in v1.2.0

func (e *StreamDecoder) PopLimit() int

func (*StreamDecoder) PushLimit added in v1.2.0

func (e *StreamDecoder) PushLimit(limit int)

func (*StreamDecoder) Seekable added in v1.2.0

func (e *StreamDecoder) Seekable() bool

func (*StreamDecoder) SkipBytes added in v1.2.0

func (e *StreamDecoder) SkipBytes(n int)

type StreamEncoder added in v1.2.0

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

func NewStreamEncoder added in v1.2.0

func NewStreamEncoder(writer io.Writer) *StreamEncoder

func (*StreamEncoder) EncodeBool added in v1.2.0

func (e *StreamEncoder) EncodeBool(v bool)

func (*StreamEncoder) EncodeBytes added in v1.2.0

func (e *StreamEncoder) EncodeBytes(v []byte)

func (*StreamEncoder) EncodeOffset added in v1.2.0

func (e *StreamEncoder) EncodeOffset(v uint32)

func (*StreamEncoder) EncodeOffsetAt added in v1.2.0

func (e *StreamEncoder) EncodeOffsetAt(pos int, v uint32)

func (*StreamEncoder) EncodeUint8 added in v1.2.0

func (e *StreamEncoder) EncodeUint8(v uint8)

func (*StreamEncoder) EncodeUint16 added in v1.2.0

func (e *StreamEncoder) EncodeUint16(v uint16)

func (*StreamEncoder) EncodeUint32 added in v1.2.0

func (e *StreamEncoder) EncodeUint32(v uint32)

func (*StreamEncoder) EncodeUint64 added in v1.2.0

func (e *StreamEncoder) EncodeUint64(v uint64)

func (*StreamEncoder) EncodeZeroPadding added in v1.2.0

func (e *StreamEncoder) EncodeZeroPadding(n int)

func (*StreamEncoder) GetBuffer added in v1.2.0

func (e *StreamEncoder) GetBuffer() []byte

func (*StreamEncoder) GetPosition added in v1.2.0

func (e *StreamEncoder) GetPosition() int

func (*StreamEncoder) GetWriteError added in v1.2.0

func (e *StreamEncoder) GetWriteError() error

func (*StreamEncoder) Seekable added in v1.2.0

func (e *StreamEncoder) Seekable() bool

func (*StreamEncoder) SetBuffer added in v1.2.0

func (e *StreamEncoder) SetBuffer(buffer []byte)

Jump to

Keyboard shortcuts

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