Skip to content Skip to sidebar Skip to footer

Protobuf-net Won't Deserialize Data From Protobuf.js

I'm using Protobuf for the communication between my web client and server (C#), using WebSocket. On the client, the de/serialization is done through Protobuf.js and, on the server,

Solution 1:

The long and short of it is that protobuf-net's polymorpism support expects the sub-type to be first in the message (or more specifically: for any object, the type will be fixed before data is provided). In the js output, the field data for BaseProperty comes first - perfectly reasonably, perhaps. But since there is no over-arching protocol definition of how inheritance should behave, protobuf-net's implementation was only really ever intended to work with itself. In terms of the bytes, this actually comes down to where the field marker "162, 6" (and the associated length/data, "5, 13, 0, 0, 0, 63") appears.

The library could potentially be reworked to allow any field order for polymorphism, but: it would take some effort. I am aware that it is usually expected to process fields in any order, but since this is already outside of the specification, I didn't focus on this. All other data fields are accepted in any order - only polymorphism works this way.

In the general case: since polymorphism is not part of the specification, I would strongly recommend avoiding polymorphism when working between libraries.

Note: you can probably force this to work by ensuring the polymorphism fields are lower (numerically) than the data fields.

Post a Comment for "Protobuf-net Won't Deserialize Data From Protobuf.js"