We use .net binary serialization right now to serialize data to persist. It does the job but doesn’t fell like it’s intended to use for that purpose as changing data is not so trivial.
So i started looking into protobuf as it is designed around that purpose.
i am looking at protobuf-net to how to use it. Below are some thing i don’t know yet. if you got an answer already it will save my day.
- I don’t care about .proto files as product is just in .net. So can i use protobuf-net without having .proto files.
- If yes, can i later generate .proto file out of my c# classes if need port to other language
Yes, protobuf-net works without .proto files. In fact, for protobuf-net the core was written long before the .proto support. All you need is something that allows it to obtain a unique number for each member you want to serialize. In “v2” (not released) you can do this externally, but in the available dll this means attributes. This can be the bespoke protobuf-net attributes, or you can use (for example) the
DataContractSerializerattributes if that is more convenient:There is support for generating a .proto file (
Serializer.GetProto) – however, there are some caveats:floatanddoublemap directly to protobuf types (available in every implementation), that is not true ofdecimalandDateTime; if you think interop is an issue, it may be worth simplifying this from the start – for example deciding that you are going to send aDateTime, perhaps send alongthat represents the offset into an epoch instead? easy to interpret in any implementation.