ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
serialized_message.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__SERIALIZED_MESSAGE_HPP_
16 #define RCLCPP__SERIALIZED_MESSAGE_HPP_
17 
18 #include "rcl/allocator.h"
19 #include "rcl/types.h"
20 
21 #include "rclcpp/visibility_control.hpp"
22 
23 namespace rclcpp
24 {
25 
27 class RCLCPP_PUBLIC_TYPE SerializedMessage
28 {
29 public:
31 
38  explicit SerializedMessage(
39  const rcl_allocator_t & allocator = rcl_get_default_allocator());
40 
42 
50  explicit SerializedMessage(
51  size_t initial_capacity,
52  const rcl_allocator_t & allocator = rcl_get_default_allocator());
53 
55  SerializedMessage(const SerializedMessage & other);
56 
58  explicit SerializedMessage(const rcl_serialized_message_t & other);
59 
62 
65 
67  SerializedMessage & operator=(const SerializedMessage & other);
68 
70  SerializedMessage & operator=(const rcl_serialized_message_t & other);
71 
73  SerializedMessage & operator=(SerializedMessage && other);
74 
76  SerializedMessage & operator=(rcl_serialized_message_t && other);
77 
79  virtual ~SerializedMessage();
80 
82  rcl_serialized_message_t & get_rcl_serialized_message();
83 
84  // Get a const handle to the underlying rcl_serialized_message_t
85  const rcl_serialized_message_t & get_rcl_serialized_message() const;
86 
88 
92  size_t size() const;
93 
95 
99  size_t capacity() const;
100 
102 
106  void reserve(size_t capacity);
107 
109 
113  rcl_serialized_message_t release_rcl_serialized_message();
114 
115 private:
116  rcl_serialized_message_t serialized_message_;
117 };
118 
119 } // namespace rclcpp
120 
121 #endif // RCLCPP__SERIALIZED_MESSAGE_HPP_
#define rcl_get_default_allocator
Return a properly initialized rcl_allocator_t with default values.
Definition: allocator.h:37
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
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.
rmw_serialized_message_t rcl_serialized_message_t
typedef for rmw_serialized_message_t;
Definition: types.h:134