Custom serialization/deserialization methods in protobuf-net

故事扮演 提交于 2019-12-13 02:29:16

问题


Is it possible to supply your own methods for serializing and deserializing a type for protobuf-net to use in its' Serializer.Serialize() and Serializer.Deserialize() methods?

i.e. Write my own code using ProtoWriter and ProtoReader, instead of marking up the class with serialization attributes.


回答1:


The mention of ProtoReader / ProtoWriter means this is a "v2" question, in which case you don't have to use the attributes at all - you can define the model at runtime via TypeModel. Re the question of custom serializers - at the moment, not exactly - but I expect I'll add an interface for this before long. The only problem is that the caller is then responsible You might also want to look at the experimental DataTable serializer, which does something similar.

There are some technical considerations too, though; in particular inheritance; the obvious pattern would be for your class to implement an interface, but this means that once the object is created it is too late to create a subclass. Unless the type that implements the interface isn't the entity itself, but a separate type that juts handles serialization/deserialization...



来源:https://stackoverflow.com/questions/4523165/custom-serialization-deserialization-methods-in-protobuf-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!