diff options
author | Josh Blum | 2013-05-07 22:32:01 -0700 |
---|---|---|
committer | Josh Blum | 2013-05-07 22:32:01 -0700 |
commit | 08927ec8a67d14192c02bec683e3a494726066d3 (patch) | |
tree | 0e6c4b34e371d7472c0859e83c9cb0e324dd3355 /lib/serialize_types.cpp | |
parent | ea7e8426db723968d91855af28a7c8b7a3482774 (diff) | |
download | sandhi-08927ec8a67d14192c02bec683e3a494726066d3.tar.gz sandhi-08927ec8a67d14192c02bec683e3a494726066d3.tar.bz2 sandhi-08927ec8a67d14192c02bec683e3a494726066d3.zip |
gras: serialization loop for sbuffer
Diffstat (limited to 'lib/serialize_types.cpp')
-rw-r--r-- | lib/serialize_types.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/serialize_types.cpp b/lib/serialize_types.cpp index 33db43c..afa9481 100644 --- a/lib/serialize_types.cpp +++ b/lib/serialize_types.cpp @@ -13,30 +13,40 @@ namespace boost { namespace serialization { template<class Archive> void save(Archive & ar, const gras::SBuffer & b, unsigned int version) { + //save null bool null = not b; ar & null; if (null) return; - //TODO lazyness string - std::string s((const char *)b.get(), b.length); - ar & s; + //save length + size_t length = b.length; + ar & length; + + //save bytes + const char *ptr = reinterpret_cast<const char *>(b.get(0)); + for (size_t i = 0; i < length; i++) ar & (ptr[i]); } template<class Archive> void load(Archive & ar, gras::SBuffer & b, unsigned int version) { + //load null bool null = false; ar & null; if (null) b.reset(); if (null) return; - //TODO lazyness string - std::string s; - ar & s; + //load length + size_t length = 0; + ar & length; + + //alloc sbuffer gras::SBufferConfig config; - config.length = s.length(); + config.length = length; b = gras::SBuffer(config); - b.length = s.length(); - std::memcpy(b.get(), s.c_str(), b.length); + + //load bytes + char *ptr = reinterpret_cast<char *>(b.get(0)); + for (size_t i = 0; i < length; i++) ar & (ptr[i]); } }} |