Skip to content

Commit b62a6e2

Browse files
authored
Merge pull request #340 from ZettaScaleLabs/fix/sub-high-latency
Fix the high latency on the subscriber due to zenoh bytes conversion
1 parent 9e17da2 commit b62a6e2

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string>
2525
#include <utility>
2626
#include <variant>
27+
#include <vector>
2728

2829
#include "attachment_helpers.hpp"
2930
#include "cdr.hpp"
@@ -43,7 +44,7 @@ namespace rmw_zenoh_cpp
4344
{
4445
///=============================================================================
4546
SubscriptionData::Message::Message(
46-
zenoh::Bytes p,
47+
std::vector<uint8_t> && p,
4748
uint64_t recv_ts,
4849
AttachmentData && attachment_)
4950
: payload(std::move(p)), recv_timestamp(recv_ts), attachment(std::move(attachment_))
@@ -224,7 +225,7 @@ bool SubscriptionData::init()
224225

225226
sub_data->add_new_message(
226227
std::make_unique<SubscriptionData::Message>(
227-
sample.get_payload().clone(),
228+
sample.get_payload().as_vector(),
228229
std::chrono::system_clock::now().time_since_epoch().count(),
229230
std::move(attachment_data)),
230231
std::string(sample.get_keyexpr().as_string_view()));
@@ -287,8 +288,6 @@ bool SubscriptionData::init()
287288
zenoh::Subscriber<void> sub = context_impl->session()->declare_subscriber(
288289
sub_ke,
289290
[data_wp](const zenoh::Sample & sample) {
290-
zenoh::KeyExpr keystr(std::string(sample.get_keyexpr().as_string_view()));
291-
292291
auto sub_data = data_wp.lock();
293292
if (sub_data == nullptr) {
294293
RMW_ZENOH_LOG_ERROR_NAMED(
@@ -310,10 +309,10 @@ bool SubscriptionData::init()
310309
AttachmentData attachment_data(attachment_value);
311310
sub_data->add_new_message(
312311
std::make_unique<SubscriptionData::Message>(
313-
sample.get_payload().clone(),
312+
payload.as_vector(),
314313
std::chrono::system_clock::now().time_since_epoch().count(),
315314
std::move(attachment_data)),
316-
std::string(keystr.as_string_view()));
315+
std::string(sample.get_keyexpr().as_string_view()));
317316
},
318317
zenoh::closures::none,
319318
std::move(sub_options),
@@ -491,7 +490,7 @@ rmw_ret_t SubscriptionData::take_one_message(
491490
std::unique_ptr<Message> msg_data = std::move(message_queue_.front());
492491
message_queue_.pop_front();
493492

494-
auto payload_data = msg_data->payload.as_vector();
493+
auto & payload_data = msg_data->payload;
495494

496495
if (payload_data.empty()) {
497496
RMW_ZENOH_LOG_DEBUG_NAMED(
@@ -549,7 +548,7 @@ rmw_ret_t SubscriptionData::take_serialized_message(
549548
std::unique_ptr<Message> msg_data = std::move(message_queue_.front());
550549
message_queue_.pop_front();
551550

552-
auto payload_data = msg_data->payload.as_vector();
551+
auto & payload_data = msg_data->payload;
553552

554553
if (payload_data.empty()) {
555554
RMW_ZENOH_LOG_DEBUG_NAMED(

rmw_zenoh_cpp/src/detail/rmw_subscription_data.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <string>
2626
#include <unordered_map>
2727
#include <variant>
28+
#include <vector>
2829

2930
#include <zenoh.hxx>
3031

@@ -50,13 +51,13 @@ class SubscriptionData final : public std::enable_shared_from_this<SubscriptionD
5051
struct Message
5152
{
5253
explicit Message(
53-
zenoh::Bytes p,
54+
std::vector<uint8_t> && p,
5455
uint64_t recv_ts,
5556
AttachmentData && attachment);
5657

5758
~Message();
5859

59-
zenoh::Bytes payload;
60+
std::vector<uint8_t> payload;
6061
uint64_t recv_timestamp;
6162
AttachmentData attachment;
6263
};

0 commit comments

Comments
 (0)