Message.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
23 #ifndef VARIANT_TOPIC_TOOLS_MESSAGE_H
24 #define VARIANT_TOPIC_TOOLS_MESSAGE_H
25 
26 #include <vector>
27 
28 #include <ros/ros.h>
29 
30 #include <variant_msgs/Variant.h>
31 
35 
36 namespace variant_topic_tools {
43  class Message {
44  public:
47  Message();
48 
51  template <typename T> Message(const T& message, const MessageHeader&
52  header = MessageHeader());
53 
56  Message(const Message& src);
57 
60  ~Message();
61 
67  void setHeader(const MessageHeader& header);
68 
71  const MessageHeader& getHeader() const;
72 
78  void setType(const MessageType& type);
79 
82  const MessageType& getType() const;
83 
86  void setData(const std::vector<uint8_t>& data);
87 
90  std::vector<uint8_t>& getData();
91 
94  const std::vector<uint8_t>& getData() const;
95 
98  void setSize(size_t size);
99 
102  size_t getSize() const;
103 
106  template <typename T> void morph();
107 
110  void serialize(const MessageVariant& variant);
111 
114  void deserialize(MessageVariant& variant) const;
115 
119 
122  template <typename T> boost::shared_ptr<T> toMessage() const;
123 
126  template <typename Stream> void read(Stream& stream);
127 
130  template <typename Stream> void write(Stream& stream) const;
131 
132  protected:
136 
140 
143  std::vector<uint8_t> data;
144  };
145 };
146 
147 #include <variant_topic_tools/Message.tpp>
148 
151 
152 #endif
void serialize(const MessageVariant &variant)
Attempt to serialize this message from a variant.
Definition: Message.cpp:95
void setHeader(const MessageHeader &header)
Set the message header.
Definition: Message.cpp:47
std::vector< uint8_t > data
The data of this message.
Definition: Message.h:143
Generic message type.
Definition: Message.h:43
Message()
Default constructor.
Definition: Message.cpp:31
Variant message type information.
Definition: MessageType.h:33
Header file providing forward declarations for the variant topic tools.
Header file providing the variant message traits.
const MessageType & getType() const
Retrieve the message type.
Definition: Message.cpp:67
size_t getSize() const
Retrieve the message size.
Definition: Message.cpp:87
Header file providing the variant message serialization.
boost::shared_ptr< T > toMessage() const
Attempt to convert the message to a strong-typed message.
Header file providing the MessageHeader class interface.
MessageHeader header
The header of this message.
Definition: Message.h:135
void setSize(size_t size)
Set the message size.
Definition: Message.cpp:83
void deserialize(MessageVariant &variant) const
Attempt to deserialize this message into a variant.
Definition: Message.cpp:109
void read(Stream &stream)
Read serialized message contents from stream.
void setType(const MessageType &type)
Set the message type.
Definition: Message.cpp:59
void morph()
Morph the message.
MessageType type
The type of this message.
Definition: Message.h:139
boost::shared_ptr< variant_msgs::Variant > toVariantMessage() const
Attempt to convert the message to a variant message.
Definition: Message.cpp:126
const MessageHeader & getHeader() const
Retrieve the message header.
Definition: Message.cpp:55
Variant message header.
Definition: MessageHeader.h:33
void write(Stream &stream) const
Write serialized message contents to stream.
std::vector< uint8_t > & getData()
Retrieve the message data (non-const version)
Definition: Message.cpp:75
Header file providing the MessageType class interface.
void setData(const std::vector< uint8_t > &data)
Set the message data.
Definition: Message.cpp:71


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49