19 #ifndef FF_UTIL_FF_SERIALIZATION_H_
20 #define FF_UTIL_FF_SERIALIZATION_H_
34 template <
class RosMessage >
35 static bool WriteFile(std::string
const& file_name, RosMessage
const& msg) {
36 std::ofstream ofs(file_name, std::ios::out | std::ios::binary);
39 uint32_t serial_size = ros::serialization::serializationLength(msg);
40 boost::shared_array < uint8_t > obuffer(
new uint8_t[serial_size]);
41 ros::serialization::OStream ostream(obuffer.get(), serial_size);
42 ros::serialization::serialize(ostream, msg);
43 ofs.write(
reinterpret_cast < char*
> (obuffer.get()), serial_size);
48 template <
class RosMessage >
49 static bool ReadFile(std::string
const& file_name, RosMessage & msg) {
50 std::ifstream ifs(file_name, std::ios::in | std::ios::binary);
53 ifs.seekg(0, std::ios::end);
54 std::streampos end = ifs.tellg();
55 ifs.seekg(0, std::ios::beg);
56 std::streampos begin = ifs.tellg();
57 uint32_t file_size = end - begin;
58 boost::shared_array<uint8_t> ibuffer(
new uint8_t[file_size]);
59 ifs.read(
reinterpret_cast<char*
> (ibuffer.get()), file_size);
60 ros::serialization::IStream istream(ibuffer.get(), file_size);
61 ros::serialization::deserialize(istream, msg);
69 #endif // FF_UTIL_FF_SERIALIZATION_H_