Verified Commit 8acaf116 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

serialization: {save,load}ToBinary for StaticBuffer

parent aecb0f21
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define __pinocchio_serialization_archive_hpp__ #define __pinocchio_serialization_archive_hpp__
#include "pinocchio/serialization/fwd.hpp" #include "pinocchio/serialization/fwd.hpp"
#include "pinocchio/serialization/static-buffer.hpp"
#include <fstream> #include <fstream>
#include <string> #include <string>
...@@ -19,6 +20,9 @@ ...@@ -19,6 +20,9 @@
#include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_oarchive.hpp>
#include <boost/asio/streambuf.hpp> #include <boost/asio/streambuf.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/stream_buffer.hpp>
// Handle NAN inside TXT or XML archives // Handle NAN inside TXT or XML archives
#include <boost/math/special_functions/nonfinite_num_facets.hpp> #include <boost/math/special_functions/nonfinite_num_facets.hpp>
...@@ -287,6 +291,44 @@ namespace pinocchio ...@@ -287,6 +291,44 @@ namespace pinocchio
oa & object; oa & object;
} }
///
/// \brief Loads an object from a static binary buffer.
/// The buffer should be of a sufficient size.
///
/// \tparam T Type of the object to deserialize.
///
/// \param[out] object Object in which the loaded data are copied.
/// \param[in] buffer Input buffer containing the serialized data.
///
template<typename T>
inline void loadFromBinary(T & object,
StaticBuffer & buffer)
{
boost::iostreams::stream_buffer< boost::iostreams::basic_array<char> > stream(buffer.data(), buffer.size());
boost::archive::binary_iarchive ia(stream);
ia >> object;
}
///
/// \brief Saves an object to a static binary buffer.
/// The buffer should be of a sufficient size.
///
/// \tparam T Type of the object to deserialize.
///
/// \param[in] object Object in which the loaded data are copied.
/// \param[out] buffer Output buffer containing the serialized data.
///
template<typename T>
inline void saveToBinary(const T & object,
StaticBuffer & buffer)
{
boost::iostreams::stream_buffer< boost::iostreams::basic_array<char> > stream(buffer.data(), buffer.size());
boost::archive::binary_oarchive oa(stream);
oa & object;
}
} // namespace serialization } // namespace serialization
} // namespace pinocchio } // namespace pinocchio
......
...@@ -96,6 +96,18 @@ namespace pinocchio ...@@ -96,6 +96,18 @@ namespace pinocchio
pinocchio::serialization::saveToBinary(derived(),container); pinocchio::serialization::saveToBinary(derived(),container);
} }
/// \brief Loads a Derived object from a static binary container.
void loadFromBinary(StaticBuffer & container)
{
pinocchio::serialization::loadFromBinary(derived(),container);
}
/// \brief Saves a Derived object as a static binary container.
void saveToBinary(StaticBuffer & container) const
{
pinocchio::serialization::saveToBinary(derived(),container);
}
}; };
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment