Protobuf.net & Conditional Serialization

We use protobuf.net to serialize classes between mobile devices and back end services, but now we need to configure what is sent back to the client based on the user's "context".

Usually we do this by implementing the ISerializable interface and consider the context value in order to later decide what to serialize. Similarly, in the constructor, we then deserialize the provided values.

But it looks like ISerializable is not implemented / supported (I don’t understand why) for protobuf.net, so we circumvented this by taking the approaches “ShouldSerialize *” and “OnSerializing”. However, this means that we ultimately have to store the StreamingContext in every class that doesn't seem right. We could use it on a global scale, but that is also not the case.

Is there a better way to achieve what we want, for example. serialization using protobuf.net format only, but does serialization depend on the external context?

+1
c # serialization deserialization protobuf-net
Apr 17 '12 at 11:15
source share
1 answer

That's a good question. Supported templates (ShouldSerialize * etc.) are borrowed "as is" entirely from BCL, therefore, there is no context - however, there are no reasons why it cannot support parameters in the same way as callbacks - indeed, for callbacks, which it supports pretty much any use (with / without context, etc.) - so I can't come up with a good reason not to support them here.

You are right, they say that it is not supported at the moment, but it could be - let me know about it, it would be useful.

0
Apr 20 '12 at 1:15
source share



All Articles