00001 /****************************************************************************** 00002 * Copyright (C) 2014 by Ralf Kaestner * 00003 * ralf.kaestner@gmail.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the Lesser GNU General Public License as published by* 00007 * the Free Software Foundation; either version 3 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * Lesser GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the Lesser GNU General Public License * 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00017 ******************************************************************************/ 00018 00023 #ifndef VARIANT_TOPIC_TOOLS_MESSAGE_H 00024 #define VARIANT_TOPIC_TOOLS_MESSAGE_H 00025 00026 #include <vector> 00027 00028 #include <ros/ros.h> 00029 00030 #include <variant_msgs/Variant.h> 00031 00032 #include <variant_topic_tools/Forwards.h> 00033 #include <variant_topic_tools/MessageHeader.h> 00034 #include <variant_topic_tools/MessageType.h> 00035 00036 namespace variant_topic_tools { 00043 class Message { 00044 public: 00047 Message(); 00048 00051 template <typename T> Message(const T& message, const MessageHeader& 00052 header = MessageHeader()); 00053 00056 Message(const Message& src); 00057 00060 ~Message(); 00061 00067 void setHeader(const MessageHeader& header); 00068 00071 const MessageHeader& getHeader() const; 00072 00078 void setType(const MessageType& type); 00079 00082 const MessageType& getType() const; 00083 00086 void setData(const std::vector<uint8_t>& data); 00087 00090 std::vector<uint8_t>& getData(); 00091 00094 const std::vector<uint8_t>& getData() const; 00095 00098 void setSize(size_t size); 00099 00102 size_t getSize() const; 00103 00106 template <typename T> void morph(); 00107 00110 void serialize(const MessageVariant& variant); 00111 00114 void deserialize(MessageVariant& variant) const; 00115 00118 boost::shared_ptr<variant_msgs::Variant> toVariantMessage() const; 00119 00122 template <typename T> boost::shared_ptr<T> toMessage() const; 00123 00126 template <typename Stream> void read(Stream& stream); 00127 00130 template <typename Stream> void write(Stream& stream) const; 00131 00132 protected: 00135 MessageHeader header; 00136 00139 MessageType type; 00140 00143 std::vector<uint8_t> data; 00144 }; 00145 }; 00146 00147 #include <variant_topic_tools/Message.tpp> 00148 00149 #include <variant_topic_tools/MessageTraits.h> 00150 #include <variant_topic_tools/Serialization.h> 00151 00152 #endif