Hi All,
I am currently using Protobuf serializer in my C# project. Currently I am
serializing my Objects using "
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]". The serialized
objects are stored in database and deserialized when needed. I have now
landed in a position that requires me to add new DataMembers to existing
object. I want to be able to do this without breaking backward
compatibility (while deserializing) of my current serialized objects.
Is there a way for me to check what order does the Protobuf
serialize/deserialize objects?
e.g of the Object being serialized:
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class Product
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public double Quantity { get; set; }
[DataMember]
public bool? IsAvailable { get; set; }
}
If I can know what order they are currently being serialized then I can use
the "Order" data member attribute and make sure that the additional fields are
ordered at the end. Hopefully this will retain backward compatibility while
deserializing. e.g:
public class Product
{
[DataMember(Order = 1)]
public int Id { get; set; }
[DataMember(Order = 2)]
public double Quantity { get; set; }
[DataMember(Order = 3)]
public bool? IsAvailable { get; set; }
[DataMember(Order = 4)]
public string Name { get; set; }
[DataMember(Order = 5)]
public string NewField1 { get; set; }
[DataMember(Order = 6)]
public string NewField2 { get; set; }
}
Any ideas?
--
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.
For more options, visit https://groups.google.com/groups/opt_out.