diff options
author | Josh Blum | 2013-05-04 23:44:55 -0700 |
---|---|---|
committer | Josh Blum | 2013-05-04 23:44:55 -0700 |
commit | 23245f06df9b76a16877339654dd5163fb213521 (patch) | |
tree | 5e50dc109ae83e158c183821d79493e26352494a /lib | |
parent | 1725bd75949b88782e6ad265dd91a0af082b8ce3 (diff) | |
download | sandhi-23245f06df9b76a16877339654dd5163fb213521.tar.gz sandhi-23245f06df9b76a16877339654dd5163fb213521.tar.bz2 sandhi-23245f06df9b76a16877339654dd5163fb213521.zip |
gras: added serialization support for gras types
sbuffer, streamtag, and packetmsg get registered
into the polymorphic archive w/ unit tests
resolves #65
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/serialize_meta.cpp | 74 |
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ba7e76e..7f33397 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -64,6 +64,7 @@ list(APPEND GRAS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/register_messages.cpp ${CMAKE_CURRENT_SOURCE_DIR}/theron_allocator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/weak_container.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/serialize_meta.cpp ) ######################################################################## diff --git a/lib/serialize_meta.cpp b/lib/serialize_meta.cpp new file mode 100644 index 0000000..33db43c --- /dev/null +++ b/lib/serialize_meta.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>") |