views:

20

answers:

1

I want to tag each protobuf serialized data with my own version number. so i can check which version was used to serialize data if required. Although protobuf is designed around idea so you don't need to check version.

To do that i can use same way we have been doing in .net serialization add version field in it.

Just want to confirm that this is the preferred way of doing in protobuf as well.

class protodata1
{
  public protodata1()
 {
  version = 1;
 }
  [Protomember(1)]
  int version { get; set;}
  [Protomember(2)]
  int somedata { get; set;}
}

Also should be done like above in protobuf-net? assign version in constructor which will get override if class is getting desiralized. for new objects to be serialized it will use version 1

A: 

Well, if your meaning of "version" is simply as a data-field, then sure; just add it as a serialized member. Note that this won't have any special meaning during serialization (running it through an alternative contract, for example) - although as an aside there might be options here in "v2" if you need to support radically different message structures (a bad idea anyway).

The only caveat I might add is that any existing data that didn't already include this number will claim to be "version 1". In "v2" another option is to use the WCF approach of skipping the constructor (if you require). This will mean that these cases default instead to "version 0" - perhaps less confusing (or perhaps more confusing; I'll let you decide).

Marc Gravell

related questions