Files
prysm/encoding/ssz/query/list.go
Jun Song b1dc5e485d SSZ-QL: Handle List type & Populate the actual value dynamically (#15637)
* Add VariableTestContainer in ssz_query.proto

* Add listInfo

* Use errors.New for making an error with a static string literal

* Add listInfo field when analyzing the List type

* Persist the field order in the container

* Add actualOffset and goFieldName at fieldInfo

* Add PopulateFromValue function & update test runner

* Handle slice of ssz object for marshalling

* Add CalculateOffsetAndLength test

* Add comments for better doc

* Changelog :)

* Apply reviews from Radek

* Remove actualOffset and update offset field instead

* Add Nested container of variable-sized for testing nested path

* Fix offset adding logics: for variable-sized field, always add 4 instead of its fixed size

* Fix multiple import issue

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2025-09-08 16:50:24 +00:00

54 lines
1009 B
Go

package query
import (
"errors"
"fmt"
)
// listInfo holds information about a SSZ List type.
//
// length is initialized with zero,
// and can be set using SetLength while populating the actual SSZ List.
type listInfo struct {
// limit is the maximum number of elements in the list.
limit uint64
// element is the SSZ info of the list's element type.
element *sszInfo
// length is the actual number of elements at runtime (0 if not set).
length uint64
}
func (l *listInfo) Limit() uint64 {
if l == nil {
return 0
}
return l.limit
}
func (l *listInfo) Element() (*sszInfo, error) {
if l == nil {
return nil, errors.New("listInfo is nil")
}
return l.element, nil
}
func (l *listInfo) Length() uint64 {
if l == nil {
return 0
}
return l.length
}
func (l *listInfo) SetLength(length uint64) error {
if l == nil {
return errors.New("listInfo is nil")
}
if length > l.limit {
return fmt.Errorf("length %d exceeds limit %d", length, l.limit)
}
l.length = length
return nil
}