11 std::string _hash, _name, _definition;
19 static std::shared_ptr<MessageType> instance(
const std::string &hash,
20 const std::string &name,
21 const std::string &definition);
22 const std::string &hash()
const {
return _hash; }
23 const std::string &name()
const {
return _name; }
24 const std::string &definition()
const {
return _definition; }
27 class Message :
public std::enable_shared_from_this<Message> {
28 std::shared_ptr<const MessageType> _type;
29 std::vector<uint8_t> _data;
31 template <
class T>
void instantiateImpl(std::shared_ptr<const T> &ret)
const {
32 if (_data.empty() || _type ==
nullptr ||
33 ros::message_traits::datatype<T>() != _type->name() ||
34 ros::message_traits::md5sum<T>() != _type->hash()) {
37 auto m = std::make_shared<T>();
38 ros::serialization::IStream s((uint8_t *)_data.data(), _data.size());
39 ros::serialization::deserialize(s, *m);
43 void instantiateImpl(std::shared_ptr<const Message> &ret)
const {
44 ret = shared_from_this();
48 template <
class T> std::shared_ptr<const T> instantiate()
const {
49 std::shared_ptr<const typename std::decay<T>::type> ret;
51 return std::move(ret);
53 template <
class Stream>
void read(Stream &stream) {
54 _data.resize(stream.getLength());
55 std::memcpy(_data.data(), stream.getData(), _data.size());
57 void type(
const std::shared_ptr<const MessageType> &type) { _type = type; }
58 const std::shared_ptr<const MessageType> &type()
const {
return _type; }
59 const ros::Time &time()
const {
return _time; }
60 void time(
const ros::Time &time) { _time = time; }
61 const uint8_t *data()
const {
return _data.data(); }
62 size_t size()
const {
return _data.size(); }
66 namespace message_traits {
68 static const char *value() {
return "*"; }
71 static const char *value() {
return "*"; }
74 namespace serialization {
76 template <
typename Stream>
77 inline static void read(Stream &stream,
Message &m) {
81 template <>
struct PreDeserialize<
Message> {
82 static void notify(
const PreDeserializeParams<Message> ¶ms) {
83 params.message->type(MessageType::instance(
84 (*params.connection_header)[
"md5sum"],
85 (*params.connection_header)[
"type"],
86 (*params.connection_header)[
"message_definition"]));