reflection

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package reflection provides runtime reflection-based SSZ encoding, decoding, and hash tree root computation.

It inspects Go struct types at runtime using type descriptors from the ssztypes package to perform SSZ operations without requiring code generation. This approach supports dynamic field sizes resolved through specification values, making it suitable for types whose SSZ layout varies across configurations (e.g., Ethereum mainnet vs. minimal presets).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReflectionCtx

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

ReflectionCtx holds the configuration for reflection-based SSZ operations. It wraps a DynamicSpecs provider for resolving dynamic field sizes, along with options controlling fastssz fallback behavior and logging.

func NewReflectionCtx

func NewReflectionCtx(ds sszutils.DynamicSpecs, logCb func(format string, args ...any), verbose, noFastSsz bool) *ReflectionCtx

NewReflectionCtx creates a new ReflectionCtx with the given configuration.

Parameters:

  • ds: provides dynamic specification values for resolving field sizes
  • logCb: callback for debug logging (may be nil)
  • verbose: enables verbose logging output
  • noFastSsz: when true, disables fastssz fallback for types that implement fastssz interfaces, forcing all operations through reflection

func (*ReflectionCtx) HashTreeRoot

func (ctx *ReflectionCtx) HashTreeRoot(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value, hh sszutils.HashWalker) error

HashTreeRoot computes the SSZ hash tree root of targetValue using the provided HashWalker and type descriptor.

func (*ReflectionCtx) MarshalSSZ

func (ctx *ReflectionCtx) MarshalSSZ(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value, encoder sszutils.Encoder) error

MarshalSSZ encodes targetValue into SSZ format using the provided encoder and type descriptor.

func (*ReflectionCtx) SizeSSZ

func (ctx *ReflectionCtx) SizeSSZ(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value) (uint32, error)

SizeSSZ computes the SSZ-encoded byte size of targetValue using its type descriptor.

func (*ReflectionCtx) UnmarshalSSZ

func (ctx *ReflectionCtx) UnmarshalSSZ(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value, decoder sszutils.Decoder) error

UnmarshalSSZ decodes SSZ data from the provided decoder into targetValue using the type descriptor.

Jump to

Keyboard shortcuts

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