Reputation: 7933
I have been looking for a solution for this for a little while and non of the stuff I've found quite matches. It is great that C# has a built in serialization library but that is not quite what I am looking for. I need to serialize objects in such a way that I can serialize them, append header data to the packet ie. ID number, timestamp, object type etc. and then be able to send it out without having to keep in mind the platform I am sending it to. In other words, I should be able to unwrap my packet in C++ or in Java without much more knowledge than what object type I am casting into and the order of header data. The binary formatter in C# creates a problem because it is designed to be deserialized on the other end using the same library. It also creates bloated packets which I would rather not have to deal with. I would rather format my packet as such
|========|========|=========|===|==============|
| packetID | datatype | timeStamp | etc | serializedObject |
|========|========|=========|===|==============|
It would be nice if I had access to something along the lines of memcpy in order to achieve this because then as long as the data type order of the object being deserialized into matches (Yes, assuming the other language has the same byte sizes for datatypes), it is easy to grab data from the server on a new platform (say I want to grab data of an Android (Java) or an iPhone (obj. C)) with little hassle
Upvotes: 0
Views: 446
Reputation: 3803
I've used Google's protocol buffers to good effect. It's small, fast, cross platform, backwards compatible and serializes to a binary format. It doesn't support the custom header information you're looking for, but if you can frame your own packets you can tack a custom header onto the binary stream as you see fit. Protobuf can compile down into C#, iOS, Java and C++.
Upvotes: 3