Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow unmarshaling of struct with more fields than marshaled struct #50

Merged
merged 2 commits into from
Feb 19, 2021

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Feb 16, 2021

It's useful to be able to add a field to a struct and for older versions of the code to ignore the added field when unmarshaling.

// V1
type Animal struct {
  Legs int
}

...

// V2
type Animal struct {
  Legs int
  Eyes int
}

This PR modifies the unmarshaling code such that it will ignore any fields it doesn't recognize.

@dirkmc dirkmc force-pushed the feat/round-trip-extra-fields branch from aed023e to b55741e Compare February 16, 2021 15:24
@dirkmc dirkmc force-pushed the feat/round-trip-extra-fields branch from b55741e to fd5c031 Compare February 16, 2021 15:26
@dirkmc dirkmc changed the title wip: add round-trip tests for v1 and v2 of object feat: allow unmarshaling of object with same fields + more fields than marshaled object Feb 16, 2021
@dirkmc dirkmc changed the title feat: allow unmarshaling of object with same fields + more fields than marshaled object feat: allow unmarshaling of object with more fields than marshaled object Feb 16, 2021
@dirkmc dirkmc changed the title feat: allow unmarshaling of object with more fields than marshaled object feat: allow unmarshaling of struct with more fields than marshaled struct Feb 16, 2021
Comment on lines +1273 to +1274
// Field doesn't exist on this type, so ignore it
cbg.ScanForLinks(r, func(cid.Cid){})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to make this opt-in (or not; I can't really think of anywhere where making it the default would be a problem)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the method name is moderately odd for what we use it here, but I guess that's ok 🤷

testing/types.go Show resolved Hide resolved
@dirkmc dirkmc requested a review from magik6k February 17, 2021 09:33
@Stebalien
Copy link
Collaborator

Just making sure: this only applies to maps, right?

@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants