This is specifically a protobuf-net question.

In short, yes - that is fine... ish. If you add the numbers manually ***and
get them right***, then it will work. However, your example actually gets
them wrong: the protobuf-net library specifically assumes an *alphabetical*
order for the properties / fields when using ImplicitFields, because
reflection does not guarantee any particular order - see the "Remarks"
section on MSDN: http://msdn.microsoft.com/en-us/library/6ztex2dc.aspx and
http://msdn.microsoft.com/en-us/library/kyaxdd3x.aspx

So the order is actually: Id = 1, IsAvailable = 2, Name = 3, Quantity = 4 -
you would then add NewField1 and NewField2 as 5 and 6, presumably.

Just to quote from the documentation on ImplicitFields, too:

    /// <summary>
    /// Specifies the method used to infer field tags for members of the type
    /// under consideration. Tags are deduced using the invariant alphabetic
    /// sequence of the members' names; this makes implicit field tags
very brittle,
    /// and susceptible to changes such as field names (normally an isolated
    /// change).
    /// </summary>


Marc
(protobuf-net)


On 15 July 2013 06:48, Pravesh Tanwar <[email protected]> wrote:

> 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.
>
>
>



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to