From 56e9d2f426da254c7ae2a63f632b92c563fe1028 Mon Sep 17 00:00:00 2001 From: Alex Day Date: Wed, 20 Mar 2024 16:49:58 -0400 Subject: [PATCH 1/2] Attach sequence number and publisher GID to serialized messages --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index ae62e7be..83e7bb02 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -1044,6 +1044,20 @@ rmw_publish_serialized_message( return RMW_RET_ERROR; } + uint64_t sequence_number = publisher_data->get_next_sequence_number(); + + z_owned_bytes_map_t map = + create_map_and_set_sequence_num(sequence_number, publisher_data->pub_gid); + + if (!z_check(map)) { + // create_map_and_set_sequence_num already set the error + return RMW_RET_ERROR; + } + auto free_attachment_map = rcpputils::make_scope_exit( + [&map]() { + z_bytes_map_drop(z_move(map)); + }); + const size_t data_length = ser.getSerializedDataLength(); // The encoding is simply forwarded and is useful when key expressions in the @@ -1051,6 +1065,7 @@ rmw_publish_serialized_message( // will be encoded with CDR so it does not really matter. z_publisher_put_options_t options = z_publisher_put_options_default(); options.encoding = z_encoding(Z_ENCODING_PREFIX_EMPTY, NULL); + options.attachment = z_bytes_map_as_attachment(&map); // Returns 0 if success. int8_t ret = z_publisher_put( z_loan(publisher_data->pub), From 793d527e6acebee3be1c4d2e57ee46ee4f9e4a52 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Wed, 20 Mar 2024 17:39:42 -0400 Subject: [PATCH 2/2] Fix trailing whitespace. Signed-off-by: Chris Lalancette --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 83e7bb02..99301136 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -1046,7 +1046,7 @@ rmw_publish_serialized_message( uint64_t sequence_number = publisher_data->get_next_sequence_number(); - z_owned_bytes_map_t map = + z_owned_bytes_map_t map = create_map_and_set_sequence_num(sequence_number, publisher_data->pub_gid); if (!z_check(map)) {