|
39 | 39 | #include "detail/rmw_data_types.hpp"
|
40 | 40 | #include "detail/serialization_format.hpp"
|
41 | 41 | #include "detail/type_support_common.hpp"
|
| 42 | +#include "detail/zenoh_utils.hpp" |
42 | 43 |
|
43 | 44 | #include "rcpputils/scope_exit.hpp"
|
44 | 45 |
|
@@ -568,51 +569,6 @@ rmw_return_loaned_message_from_publisher(
|
568 | 569 | return RMW_RET_UNSUPPORTED;
|
569 | 570 | }
|
570 | 571 |
|
571 |
| -namespace |
572 |
| -{ |
573 |
| -z_owned_bytes_map_t |
574 |
| -create_map_and_set_sequence_num(int64_t sequence_number, const uint8_t gid[RMW_GID_STORAGE_SIZE]) |
575 |
| -{ |
576 |
| - z_owned_bytes_map_t map = z_bytes_map_new(); |
577 |
| - if (!z_check(map)) { |
578 |
| - RMW_SET_ERROR_MSG("failed to allocate map for sequence number"); |
579 |
| - return z_bytes_map_null(); |
580 |
| - } |
581 |
| - auto free_attachment_map = rcpputils::make_scope_exit( |
582 |
| - [&map]() { |
583 |
| - z_bytes_map_drop(z_move(map)); |
584 |
| - }); |
585 |
| - |
586 |
| - // The largest possible int64_t number is INT64_MAX, i.e. 9223372036854775807. |
587 |
| - // That is 19 characters long, plus one for the trailing \0, means we need 20 bytes. |
588 |
| - char seq_id_str[20]; |
589 |
| - if (rcutils_snprintf(seq_id_str, sizeof(seq_id_str), "%" PRId64, sequence_number) < 0) { |
590 |
| - RMW_SET_ERROR_MSG("failed to print sequence_number into buffer"); |
591 |
| - return z_bytes_map_null(); |
592 |
| - } |
593 |
| - z_bytes_map_insert_by_copy(&map, z_bytes_new("sequence_number"), z_bytes_new(seq_id_str)); |
594 |
| - |
595 |
| - auto now = std::chrono::system_clock::now().time_since_epoch(); |
596 |
| - auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now); |
597 |
| - char source_ts_str[20]; |
598 |
| - if (rcutils_snprintf(source_ts_str, sizeof(source_ts_str), "%" PRId64, now_ns.count()) < 0) { |
599 |
| - RMW_SET_ERROR_MSG("failed to print sequence_number into buffer"); |
600 |
| - return z_bytes_map_null(); |
601 |
| - } |
602 |
| - z_bytes_map_insert_by_copy(&map, z_bytes_new("source_timestamp"), z_bytes_new(source_ts_str)); |
603 |
| - |
604 |
| - z_bytes_t gid_bytes; |
605 |
| - gid_bytes.len = RMW_GID_STORAGE_SIZE; |
606 |
| - gid_bytes.start = gid; |
607 |
| - |
608 |
| - z_bytes_map_insert_by_copy(&map, z_bytes_new("source_gid"), gid_bytes); |
609 |
| - |
610 |
| - free_attachment_map.cancel(); |
611 |
| - |
612 |
| - return map; |
613 |
| -} |
614 |
| -} // namespace |
615 |
| - |
616 | 572 | //==============================================================================
|
617 | 573 | /// Publish a ROS message.
|
618 | 574 | rmw_ret_t
|
@@ -766,7 +722,7 @@ rmw_publish_serialized_message(
|
766 | 722 | uint64_t sequence_number = publisher_data->get_next_sequence_number();
|
767 | 723 |
|
768 | 724 | z_owned_bytes_map_t map =
|
769 |
| - create_map_and_set_sequence_num(sequence_number, publisher_data->gid()); |
| 725 | + rmw_zenoh_cpp::create_map_and_set_sequence_num(sequence_number, publisher_data->gid()); |
770 | 726 |
|
771 | 727 | if (!z_check(map)) {
|
772 | 728 | // create_map_and_set_sequence_num already set the error
|
@@ -2170,7 +2126,8 @@ rmw_send_request(
|
2170 | 2126 | // Send request
|
2171 | 2127 | z_get_options_t opts = z_get_options_default();
|
2172 | 2128 |
|
2173 |
| - z_owned_bytes_map_t map = create_map_and_set_sequence_num(*sequence_id, client_data->client_gid); |
| 2129 | + z_owned_bytes_map_t map = rmw_zenoh_cpp::create_map_and_set_sequence_num(*sequence_id, |
| 2130 | + client_data->client_gid); |
2174 | 2131 | if (!z_check(map)) {
|
2175 | 2132 | // create_map_and_set_sequence_num already set the error
|
2176 | 2133 | return RMW_RET_ERROR;
|
@@ -2861,7 +2818,7 @@ rmw_send_response(
|
2861 | 2818 | const z_query_t loaned_query = query->get_query();
|
2862 | 2819 | z_query_reply_options_t options = z_query_reply_options_default();
|
2863 | 2820 |
|
2864 |
| - z_owned_bytes_map_t map = create_map_and_set_sequence_num( |
| 2821 | + z_owned_bytes_map_t map = rmw_zenoh_cpp::create_map_and_set_sequence_num( |
2865 | 2822 | request_header->sequence_number, request_header->writer_guid);
|
2866 | 2823 | if (!z_check(map)) {
|
2867 | 2824 | // create_map_and_set_sequence_num already set the error
|
|
0 commit comments