|
nros C API
Lightweight ROS 2 client for embedded real-time systems
|
RFC-0088 D5 — the linked backend's serialization format, as a compile-time fact the C API can assert on. More...
#include "nros/nros_generated.h"

Go to the source code of this file.
Macros | |
| #define | NROS_ASSERT_MESSAGE_FORMAT(msg_format_id, type_literal) |
| #define | NROS_SERIALIZATION_FORMAT_ID_CDR 1 |
| #define | NROS_SERIALIZATION_FORMAT_ID_UORB 2 |
| #define | NROS_STATIC_ASSERT(cond, msg) |
| #define | NROS_STATIC_ASSERT_CAT(a, b) NROS_STATIC_ASSERT_CAT_(a, b) |
| #define | NROS_STATIC_ASSERT_CAT_(a, b) a##b |
| #define | NROS_STATIC_ASSERT_TAG_ __LINE__ |
RFC-0088 D5 — the linked backend's serialization format, as a compile-time fact the C API can assert on.
ROS 2 asks rmw_get_serialization_format() at run time because it resolves its typesupport through dlopen. nano-ros does not dlopen, so the answer is already known when the image is compiled: exactly one backend is linked, and one backend speaks exactly one encoding.
NROS_SERIALIZATION_FORMAT_ID is generated — it is cbindgen output in nros/nros_generated.h, lowered from nros_c::constants, whose value is proven equal to nros_node::session::IMAGE_SERIALIZATION_FORMAT_ID by a const _ in that module. So the macro cannot silently disagree with the backend this image links: a backend whose format is not the one mirrored there fails the Rust build with a message naming the drift.
NROS_SERIALIZATION_FORMAT is its cross-image identity string, derived here from the discriminant. RFC-0088 D2 is the reason for that direction: the string is the identity that crosses image boundaries, and the **u8 is image-local** — never persist it, never compare it against a value another image produced.
A bridge image (Executor::open_multi) links two backends and therefore has no single answer, so neither macro means anything there; such an image asks per session instead, with nros_node_get_serialization_format(). scripts/check-format-macro-scope.py refuses a bridge-linked translation unit that references either macro.
Copyright 2026 nros contributors Licensed under Apache-2.0
| #define NROS_ASSERT_MESSAGE_FORMAT | ( | msg_format_id, | |
| type_literal | |||
| ) |
Cross-image identity of NROS_SERIALIZATION_FORMAT_ID (RFC-0088 D2).
Derived from the discriminant rather than emitted beside it: cbindgen maps no Rust &str to a C constant, so a second generated macro would be a second authored spelling with nothing tying the two together. One generated number and one table is the shape that cannot drift into disagreeing with itself. Assert that a message type's serialization format is the one the linked backend speaks. Emitted once per generated message header.
| msg_format_id | the type's own NROS_MSG_FORMAT_ID_<type> macro |
| type_literal | the type's name, as a string literal, so the diagnostic names the message rather than the header |
| #define NROS_SERIALIZATION_FORMAT_ID_CDR 1 |
| #define NROS_SERIALIZATION_FORMAT_ID_UORB 2 |
| #define NROS_STATIC_ASSERT | ( | cond, | |
| msg | |||
| ) |
| #define NROS_STATIC_ASSERT_CAT | ( | a, | |
| b | |||
| ) | NROS_STATIC_ASSERT_CAT_(a, b) |
| #define NROS_STATIC_ASSERT_CAT_ | ( | a, | |
| b | |||
| ) | a##b |
Portable compile-time assertion.
Spelled once here because the generated message headers are compiled as C and included from C++ (they carry their own extern "C" block), and _Static_assert is not a C++ keyword. C23 spells the C keyword static_assert too; C11 spells it _Static_assert; the C99 fallback is the negative-array-size idiom, so a freestanding pre-C11 toolchain still gets the diagnostic rather than silently skipping the check.
| #define NROS_STATIC_ASSERT_TAG_ __LINE__ |