Skip to content

Commit

Permalink
support list of non-ptr containers (ferranbt#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
letonchanh authored Mar 25, 2024
1 parent 274d5da commit 3fad963
Show file tree
Hide file tree
Showing 3 changed files with 314 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sszgen/generator/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ func (v *Value) createSlice(useNumVariable bool) string {

case TypeContainer:
// []*(ref.)Struct{}
return fmt.Sprintf("::.%s = make([]*%s, %s)", v.name, v.e.objRef(), size)
ptr := "*"
if v.e.noPtr {
ptr = ""
}
return fmt.Sprintf("::.%s = make([]%s%s, %s)", v.name, ptr, v.e.objRef(), size)

case TypeBytes:
// [][]byte
Expand Down
15 changes: 15 additions & 0 deletions sszgen/testcases/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testcases

//go:generate go run ../main.go --path list.go

type BytesWrapper struct {
Bytes []byte `ssz-size:"48"`
}

type ListC struct {
Elems []BytesWrapper `ssz-max:"32"`
}

type ListP struct {
Elems []*BytesWrapper `ssz-max:"32"`
}
294 changes: 294 additions & 0 deletions sszgen/testcases/list_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fad963

Please sign in to comment.