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 ¶
- type ReflectionCtx
- func (ctx *ReflectionCtx) HashTreeRoot(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value, ...) error
- func (ctx *ReflectionCtx) MarshalSSZ(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value, ...) error
- func (ctx *ReflectionCtx) SizeSSZ(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value) (int64, error)
- func (ctx *ReflectionCtx) UnmarshalSSZ(targetType *ssztypes.TypeDescriptor, targetValue reflect.Value, ...) error
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, noDelegation bool, maxDepth int) *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; nil names no sink, and the default one answers for it
- verbose: enables verbose logging output
- noFastSsz: when true, disables fastssz fallback for types that implement fastssz interfaces, forcing all operations through reflection
- noDelegation: when true, disables delegation to a type's own generated Dynamic* SSZ methods, forcing the generic reflection walk. Custom types (which have no reflection representation) always delegate regardless.
- maxDepth: bounds how many recursion-cycle levels a value may nest before the walk fails with sszutils.ErrMaxDepthExceeded. A non-positive value selects defaultMaxNestingDepth. Only types flagged as recursion members count against it; every other type is unaffected.
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) (int64, 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.