Skip to content

Commit

Permalink
Revert "fix(generator): Unmarshaling of fixed sized custom types is g…
Browse files Browse the repository at this point in the history
…enerated incorrectly. (ferranbt#152)"

This reverts commit b8fd7b4.
  • Loading branch information
itsdevbear committed Apr 7, 2024
1 parent b8fd7b4 commit c2bc1c1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 156 deletions.
5 changes: 2 additions & 3 deletions sszgen/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ func detectImports(v *Value) string {
ref = v.ref
case TypeList, TypeVector:
ref = v.e.ref
case TypeBytes:
ref = v.ref
default:
ref = v.ref
}
Expand All @@ -225,6 +223,7 @@ func (v *Value) objRef() string {
if v.ref == "" {
return v.obj
}

valuesImported = append(valuesImported, v)
return v.ref + "." + v.obj
}
Expand Down Expand Up @@ -323,6 +322,7 @@ type env struct {

func (e *env) generateOutputEncodings(output string) (map[string]string, error) {
out := map[string]string{}

keys := make([]string, 0, len(e.order))
for k := range e.order {
keys = append(keys, k)
Expand Down Expand Up @@ -444,7 +444,6 @@ func (e *env) print(order []string) (string, bool, error) {
// require the sszgen functions.
continue
}

objs = append(objs, &Obj{
HashTreeRoot: e.hashTreeRoot(name, obj),
GetTree: e.getTree(name, obj),
Expand Down
15 changes: 6 additions & 9 deletions sszgen/generator/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,18 @@ func (v *Value) createSlice(useNumVariable bool) string {
return fmt.Sprintf("::.%s = make([]%s%s, %s)", v.name, ptr, v.e.objRef(), size)

case TypeBytes:
// [][]byte
if v.c {
return ""
}

// Check for a type alias.
ref := v.e.objRef()
if ref != "" {
return fmt.Sprintf("::.%s = make([]%s, %s)", v.name, ref, size)
}

if v.e.c {
return fmt.Sprintf("::.%s = make([][%d]byte, %s)", v.name, v.e.s, size)
}

return fmt.Sprintf("::.%s = make([][]byte, %s)", v.name, size)
ref := v.e.objRef()
if ref == "" {
ref = "[]byte"
}
return fmt.Sprintf("::.%s = make([]%s, %s)", v.name, ref, size)

default:
panic(fmt.Sprintf("create not implemented for %s type %s", v.name, v.e.t.String()))
Expand Down
11 changes: 0 additions & 11 deletions sszgen/testcases/pr_152.go

This file was deleted.

133 changes: 0 additions & 133 deletions sszgen/testcases/pr_152_encoding.go

This file was deleted.

0 comments on commit c2bc1c1

Please sign in to comment.