see http://voices.canonical.com/jussi.pakkanen/2013/09/14/serialising-any-c-data-structure-to-disk-with-20-lines-of-code/