types

package
v0.0.0-...-f620887 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const BasicArraySizeCache = 100000

BasicArraySizeCache for HashTreeRoot.

View Source
const BasicTypeCacheSize = 100000

BasicTypeCacheSize for HashTreeRoot.

View Source
const RootsArraySizeCache = 100000

RootsArraySizeCache for hash tree root.

Variables

View Source
var (
	// BytesPerChunk for an SSZ serialized object.
	BytesPerChunk = 32
	// BytesPerLengthOffset defines a constant for off-setting serialized chunks.
	BytesPerLengthOffset = uint64(4)
)
View Source
var StructFactory = newStructSSZ()

StructFactory exports an implementation of a interface containing helpers for marshaling/unmarshaling, and determining the hash tree root of struct values.

View Source
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

func BitlistRoot(bfield bitfield.Bitfield, maxCapacity uint64) ([32]byte, error)

BitlistRoot computes the hash tree root of a bitlist type as outlined in the Simple Serialize official specification document.

func Bitvector4Root

func Bitvector4Root(bfield bitfield.Bitfield, maxCapacity uint64) ([32]byte, error)

Bitvector4Root computes the hash tree root of a bitvector4 type as outlined in the Simple Serialize official specification document.

func DetermineSize

func DetermineSize(val reflect.Value) uint64

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

func SSZFactory(val reflect.Value, typ reflect.Type) (SSZAble, error)

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.

Jump to

Keyboard shortcuts

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