rclcpp  master
C++ ROS Client Library API
serialization.hpp
Go to the documentation of this file.
1 // Copyright 2020 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__SERIALIZATION_HPP_
16 #define RCLCPP__SERIALIZATION_HPP_
17 
18 #include <memory>
19 #include <stdexcept>
20 #include <string>
21 
23 
24 #include "rcl/types.h"
25 
26 #include "rosidl_runtime_c/message_type_support_struct.h"
27 
28 #include "rosidl_typesupport_cpp/message_type_support.hpp"
29 
30 namespace rclcpp
31 {
32 
33 class SerializedMessage;
34 
35 namespace serialization_traits
36 {
37 // trait to check if type is the object oriented serialized message
38 template<typename T>
40 {};
41 
42 template<>
44 {};
45 } // namespace serialization_traits
46 
49 {
50 public:
52 
56  explicit SerializationBase(const rosidl_message_type_support_t * type_support);
57 
59  virtual ~SerializationBase() = default;
60 
62 
66  void serialize_message(
67  const void * ros_message, SerializedMessage * serialized_message) const;
68 
70 
74  void deserialize_message(
75  const SerializedMessage * serialized_message, void * ros_message) const;
76 
77 private:
78  const rosidl_message_type_support_t * type_support_;
79 };
80 
82 template<typename MessageT>
84 {
85 public:
88  : SerializationBase(rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>())
89  {
90  static_assert(
92  "Serialization of serialized message to serialized message is not possible.");
93  }
94 };
95 
96 } // namespace rclcpp
97 
98 #endif // RCLCPP__SERIALIZATION_HPP_
std::false_type
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::serialization_traits::is_serialized_message_class
Definition: serialization.hpp:39
rclcpp::SerializationBase
Interface to (de)serialize a message.
Definition: serialization.hpp:48
RCLCPP_PUBLIC_TYPE
#define RCLCPP_PUBLIC_TYPE
Definition: visibility_control.hpp:53
visibility_control.hpp
rclcpp::SerializedMessage
Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.
Definition: serialized_message.hpp:27
rclcpp::Serialization::Serialization
Serialization()
Constructor of Serialization.
Definition: serialization.hpp:87
rclcpp::Serialization
Default implementation to (de)serialize a message by using rmw_(de)serialize.
Definition: serialization.hpp:83