ROS 2 rclcpp + rcl - rolling  rolling-20536064
ROS 2 C++ Client Library with ROS Client Library
serialization.hpp
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 <stdexcept>
19 #include <string>
20 
21 #include "rclcpp/visibility_control.hpp"
22 
23 #include "rcl/types.h"
24 
25 #include "rosidl_runtime_c/message_type_support_struct.h"
26 
27 #include "rosidl_typesupport_cpp/message_type_support.hpp"
28 
29 namespace rclcpp
30 {
31 
32 class SerializedMessage;
33 
34 namespace serialization_traits
35 {
36 // trait to check if type is the object oriented serialized message
37 template<typename T>
38 struct is_serialized_message_class : std::false_type
39 {};
40 
41 template<>
43 {};
44 } // namespace serialization_traits
45 
47 class RCLCPP_PUBLIC_TYPE SerializationBase
48 {
49 public:
51 
55  explicit SerializationBase(const rosidl_message_type_support_t * type_support);
56 
58  virtual ~SerializationBase() = default;
59 
61 
65  void serialize_message(
66  const void * ros_message, SerializedMessage * serialized_message) const;
67 
69 
73  void deserialize_message(
74  const SerializedMessage * serialized_message, void * ros_message) const;
75 
76 private:
77  const rosidl_message_type_support_t * type_support_;
78 };
79 
81 template<typename MessageT>
83 {
84 public:
87  : SerializationBase(rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>())
88  {
89  static_assert(
91  "Serialization of serialized message to serialized message is not possible.");
92  }
93 };
94 
95 } // namespace rclcpp
96 
97 #endif // RCLCPP__SERIALIZATION_HPP_
Interface to (de)serialize a message.
virtual ~SerializationBase()=default
Destructor of SerializationBase.
Default implementation to (de)serialize a message by using rmw_(de)serialize.
Serialization()
Constructor of Serialization.
Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.