[serialization] Trouble serializing a bitfield
Following is a very short program to test serialization along with the
g++ output when compiling it. My problem arises when I try to write a
serialization function for a bitfield. As the compiler output shows,
the bitfield is the cause of this problem.
How should one serialize a bitfield? Have I made some mistake in this
code?
I can get seriailziation to work if I instead use a save() and load()
function that copies each bit to an int before archiving but I'm unsure
if this is the best way.
#include
Ken Roser wrote: ...
How should one serialize a bitfield?
There are a couple of ideas in the vault.
Have I made some mistake in this code?
without actually trying the code I would make the following changes to the test: Robert Ramey
#include
#include <string> #include <iostream> #include <sstream> #include
#include class Event { friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const int version) { ar & bits; ar & field1; }; public: struct s { friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const int version) { ar & spare1; // error here as no serialization has been defined for bit fields }; int spare1 : 1; } bits; int field1; };
main(int argc, char **argv) { Event evt; evt.field1 = 0x1234;
std::stringstream ofs; boost::archive::binary_oarchive oa(ofs); oa & evt; // serialize the event }
http://boost-consulting.com/vault/ look in "serialization" Robert Ramey Markus Werle wrote:
Robert Ramey
writes: Ken Roser wrote: ...
How should one serialize a bitfield?
There are a couple of ideas in the vault.
Where exactly?
Markus
participants (3)
-
Ken Roser
-
Markus Werle
-
Robert Ramey