boost::uuids::uuid with SF

RCF support and general discussion.
Post Reply
Volker
Posts: 26
Joined: Wed May 23, 2012 3:27 pm

boost::uuids::uuid with SF

Post 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

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: boost::uuids::uuid with SF

Post 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 ;
   }

}
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

Volker
Posts: 26
Joined: Wed May 23, 2012 3:27 pm

Re: boost::uuids::uuid with SF

Post 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

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: boost::uuids::uuid with SF

Post 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.
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

Post Reply