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

allow option for deserializing with missing, extra, or renamed fields #88

Open
timotheecour opened this issue Oct 14, 2016 · 1 comment

Comments

@timotheecour
Copy link

happy to discuss design of this

this is one of the best features of protocol buffers, allowing one to be forward and backward compatible with schema changes.

Eg:

struct Dataset{int age; int height;}
Dataset(13).pack.writeToFile("dataset.mpck");

// later on, Dataset is updated but we still want to use the saved data
struct Dataset{int age; string address = "bar";}
auto dataset="dataset.mpck".read.unpack!Dataset;
// currently, error: incompatible type
  • NOTE: error is actually uninformative, it should also show which fields are wrong
// desired behavior:
struct MsgpackOption{
 bool allow_missing_fields=false;
 bool allow_added_fields=false;
}

MsgpackOption opt={allow_missing_fields:true, allow_added_fields:true};
auto dataset="dataset.mpck".read.unpack!Dataset(opt);
assert(dataset==Dataset(13, "bar"));
  • NOTE: should also work with reordered fields (eg: struct Dataset{int height;int age; }, possibly modulo an option bool allow_reordered_fields
@repeatedly
Copy link
Member

Allowing missing / extra fields seems good for me.
msgpack doesn't have a schema unlike protocol buffers, so
it seems to work with only tail fields.
I will try to implement it.

For reorder support, user should provide serialized data index to actual struct field index.
For such case, msgpack seems to not fit...

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

No branches or pull requests

2 participants