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) (uint32, 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 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.