diff options
author | Josh Blum | 2013-05-04 23:56:55 -0700 |
---|---|---|
committer | Josh Blum | 2013-05-04 23:56:55 -0700 |
commit | 3e1d523d5c218f1fead19407a8e902329d4120b4 (patch) | |
tree | cdd23406449986f4b868ed36c3ae6329c81ad648 /lib/serialize_types.cpp | |
parent | 23245f06df9b76a16877339654dd5163fb213521 (diff) | |
download | sandhi-3e1d523d5c218f1fead19407a8e902329d4120b4.tar.gz sandhi-3e1d523d5c218f1fead19407a8e902329d4120b4.tar.bz2 sandhi-3e1d523d5c218f1fead19407a8e902329d4120b4.zip |
gras: rename to serialize_types.cpp
Diffstat (limited to 'lib/serialize_types.cpp')
-rw-r--r-- | lib/serialize_types.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/serialize_types.cpp b/lib/serialize_types.cpp new file mode 100644 index 0000000..33db43c --- /dev/null +++ b/lib/serialize_types.cpp @@ -0,0 +1,74 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#include <gras/sbuffer.hpp> +#include <gras/tags.hpp> +#include <PMC/Serialize.hpp> +#include <boost/serialization/split_free.hpp> +#include <boost/serialization/string.hpp> + +/*********************************************************************** + * support for sbuffer + **********************************************************************/ +namespace boost { namespace serialization { +template<class Archive> +void save(Archive & ar, const gras::SBuffer & b, unsigned int version) +{ + bool null = not b; + ar & null; + if (null) return; + + //TODO lazyness string + std::string s((const char *)b.get(), b.length); + ar & s; +} +template<class Archive> +void load(Archive & ar, gras::SBuffer & b, unsigned int version) +{ + bool null = false; + ar & null; + if (null) b.reset(); + if (null) return; + + //TODO lazyness string + std::string s; + ar & s; + gras::SBufferConfig config; + config.length = s.length(); + b = gras::SBuffer(config); + b.length = s.length(); + std::memcpy(b.get(), s.c_str(), b.length); +} +}} + +BOOST_SERIALIZATION_SPLIT_FREE(gras::SBuffer) +PMC_SERIALIZE_EXPORT(gras::SBuffer, "PMC<gras::SBuffer>") + + +/*********************************************************************** + * support for special packet msg type + **********************************************************************/ +namespace boost { namespace serialization { +template <class Archive> +void serialize(Archive &ar, gras::PacketMsg &t, const unsigned int) +{ + ar & t.info; + ar & t.buff; +} +}} + +PMC_SERIALIZE_EXPORT(gras::PacketMsg, "PMC<gras::PacketMsg>") + +/*********************************************************************** + * support for special stream tag type + **********************************************************************/ +namespace boost { namespace serialization { +template <class Archive> +void serialize(Archive &ar, gras::StreamTag &t, const unsigned int) +{ + ar & t.key; + ar & t.val; + ar & t.src; +} +}} + +PMC_SERIALIZE_EXPORT(gras::StreamTag, "PMC<gras::StreamTag>") |