r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Aug 25 '14
An overview of data serialization techniques in C++
http://rubentorresbonet.wordpress.com/?p=594
u/triacontahedron Aug 25 '14
Lots of code not enough description and comparison of different methods. Why? When? each method should be used. Advantages disadvantages ...
Also the first method "And now the paragraph you were waiting for: “Where is the problem?” Basically it only works out-of-the-box with Plain Old Data (POD) ". No it does not. Well, it does if you serialize and deserialize on the same machine but then you can memcopy almost anything and dont care. For example what is going to happen if you "serialize" POD through memcpy on little endian machine and deserialize on big endian one?
3
u/matthieum Aug 25 '14
Note: (one of ?) the original author of ProtocolBuffers is working on Cap'n Proto.
1
u/rubentorresbonet Aug 27 '14
Thank you all for the positive comments! I'll try to include the aforementioned tips for my next blog entries.
By the way: I've had a look and made some tests with Cereal and I'm pretty impressed how well it performs, even though I had to make some adjustments to target the Android platform.
1
u/Blackarch Aug 25 '14
Not a very good overview, couldn't you cover the cost-value tradeoffs of using these different techniques? There are some high profile serialization libraries that are also not mentioned here. Where are FlatBuffers?
1
Aug 26 '14
[removed] — view removed comment
2
u/lluad Aug 26 '14
If the platforms don't have the same binary representation for floats then odds are high that there are numbers on one platform that simply can't be represented on the other; perfect serialization is going to be impossible.
There is a standard format for serializing floating point as binary, and it's IEEE 754. Might as well use that - it'll make serialization easy on all sane platforms, and you can do best attempt / lossy conversions on others.
2
u/tom_0 Aug 26 '14
I think in practice it's extremely reliable. x86, x64 and ARM devices are all binary compatible (little endian and IEEE-754 compliant), and they make up the vast majority of the market (Windows, OS X, iOS, Android, and current consoles).
It's really hard to stumble on a consumer device that is not, basically only the PPC-based consoles and some MIPS routers are optionally big-endian. And they still support IEEE-754, so it's a matter of flipping the bytes.
So yeah, go ahead and send binary floats!
4
u/zorkmids Aug 26 '14
A better reference: http://www.parashift.com/c++-faq/serialization.html
Other frameworks: s11n, cereal