Sorry - intended to cc the list for reference purposes -------------------------------------------
This is protobuf-net specific; sorry for delay bit I'm on a family weekend and my wife deliberately picks destinations far far away from cell towers. To explain: protobuf-net always starts from the root type; the most-base-type that it knows of as a contract. This means that you can still deserialize the base-type information. This mimics the scenario where you receive a message from an up-level caller who knows about a new subtype. It will deserialize as much as it can, basically. Does that answer things? Do you need more? On 15 Mar 2013 23:35, "Wallace Turner" <[email protected]> wrote: > Consider these simple classes: > > [DataContract] >> public class Container >> { >> [DataMember(Order = 1)] >> public Order Order { get; set; } >> } >> >> [DataContract] >> public class Order >> { >> [DataMember(Order = 1)] >> public string Field1 { get; set; } >> } >> [DataContract] >> public class SubOrder : Order >> { >> [DataMember(Order = 1)] >> public string Field2 { get; set; } >> } > > > > I have serialized a populated instance of Container to a base64 string: > > RuntimeTypeModel.Default[typeof(Order)].AddSubType(100, typeof(SubOrder)); >> var tmp = new Container() { Order = new SubOrder { Field1 = "field1", >> Field2 = "field2" } }; >> Trace.WriteLine(Convert.ToBase64String(tmp.SerializeProto())); > > > after which I removed the reference to SubOrder and attempted to > deserialize the base64 string back to Container - to my surprise this > worked! > > I understand the type information is not saved but there must be a set of > circumstances under which this would not work - that is, if you start > adding new fields to Order and then attempt deserialization? or perhaps > something else? > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/protobuf?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Regards, Marc -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
