Skip to content

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

@timotheecour

Description

@timotheecour

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions