diff --git a/sszgen/generator/size.go b/sszgen/generator/size.go index f19c12d..08f27ae 100755 --- a/sszgen/generator/size.go +++ b/sszgen/generator/size.go @@ -19,16 +19,29 @@ func (e *env) size(name string, v *Value) string { {{.dynamic}} {{end}} return - }` + } + {{.fieldsMaxSizes}} + ` str := execTmpl(tmpl, map[string]interface{}{ - "name": name, - "fixed": v.fixedSize(), - "dynamic": v.sizeContainer("size", true), + "name": name, + "fixed": v.fixedSize(), + "dynamic": v.sizeContainer("size", true), + "fieldsMaxSizes": v.fieldsMaxSizes(name), }) return appendObjSignature(str, v) } +func (v *Value) fieldsMaxSizes(name string) string { + out := []string{} + for _, v := range v.o { + if !v.isFixed() { + out = append(out, fmt.Sprintf("const %sMax%sSize = %d", name, v.name, v.s)) + } + } + return strings.Join(out, "\n") +} + func (v *Value) fixedSize() uint64 { switch v.t { case TypeVector: