28 #ifndef ROSCPP_SERIALIZATION_H 29 #define ROSCPP_SERIALIZATION_H 45 #include <boost/array.hpp> 46 #include <boost/call_traits.hpp> 47 #include <boost/utility/enable_if.hpp> 48 #include <boost/mpl/and.hpp> 49 #include <boost/mpl/or.hpp> 50 #include <boost/mpl/not.hpp> 54 #define ROS_NEW_SERIALIZATION_API 1 73 #define ROS_DECLARE_ALLINONE_SERIALIZER \ 74 template<typename Stream, typename T> \ 75 inline static void write(Stream& stream, const T& t) \ 77 allInOne<Stream, const T&>(stream, t); \ 80 template<typename Stream, typename T> \ 81 inline static void read(Stream& stream, T& t) \ 83 allInOne<Stream, T&>(stream, t); \ 86 template<typename T> \ 87 inline static uint32_t serializedLength(const T& t) \ 90 allInOne<LStream, const T&>(stream, t); \ 91 return stream.getLength(); \ 96 namespace serialization
98 namespace mt = message_traits;
99 namespace mpl = boost::mpl;
124 template<
typename Stream>
125 inline static void write(
Stream& stream,
typename boost::call_traits<T>::param_type t)
127 t.serialize(stream.
getData(), 0);
133 template<
typename Stream>
134 inline static void read(
Stream& stream,
typename boost::call_traits<T>::reference t)
136 t.deserialize(stream.
getData());
144 return t.serializationLength();
151 template<
typename T,
typename Stream>
160 template<
typename T,
typename Stream>
175 #define ROS_CREATE_SIMPLE_SERIALIZER(Type) \ 176 template<> struct Serializer<Type> \ 178 template<typename Stream> inline static void write(Stream& stream, const Type v) \ 180 memcpy(stream.advance(sizeof(v)), &v, sizeof(v) ); \ 183 template<typename Stream> inline static void read(Stream& stream, Type& v) \ 185 memcpy(&v, stream.advance(sizeof(v)), sizeof(v) ); \ 188 inline static uint32_t serializedLength(const Type&) \ 190 return sizeof(Type); \ 210 template<
typename Stream>
inline static void write(
Stream& stream,
const bool v)
212 uint8_t b =
static_cast<uint8_t
>(v);
213 memcpy(stream.
advance(1), &b, 1 );
216 template<
typename Stream>
inline static void read(
Stream& stream,
bool& v)
219 memcpy(&b, stream.
advance(1), 1 );
220 v =
static_cast<bool>(b);
232 template<
class ContainerAllocator>
233 struct Serializer<
std::basic_string<char, std::char_traits<char>, ContainerAllocator> >
235 typedef std::basic_string<char, std::char_traits<char>, ContainerAllocator>
StringType;
237 template<
typename Stream>
240 size_t len = str.size();
241 stream.next(static_cast<uint32_t>(len));
245 memcpy(stream.
advance(static_cast<uint32_t>(len)), str.data(), len);
249 template<
typename Stream>
256 str = StringType(reinterpret_cast<char*>(stream.
advance(len)), len);
266 return 4 +
static_cast<uint32_t
>(str.size());
276 template<
typename Stream>
283 template<
typename Stream>
302 template<
typename Stream>
309 template<
typename Stream>
325 template<
typename T,
class ContainerAllocator,
class Enabled =
void>
332 template<
typename T,
class ContainerAllocator>
335 typedef std::vector<T, typename ContainerAllocator::template rebind<T>::other>
VecType;
339 template<
typename Stream>
342 stream.next(static_cast<uint32_t>(v.size()));
343 ConstIteratorType it = v.begin();
344 ConstIteratorType end = v.end();
345 for (; it != end; ++it)
351 template<
typename Stream>
357 IteratorType it = v.begin();
358 IteratorType end = v.end();
359 for (; it != end; ++it)
368 ConstIteratorType it = v.begin();
369 ConstIteratorType end = v.end();
370 for (; it != end; ++it)
382 template<
typename T,
class ContainerAllocator>
385 typedef std::vector<T, typename ContainerAllocator::template rebind<T>::other>
VecType;
389 template<
typename Stream>
392 uint32_t len =
static_cast<uint32_t
>(v.size());
396 const uint32_t data_len = len *
static_cast<uint32_t
>(
sizeof(T));
397 memcpy(stream.
advance(data_len), &v.front(), data_len);
401 template<
typename Stream>
410 const uint32_t data_len =
static_cast<uint32_t
>(
sizeof(T)) * len;
411 memcpy(static_cast<void*>(&v.front()), stream.
advance(data_len), data_len);
417 return 4 + v.size() *
static_cast<uint32_t
>(
sizeof(T));
424 template<
typename T,
class ContainerAllocator>
425 struct VectorSerializer<T, ContainerAllocator, typename
boost::enable_if<mpl::and_<mt::IsFixedSize<T>, mpl::not_<mt::IsSimple<T> > > >::type >
427 typedef std::vector<T, typename ContainerAllocator::template rebind<T>::other>
VecType;
431 template<
typename Stream>
434 stream.next(static_cast<uint32_t>(v.size()));
435 ConstIteratorType it = v.begin();
436 ConstIteratorType end = v.end();
437 for (; it != end; ++it)
443 template<
typename Stream>
449 IteratorType it = v.begin();
450 IteratorType end = v.end();
451 for (; it != end; ++it)
463 size += len_each *
static_cast<uint32_t
>(v.size());
473 template<
typename T,
class ContainerAllocator,
typename Stream>
482 template<
typename T,
class ContainerAllocator,
typename Stream>
491 template<
typename T,
class ContainerAllocator>
500 template<
typename T,
size_t N,
class Enabled =
void>
507 template<
typename T,
size_t N>
514 template<
typename Stream>
517 ConstIteratorType it = v.begin();
518 ConstIteratorType end = v.end();
519 for (; it != end; ++it)
525 template<
typename Stream>
528 IteratorType it = v.begin();
529 IteratorType end = v.end();
530 for (; it != end; ++it)
539 ConstIteratorType it = v.begin();
540 ConstIteratorType end = v.end();
541 for (; it != end; ++it)
553 template<
typename T,
size_t N>
560 template<
typename Stream>
563 const uint32_t data_len = N *
sizeof(T);
564 memcpy(stream.
advance(data_len), &v.front(), data_len);
567 template<
typename Stream>
570 const uint32_t data_len = N *
sizeof(T);
571 memcpy(&v.front(), stream.
advance(data_len), data_len);
576 return N *
sizeof(T);
583 template<
typename T,
size_t N>
584 struct ArraySerializer<T, N, typename
boost::enable_if<mpl::and_<mt::IsFixedSize<T>, mpl::not_<mt::IsSimple<T> > > >::type>
590 template<
typename Stream>
593 ConstIteratorType it = v.begin();
594 ConstIteratorType end = v.end();
595 for (; it != end; ++it)
601 template<
typename Stream>
604 IteratorType it = v.begin();
605 IteratorType end = v.end();
606 for (; it != end; ++it)
621 template<
typename T,
size_t N,
typename Stream>
630 template<
typename T,
size_t N,
typename Stream>
639 template<
typename T,
size_t N>
648 namespace stream_types
675 uint8_t* old_data = data_;
689 inline uint32_t
getLength() {
return static_cast<uint32_t
>(end_ - data_); }
694 , end_(_data + _count)
786 uint32_t old = count_;
885 #endif // ROSCPP_SERIALIZATION_H VecType::iterator IteratorType
static void write(Stream &stream, typename boost::call_traits< T >::param_type t)
Write an object to the stream. Normally the stream passed in here will be a ros::serialization::OStre...
static void notify(const PreDeserializeParams< M > &)
static void write(Stream &stream, const StringType &str)
static void read(Stream &stream, ArrayType &v)
static void read(Stream &stream, ros::Time &v)
stream_types::StreamType StreamType
OStream(uint8_t *data, uint32_t count)
ArrayType::iterator IteratorType
static uint32_t serializedLength(const VecType &v)
SerializedMessage serializeServiceResponse(bool ok, const M &message)
Serialize a service response.
static uint32_t serializedLength(typename boost::call_traits< T >::param_type t)
Determine the serialized length of an object.
static void read(Stream &stream, VecType &v)
Vector serializer. Default implementation does nothing.
static void write(Stream &stream, const ros::Duration &v)
ArrayType::const_iterator ConstIteratorType
static void read(Stream &stream, StringType &str)
std::vector< T, typename ContainerAllocator::template rebind< T >::other > VecType
static void read(Stream &stream, ros::Duration &v)
static void read(Stream &stream, bool &v)
VecType::const_iterator ConstIteratorType
void deserializeMessage(const SerializedMessage &m, M &message)
Deserialize a message. If includes_length is true, skips the first 4 bytes.
ArrayType::const_iterator ConstIteratorType
VecType::const_iterator ConstIteratorType
ROS_FORCE_INLINE void next(T &t)
Deserialize an item from this input stream.
ROS_FORCE_INLINE uint8_t * advance(uint32_t len)
Advances the stream, checking bounds, and returns a pointer to the position before it was advanced...
ArrayType::iterator IteratorType
boost::array< T, N > ArrayType
static uint32_t serializedLength(const ArrayType &v)
static uint32_t serializedLength(const ArrayType &)
static void write(Stream &stream, const VecType &v)
StreamOverrunException(const std::string &what)
uint32_t getLength()
Returns the amount of space left in the stream.
ROSCPP_SERIALIZATION_DECL void throwStreamOverrun()
std::basic_string< char, std::char_traits< char >, ContainerAllocator > StringType
void serialize(Stream &stream, const T &t)
Serialize an object. Stream here should normally be a ros::serialization::OStream.
#define ROSCPP_SERIALIZATION_DECL
static uint32_t serializedLength(const StringType &str)
boost::shared_ptr< M > message
called by the SubscriptionCallbackHelper after a message is instantiated but before that message is d...
ROS_FORCE_INLINE OStream & operator<<(const T &t)
uint32_t getLength()
Get the total length of this tream.
Templated serialization class. Default implementation provides backwards compatibility with old messa...
static void read(Stream &stream, typename boost::call_traits< T >::reference t)
Read an object from the stream. Normally the stream passed in here will be a ros::serialization::IStr...
static void read(Stream &stream, ArrayType &v)
static uint32_t serializedLength(const ArrayType &v)
SerializedMessage serializeMessage(const M &message)
Serialize a message.
#define ROS_CREATE_SIMPLE_SERIALIZER(Type)
static uint32_t serializedLength(bool)
static void write(Stream &stream, const VecType &v)
ROS_FORCE_INLINE void next(const T &t)
Add the length of an item to this length stream.
ROS_FORCE_INLINE IStream & operator>>(T &t)
Stream base-class, provides common functionality for IStream and OStream.
ArrayType::const_iterator ConstIteratorType
uint32_t serializationLength(const T &t)
Determine the serialized length of an object.
static void write(Stream &stream, const ArrayType &v)
static uint32_t serializedLength(const VecType &v)
static void write(Stream &stream, const ArrayType &v)
boost::shared_array< uint8_t > buf
static void write(Stream &stream, const ArrayType &v)
VecType::iterator IteratorType
VecType::iterator IteratorType
static void write(Stream &stream, const ros::Time &v)
static void write(Stream &stream, const VecType &v)
VecType::const_iterator ConstIteratorType
ROS_FORCE_INLINE void next(const T &t)
Serialize an item to this output stream.
ArrayType::iterator IteratorType
IStream(uint8_t *data, uint32_t count)
Stream(uint8_t *_data, uint32_t _count)
boost::shared_ptr< std::map< std::string, std::string > > connection_header
boost::array< T, N > ArrayType
static uint32_t serializedLength(const VecType &v)
std::vector< T, typename ContainerAllocator::template rebind< T >::other > VecType
Array serializer, default implementation does nothing.
static void read(Stream &stream, VecType &v)
void deserialize(Stream &stream, T &t)
Deserialize an object. Stream here should normally be a ros::serialization::IStream.
static void write(Stream &stream, const bool v)
std::vector< T, typename ContainerAllocator::template rebind< T >::other > VecType
boost::array< T, N > ArrayType
ROS_FORCE_INLINE uint32_t advance(uint32_t len)
increment the length by len
static uint32_t serializedLength(const ros::Duration &)
static void read(Stream &stream, VecType &v)
static uint32_t serializedLength(const ros::Time &)
static void read(Stream &stream, ArrayType &v)