Documentation
¶
Overview ¶
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
Package dynssz provides dynamic SSZ (Simple Serialize) encoding and decoding for Ethereum data structures. Unlike static code generation approaches, dynssz uses runtime reflection to handle dynamic field sizes, making it suitable for various Ethereum presets beyond the mainnet. It seamlessly integrates with fastssz for optimal performance when static definitions are applicable.
Copyright (c) 2024 by pk910. See LICENSE file for details.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
dynssz: Dynamic SSZ encoding/decoding for Ethereum with fastssz efficiency. This file is part of the dynssz package. Copyright (c) 2024 by pk910. Refer to LICENSE for more information.
Index ¶
- Variables
- func CalculateLimit(maxCapacity, numItems, size uint64) uint64
- type DynSsz
- type HashFn
- type Hasher
- func (h *Hasher) Append(i []byte)
- func (h *Hasher) AppendBytes32(b []byte)
- func (h *Hasher) AppendUint8(i uint8)
- func (h *Hasher) AppendUint32(i uint32)
- func (h *Hasher) AppendUint64(i uint64)
- func (h *Hasher) FillUpTo32()
- func (h *Hasher) Hash() []byte
- func (h *Hasher) HashRoot() (res [32]byte, err error)
- func (h *Hasher) Index() int
- func (h *Hasher) Merkleize(indx int)
- func (h *Hasher) MerkleizeWithMixin(indx int, num, limit uint64)
- func (h *Hasher) PutBitlist(bb []byte, maxSize uint64)
- func (h *Hasher) PutBool(b bool)
- func (h *Hasher) PutBytes(b []byte)
- func (h *Hasher) PutRootVector(b [][]byte, maxCapacity ...uint64) error
- func (h *Hasher) PutUint8(i uint8)
- func (h *Hasher) PutUint16(i uint16)
- func (h *Hasher) PutUint32(i uint32)
- func (h *Hasher) PutUint64(i uint64)
- func (h *Hasher) PutUint64Array(b []uint64, maxCapacity ...uint64)
- func (h *Hasher) Reset()
- type HasherPool
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIncorrectByteSize means that the byte size is incorrect ErrIncorrectByteSize = fmt.Errorf("incorrect byte size") // ErrIncorrectListSize means that the size of the list is incorrect ErrIncorrectListSize = fmt.Errorf("incorrect list size") )
var ( ErrOffset = fmt.Errorf("incorrect offset") ErrSize = fmt.Errorf("incorrect size") ErrBytesLength = fmt.Errorf("bytes array does not have the correct length") ErrVectorLength = fmt.Errorf("vector does not have the correct length") ErrListTooBig = fmt.Errorf("list length is higher than max value") ErrEmptyBitlist = fmt.Errorf("bitlist is empty") ErrInvalidVariableOffset = fmt.Errorf("invalid ssz encoding. first variable element offset indexes into fixed value data") )
Functions ¶
func CalculateLimit ¶ added in v0.0.6
Types ¶
type DynSsz ¶
DynSsz is a dynamic SSZ encoder/decoder that uses runtime reflection to handle dynamic field sizes. The instance holds caches for referenced types, so it's recommended to reuse the same instance to speed up the encoding/decoding process.
func NewDynSsz ¶
NewDynSsz creates a new instance of the DynSsz encoder/decoder. The 'specs' map contains dynamic properties and configurations that will be applied during SSZ serialization and deserialization processes. This allows for flexible and dynamic handling of SSZ encoding/decoding based on the given specifications, making it suitable for various Ethereum presets and custom scenarios. Returns a pointer to the newly created DynSsz instance, ready for use in serializing and deserializing operations.
func (*DynSsz) HashTreeRoot ¶ added in v0.0.6
HashTreeRoot computes the hash tree root of the given source object. This method uses the default hasher pool to get a new hasher instance, builds the root from the source object, and returns the computed hash root. It returns the computed hash root and an error if the process fails.
func (*DynSsz) MarshalSSZ ¶
MarshalSSZ serializes the given source into its SSZ (Simple Serialize) representation. It dynamically handles the serialization of types, including those with dynamic field sizes, by leveraging reflection at runtime. This method integrates with fastssz for types without dynamic specifications, optimizing performance. It returns the serialized data as a byte slice, or an error if serialization fails.
func (*DynSsz) MarshalSSZTo ¶
MarshalSSZTo serializes the given source into its SSZ (Simple Serialize) representation and writes the output to the provided buffer. This method allows direct control over the serialization output buffer, allowing optimizations like buffer reuse. The 'source' parameter is the structure to be serialized, and 'buf' is the pre-allocated slice where the serialized data will be written. It dynamically handles serialization for types with dynamic field sizes, seamlessly integrating with fastssz when possible. Returns the updated buffer containing the serialized data and an error if serialization fails.
func (*DynSsz) SizeSSZ ¶
SizeSSZ calculates the size of the given source object when serialized using SSZ encoding. This function is useful for pre-determining the amount of space needed to serialize a given source object. The 'source' parameter can be any Go value. It dynamically evaluates the size, accommodating types with dynamic field sizes efficiently. Returns the calculated size as an int and an error if the process fails.
func (*DynSsz) UnmarshalSSZ ¶
UnmarshalSSZ decodes the given SSZ-encoded data into the target object. The 'ssz' byte slice contains the SSZ-encoded data, and 'target' is a pointer to the Go value that will hold the decoded data. This method dynamically handles the decoding, accommodating for types with dynamic field sizes. It seamlessly integrates with fastssz for types without dynamic specifications to ensure efficient decoding. Returns an error if decoding fails or if the provided ssz data has not been fully used for decoding.
type HashFn ¶ added in v0.0.6
func NativeHashWrapper ¶ added in v0.0.6
NativeHashWrapper wraps a hash.Hash function into a HashFn
type Hasher ¶ added in v0.0.6
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a utility tool to hash SSZ structs
func NewHasher ¶ added in v0.0.6
func NewHasher() *Hasher
NewHasher creates a new Hasher object with sha256 hash
func NewHasherWithHash ¶ added in v0.0.6
NewHasherWithHash creates a new Hasher object with a custom hash.Hash function
func NewHasherWithHashFn ¶ added in v0.0.6
NewHasherWithHashFn creates a new Hasher object with a custom HashFn function
func (*Hasher) AppendBytes32 ¶ added in v0.0.6
func (*Hasher) AppendUint8 ¶ added in v0.0.6
func (*Hasher) AppendUint32 ¶ added in v0.0.6
func (*Hasher) AppendUint64 ¶ added in v0.0.6
func (*Hasher) FillUpTo32 ¶ added in v0.0.6
func (h *Hasher) FillUpTo32()
func (*Hasher) Merkleize ¶ added in v0.0.6
Merkleize is used to merkleize the last group of the hasher
func (*Hasher) MerkleizeWithMixin ¶ added in v0.0.6
MerkleizeWithMixin is used to merkleize the last group of the hasher
func (*Hasher) PutBitlist ¶ added in v0.0.6
PutBitlist appends a ssz bitlist
func (*Hasher) PutRootVector ¶ added in v0.0.6
PutRootVector appends an array of roots
func (*Hasher) PutUint64Array ¶ added in v0.0.6
PutUint64Array appends an array of uint64
type HasherPool ¶ added in v0.0.6
type HasherPool struct {
// contains filtered or unexported fields
}
HasherPool may be used for pooling Hashers for similarly typed SSZs.
var DefaultHasherPool HasherPool
DefaultHasherPool is a default hasher pool
func (*HasherPool) Get ¶ added in v0.0.6
func (hh *HasherPool) Get() *Hasher
Get acquires a Hasher from the pool.
func (*HasherPool) Put ¶ added in v0.0.6
func (hh *HasherPool) Put(h *Hasher)
Put releases the Hasher to the pool.