$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Robert Ramey (ramey_at_[hidden])
Date: 2006-11-22 23:17:05
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 <stdlib.h>
> #include <string>
> #include <iostream>
> #include <sstream>
>
> #include <boost/archive/text_iarchive.hpp>
> #include <boost/archive/text_oarchive.hpp>
>
> 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
> }