Documentation
¶
Index ¶
Constants ¶
const BasicArraySizeCache = 100000
BasicArraySizeCache for HashTreeRoot.
const BasicTypeCacheSize = 100000
BasicTypeCacheSize for HashTreeRoot.
const RootsArraySizeCache = 100000
RootsArraySizeCache for hash tree root.
Variables ¶
var ( // BytesPerChunk for an SSZ serialized object. BytesPerChunk = 32 // BytesPerLengthOffset defines a constant for off-setting serialized chunks. BytesPerLengthOffset = uint64(4) )
var StructFactory = newStructSSZ()
StructFactory exports an implementation of a interface containing helpers for marshaling/unmarshaling, and determining the hash tree root of struct values.
var UnboundedSSZFieldSizeMarker = "?"
UnboundedSSZFieldSizeMarker is the character used to specify a ssz field should have unbounded size, which is useful when describing slices of arrays such as [][32]byte. The ssz struct tag for such field type would be `ssz:"size=?,32"`. A question mark is chosen as the default value given its simplicity to represent unbounded size.
Functions ¶
func BitlistRoot ¶
BitlistRoot computes the hash tree root of a bitlist type as outlined in the Simple Serialize official specification document.
func Bitvector4Root ¶
Bitvector4Root computes the hash tree root of a bitvector4 type as outlined in the Simple Serialize official specification document.
func DetermineSize ¶
DetermineSize returns the required byte size of a buffer for using SSZ to marshal an object.
func ToggleCache ¶
func ToggleCache(val bool)
ToggleCache enables caching of ssz hash tree root. It is disabled by default.
Types ¶
type SSZAble ¶
type SSZAble interface { Root(val reflect.Value, typ reflect.Type, fieldName string, maxCapacity uint64) ([32]byte, error) Marshal(val reflect.Value, typ reflect.Type, buf []byte, startOffset uint64) (uint64, error) Unmarshal(val reflect.Value, typ reflect.Type, buf []byte, startOffset uint64) (uint64, error) }
SSZAble defines a type which can marshal/unmarshal and compute its hash tree root according to the Simple Serialize specification. See: https://github.com/ethereum/eth2.0-specs/blob/v0.8.2/specs/simple-serialize.md.
func SSZFactory ¶
SSZFactory recursively walks down a type and determines which SSZ-able core type it belongs to, and then returns and implementation of SSZ-able that contains marshal, unmarshal, and hash tree root related functions for use.