Search code examples
javac#.netprotocol-buffersprotobuf-net

Can I use Protobuf-net to deserilaze data which has been serialized in Java?


We have a Java based WebSocket that is currently returning JSON which we are then consuming in a .Net application. Due to the size of the data we receive, I would like to start taking advantage of all the goodness that Protocol Buffers provide specially with regards to size/bandwidth and the saving around time/resources on both sides during serialization and deserialization.

My question is:

If I ask our Java team to replace their JSON serializer with the Java implementation of Protobuf am I then able to use Protobuf-net in my .Net consumer to deserialize it?

In other words how can I ensure my POCO matches their POJO!?

[*]: Please note this is not a question around the performance benefits of different JSON serlializers, It is specific to Protobufs.


Solution

  • Yes, absolutely.

    Protocol Buffers were designed to to be language agnostic. In fact, one of their main uses is to communicate between machines that are running different stacks.

    On the wire, protocol buffers are no different than XML or JSON. In that they are language independent.

    To deserialize, you should use Google's machine generated code for both .Net and Java. This will ensure that your Protocol Buffers are deserialized correctly.