Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _SOCROB_MULTICAST_SERIALIZATION_H_
00021 #define _SOCROB_MULTICAST_SERIALIZATION_H_
00022
00023 #include <cstddef>
00024 #include <stdint.h>
00025
00026 #include <vector>
00027
00028 #include <ros/console.h>
00029 #include <ros/serialization.h>
00030
00031
00032
00033 namespace socrob
00034 {
00035 namespace multicast
00036 {
00046 template<typename T>
00047 void
00048 serialize_append (std::vector<uint8_t> & out,
00049 T const& msg)
00050 {
00051 std::size_t out_offset = out.size();
00052 std::size_t msg_size = ros::serialization::serializationLength (msg);
00053 out.resize (out_offset + msg_size);
00054 ros::serialization::OStream stream (& (out[out_offset]), msg_size);
00055 ros::serialization::serialize (stream, msg);
00056 }
00057
00067 template<typename T>
00068 void
00069 serialize_overwrite (std::vector<uint8_t> & out,
00070 T const& msg)
00071 {
00072 std::size_t msg_size = ros::serialization::serializationLength (msg);
00073 out.resize (msg_size);
00074 ros::serialization::OStream stream (& (out[0]), msg_size);
00075 ros::serialization::serialize (stream, msg);
00076 }
00077
00095 template<typename T>
00096 std::size_t
00097 deserialize (T& msg,
00098 std::vector<uint8_t> & in,
00099 std::size_t offset = 0)
00100 {
00101 if (offset >= in.size()) {
00102 ROS_FATAL ("deserialize called with offset after the end of input");
00103 abort();
00104 }
00105 ros::serialization::IStream stream (& (in[offset]), in.size() - offset);
00106 ros::serialization::deserialize (stream, msg);
00107 return ros::serialization::serializationLength (msg);
00108 }
00109 }
00110 }
00111
00112 #endif