mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
* Move ssz_query objects into testing folder (ensuring test objects only used in test environment) * Add containers for response * Export sszInfo * Add QueryBeaconState/Block * Add comments and few refactor * Fix merge conflict issues * Return 500 when calculate offset fails * Add test for QueryBeaconState * Add test for QueryBeaconBlock * Changelog :) * Rename `QuerySSZRequest` to `SSZQueryRequest` * Fix middleware hooks for RPC to accept JSON from client and return SSZ * Convert to `SSZObject` directly from proto * Move marshalling/calculating hash tree root part after `CalculateOffsetAndLength` * Make nogo happy * Add informing comment for using proto unsafe conversion --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
40 lines
628 B
Go
40 lines
628 B
Go
package query
|
|
|
|
import "errors"
|
|
|
|
// vectorInfo holds information about a SSZ Vector type.
|
|
type vectorInfo struct {
|
|
// element is the SSZ info of the vector's element type.
|
|
element *SszInfo
|
|
// length is the fixed length of the vector.
|
|
length uint64
|
|
}
|
|
|
|
func (v *vectorInfo) Length() uint64 {
|
|
if v == nil {
|
|
return 0
|
|
}
|
|
|
|
return v.length
|
|
}
|
|
|
|
func (v *vectorInfo) Element() (*SszInfo, error) {
|
|
if v == nil {
|
|
return nil, errors.New("vectorInfo is nil")
|
|
}
|
|
|
|
return v.element, nil
|
|
}
|
|
|
|
func (v *vectorInfo) Size() uint64 {
|
|
if v == nil {
|
|
return 0
|
|
}
|
|
|
|
if v.element == nil {
|
|
return 0
|
|
}
|
|
|
|
return v.length * v.element.Size()
|
|
}
|