Are you sure you want to use ProtoBuf? You can use Json first, and then switch to Bson or MessagePack as a binary format.
The Json / Bson combination has the advantage that you can use the same library for them (Json.net). I believe Bson is a little bigger than ProtoBuf.
Or you can use Json / MessagePack. Technically, MessagePack is a better binary format than Bson / ProtoBuf IMO. But toolkit support is worse, and you will need a separate library for Json and MessagePack. It supports all Json and much more (in particular, it can use both dictionary and whole keys in dictionaries).
A quick comparison of MsgPack and ProtoBuf:
- The resulting data size, if similar constructions are used, seems comparable.
- Encoding / decoding performance is highly dependent on implementation, but I expect it to have a similar value.
- MsgPack describes itself more., In ProtoBuf you donβt even see if something is subordinate or blob.
- MsgPack supports non-integer keys in a dictionary. One thing that allows this is to save properties by name when you don't care about size and switch to integers where there are big profits.
- MsgPack stores the counter of elements instead of the size for arrays / dictionaries. This has the advantage that you donβt have to go back and fit in the size all the time, which makes it easier to write to the serializer and possibly gives a higher write speed. On the other hand, you cannot easily skip an element because you do not know its size.
- MsgPack naturally supports a superset of Json, so you can easily migrate from Json.
- Protocol support, documentation, and popularity are much better with ProtoBuf. In particular, ProtoBuf.net looks better than the C # code available for MsgPack.
source share