Page 1 of 1

boost::uuids::uuid with SF

Posted: Tue Apr 23, 2013 12:25 pm
by Volker
(RCF 2.0.0.2679, selected serialization formats : SF and boost::serialization, gcc 4.6)

Hi Jarl,

I tried to serialize the boost class boost::uuids::uuid . First I thought its pretty simple, because it boils down to serialize an array of boost::uint8_t :

Code: Select all

namespace boost {
namespace uuids {

struct uuid
{
    // or should it be array<uint8_t, 16>
    uint8_t data[16];
};

}
}
I tried the following code :

Code: Select all

#include <boost/uuid/uuid.hpp>
#include <SF/Archive.hpp>

namespace SF
{

void serialize( SF:Archive &ar, boost::uuids::uuid &u )
{
   ar & u.data ;
}

}
SF doesn't seem to handle an array of boost::uint8_t as fundamental and tries to call method u.data.serialize( SF::Archive &ar ), which of course fails. I tried to work around this but didn't find a satisfying solution...

(IMHO the best way to solve this would be to change the definition in boost::uuids::uuid as the author of this module already suggested but this would last far too long ...)

Regards,

Volker

Re: boost::uuids::uuid with SF

Posted: Tue Apr 23, 2013 1:14 pm
by jarl
SF has built in support for static arrays, so u.data should not be a problem. I think all that's missing in your code is an include at the top:

Code: Select all

#include <SF/SerializeStaticArray.hpp>

namespace SF
{

   void serialize( SF:Archive &ar, boost::uuids::uuid &u )
   {
      ar & u.data ;
   }

}

Re: boost::uuids::uuid with SF

Posted: Wed Apr 24, 2013 1:26 pm
by Volker
That was easy ... and works !

Ever tried to serialize boost::chrono::steady_clock ?

Unfortunately in contrast to some other boost modules boost::chrono doesn't have any support for boost::serialization.

Please don't invest too much time ...

Regards and thanks for your support !

Volker

Re: boost::uuids::uuid with SF

Posted: Thu Apr 25, 2013 6:27 am
by jarl
No problem Volker.

I haven't used boost::chrono myself, so I don't know how steady_clock etc works. However, to serialize something that represents a point in time, you could format it as a string before serializing it, and then parse the string into a time when you deserialize. Or, to go easier on the CPU, convert the time into something like number of milliseconds since some fixed point in time, and serialize that.