Skip to content

Commit

Permalink
Fix missing import for external []byte alias (ferranbt#167)
Browse files Browse the repository at this point in the history
* Fix missing import for external []byte alias

* Remove comment
  • Loading branch information
ferranbt authored and olegrok committed Jul 4, 2024
1 parent 05d4f47 commit 93de215
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 7 deletions.
10 changes: 3 additions & 7 deletions sszgen/generator/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ func (v *Value) unmarshal(dst string) string {
validate = fmt.Sprintf("if len(%s) > %d { return ssz.ErrBytesLength }\n", dst, v.m)
}

refName := ""
if v.ref != "" {
refName = v.ref + "." + v.obj
}

// both fixed and dynamic are decoded equally
tmpl := `{{.validate}}if cap(::.{{.name}}) == 0 {
{{if .refName}} ::.{{.name}} = {{ .refName }}(make([]byte, 0, len({{.dst}}))) {{ else }} ::.{{.name}} = make([]byte, 0, len({{.dst}})) {{ end }}
{{if .isRef}} ::.{{.name}} = {{ ref .obj }}(make([]byte, 0, len({{.dst}}))) {{ else }} ::.{{.name}} = make([]byte, 0, len({{.dst}})) {{ end }}
}
::.{{.name}} = append(::.{{.name}}, {{.dst}}...)`
return execTmpl(tmpl, map[string]interface{}{
"validate": validate,
"name": v.name,
"dst": dst,
"size": v.m,
"refName": refName,
"isRef": v.ref != "",
"obj": v,
})

case TypeUint:
Expand Down
9 changes: 9 additions & 0 deletions sszgen/testcases/issue_166.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package testcases

//go:generate go run ../main.go --path issue_166.go --include ./other

import "github.com/NilFoundation/fastssz/sszgen/testcases/other"

type Issue165 struct {
A other.Case4Bytes
}
106 changes: 106 additions & 0 deletions sszgen/testcases/issue_166_encoding.go

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

0 comments on commit 93de215

Please sign in to comment.