Skip to content

Commit

Permalink
feat: allow unmarshalling of object with same fields + more fields th…
Browse files Browse the repository at this point in the history
…an marshalled object
  • Loading branch information
dirkmc committed Feb 16, 2021
1 parent 169e9d7 commit fd5c031
Show file tree
Hide file tree
Showing 7 changed files with 709 additions and 3 deletions.
4 changes: 3 additions & 1 deletion gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
var _ = xerrors.Errorf
var _ = cid.Undef
`)
}
Expand Down Expand Up @@ -1269,7 +1270,8 @@ func (t *{{ .Name}}) UnmarshalCBOR(r io.Reader) error {

return doTemplate(w, gti, `
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
// Field doesn't exist on this type, so ignore it
cbg.ScanForLinks(r, func(cid.Cid){})
}
}
Expand Down
1 change: 1 addition & 0 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
defaultImports = []Import{
{Name: "cbg", PkgPath: "github.com/whyrusleeping/cbor-gen"},
{Name: "xerrors", PkgPath: "golang.org/x/xerrors"},
{Name: "cid", PkgPath: "github.com/ipfs/go-cid"},
}
)

Expand Down
2 changes: 2 additions & 0 deletions testgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func main() {
if err := cbg.WriteMapEncodersToFile("testing/cbor_map_gen.go", "testing",
types.SimpleTypeTree{},
types.NeedScratchForMap{},
types.SimpleStructV1{},
types.SimpleStructV2{},
); err != nil {
panic(err)
}
Expand Down
2 changes: 2 additions & 0 deletions testing/cbor_gen.go

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

Loading

0 comments on commit fd5c031

Please sign in to comment.