nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
serialization_format.hpp
Go to the documentation of this file.
1// nros-cpp: the serialization format as a compile-time fact (freestanding C++14)
2//
3// RFC-0088 D5. ROS 2 asks `rmw_get_serialization_format()` at run time because
4// it resolves its typesupport through `dlopen`; nano-ros does not `dlopen`, so
5// the answer is already known when the image is compiled — one image links one
6// backend, and one backend speaks one encoding.
7//
8// `const char*` throughout, never `std::string` or `std::string_view`: these
9// headers must compile against Zephyr's minimal libcpp behind `NROS_CPP_STD`,
10// where `<string>` does not exist (issue 0112).
11
21#ifndef NROS_RCLCPP_DETAIL_SERIALIZATION_FORMAT_HPP
22#define NROS_RCLCPP_DETAIL_SERIALIZATION_FORMAT_HPP
23
24#include <cstdint>
25
26// `NROS_CPP_SERIALIZATION_FORMAT_ID` — cbindgen output, lowered from
27// `nros_cpp`'s own mirror, which a `const _` proves equal to
28// `nros_node::session::IMAGE_SERIALIZATION_FORMAT_ID`. Taken from the C++ FFI
29// header rather than from `<rclc/detail/nros_generated.h>` so that a generated message
30// header never pulls a C API header ahead of this one (issue 0160 — the FFI
31// struct mirrors make that include order one-way).
32#include "rclcpp/detail/nros_cpp_ffi.h"
33
34namespace rclcpp {
35
45 Cdr = 1,
47 Uorb = 2,
48};
49
60template <typename M> struct format_of {
62};
63
73
80constexpr const char* linked_format_name() {
82 ? "cdr"
83 : (linked_format() == SerializationFormat::Uorb ? "uorb" : "unknown");
84}
85
86} // namespace rclcpp
87
97#define NROS_CPP_ASSERT_MESSAGE_FORMAT(M) \
98 static_assert(::rclcpp::format_of<M>::value == ::rclcpp::linked_format(), \
99 "RFC-0088: this message type is not encoded in the format the linked " \
100 "backend speaks: one image, one backend, one encoding. A bridge image " \
101 "is the only place two formats legitimately meet, and it converts " \
102 "explicitly.")
103
104#endif // NROS_RCLCPP_DETAIL_SERIALIZATION_FORMAT_HPP
Definition client.hpp:129
Definition rclcpp.hpp:75
constexpr SerializationFormat linked_format()
Definition serialization_format.hpp:70
constexpr const char * linked_format_name()
Definition serialization_format.hpp:80
SerializationFormat
Definition serialization_format.hpp:43
@ Cdr
OMG CDR as ROS 2 puts it on the wire, encapsulation header included.
@ Uorb
PX4's in-memory struct, verbatim — no encoding step at all (RFC-0011).
Definition serialization_format.hpp:60
static constexpr SerializationFormat value
Definition serialization_format.hpp:61