Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zenoh 1.0.0 Porting #276

Open
wants to merge 116 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
e2fabb6
Update style.yaml
Mallets Jul 23, 2024
6cd6dbe
Update check_logging.yaml
Mallets Jul 23, 2024
dcefb68
Update build.yaml
Mallets Jul 23, 2024
14fe58c
chore: configure the compiliation
YuanYuYuan Jun 20, 2024
301a8ce
chore: complete the 1st version
YuanYuYuan Jun 25, 2024
8ef92b5
fix: memory leak
YuanYuYuan Jul 18, 2024
06b6fa4
wip
YuanYuYuan Jul 25, 2024
71e7c5b
fix: z_error_t -> z_result_t
YuanYuYuan Jul 26, 2024
a717270
Fix `scouting/*/autoconnect/*` per eclipse-zenoh/zenoh@b31a410 (#3)
fuzzypixelz Jul 24, 2024
cfa63d9
chore: checkout the local zenoh-c
YuanYuYuan Jul 30, 2024
12dc820
chore: polish z_open
YuanYuYuan Jul 31, 2024
d331b74
fix: segfault
YuanYuYuan Jul 31, 2024
1db4bef
feat: `z_bytes_serialize_from_slice` without copy
YuanYuYuan Jul 31, 2024
d12f189
chore: switch back to https://github.com/eclipse-zenoh/zenoh-c
YuanYuYuan Jul 31, 2024
909329b
Initialize `query_` member of `ZenohQuery`
fuzzypixelz Jul 26, 2024
511c6f6
refactor: use `z_owned_slice_t` instead
YuanYuYuan Jul 31, 2024
044d25b
chore: adapt the latest change of zenoh-c dev/1.0.0
YuanYuYuan Aug 2, 2024
d79cf5e
chore: use `strncmp` to avoid copying
YuanYuYuan Aug 7, 2024
6637400
refactor: use `z_view_keyexpr_t` to avoid copying
YuanYuYuan Aug 8, 2024
83334c8
feat: implment the SHM feature
YuanYuYuan Aug 8, 2024
bf0da8a
chore: adpat the new changes from zenoh-c and fix the bug in liveliness
YuanYuYuan Aug 13, 2024
dfc95ad
fix: segmentation fault due to the unallocated query memory
YuanYuYuan Aug 18, 2024
cd071e5
fix: workaround the ZID parsing issue
YuanYuYuan Aug 26, 2024
4f842fd
fix Zenoh Config read\check
yellowhatter Aug 22, 2024
af2e344
adopt to recent zenoh-c API changes
yellowhatter Aug 23, 2024
0225a59
chore: sync up with the rolling branch
YuanYuYuan Aug 27, 2024
36140fd
chore: update to self-hosted runners
imstevenpmwork Aug 27, 2024
080eb15
fix: adapt the latest change of batching config
YuanYuYuan Aug 29, 2024
f60c2a2
Merge remote-tracking branch 'origin/rolling' into dev/1.0.0
YuanYuYuan Aug 29, 2024
83a26f2
build: deprecate the zenohc_debug and incldue the zenohc dependency i…
YuanYuYuan Aug 29, 2024
31a76fd
Use main branch for upgrading to Zenoh 1.0
evshary Sep 2, 2024
7dba674
Merge pull request #14 from ZettaScaleLabs/update_branch
evshary Sep 2, 2024
b5cdd73
Increase the delay in scouting (#16)
evshary Sep 4, 2024
191181a
Merge remote-tracking branch 'origin/rolling' into dev/1.0.0
YuanYuYuan Sep 5, 2024
aed64e8
fixup! Merge remote-tracking branch 'origin/rolling' into dev/1.0.0
YuanYuYuan Sep 5, 2024
dd0e541
chore: ament_uncrustify and ament_cpplint
YuanYuYuan Sep 5, 2024
7dcc7d6
ci: fix the argument order in the style CI
YuanYuYuan Sep 5, 2024
7bbfdf5
chore: remove .clang_format
YuanYuYuan Sep 5, 2024
ed51a81
chore: clean up
YuanYuYuan Sep 5, 2024
975ea82
refactor: use `z_id_to_string`
YuanYuYuan Sep 5, 2024
17adcfa
chore: tidy up
YuanYuYuan Sep 5, 2024
e62c9bd
build: use the latest zenoh-c commit
YuanYuYuan Sep 5, 2024
458414d
build: enable the unstable feature flag
YuanYuYuan Sep 5, 2024
bf49775
chore: make iron ament_uncrustify happy
YuanYuYuan Sep 5, 2024
1630e11
test: check uncrustify version
YuanYuYuan Sep 5, 2024
c0a7533
fixup! test: check uncrustify version
YuanYuYuan Sep 5, 2024
798b006
chore: make iron ament_uncrustify happy
YuanYuYuan Sep 5, 2024
7d7a296
test
YuanYuYuan Sep 5, 2024
30aae80
Revert "test"
YuanYuYuan Sep 5, 2024
4f369c5
build: bump up the zenoh-c commit
YuanYuYuan Sep 9, 2024
39f10d5
chore(style): align rmw_zenoh.cpp
YuanYuYuan Sep 10, 2024
c7c17a6
chore(styel): align detail/rmw_data_types.cpp
YuanYuYuan Sep 10, 2024
1eef11d
chore(style): align rmw_init.cpp
YuanYuYuan Sep 10, 2024
e57ce89
chore(style): align detail/attachment_helpers.cpp
YuanYuYuan Sep 10, 2024
86940a8
build: update zenoh-c version
YuanYuYuan Sep 10, 2024
3aba418
chore(style): align the remaining files
YuanYuYuan Sep 10, 2024
05ff443
chore(style): consistently use `Z_OK` in the if condition
YuanYuYuan Sep 10, 2024
dd1e691
chore(style): ament_uncrustify
YuanYuYuan Sep 10, 2024
5bf7cc0
chore(style): ament_cpplint
YuanYuYuan Sep 10, 2024
206e34e
fix: set the max size of initial query queue to `SIZE_MAX - 1`
YuanYuYuan Sep 11, 2024
e9d0513
fix: iterator memory leak
YuanYuYuan Sep 16, 2024
520a3a2
feat: update to zenoh-c 1.0.0.8 changes
imstevenpmwork Sep 13, 2024
fce8a62
chore(style): address `ament_cpplint` and `ament_uncrustiy`
YuanYuYuan Sep 16, 2024
09c5cbc
fix: initiate zenoh logger
YuanYuYuan Sep 17, 2024
54dd96a
chore: apply the suggestions
YuanYuYuan Sep 19, 2024
becea93
chore: add the comments for the zenoh logger
YuanYuYuan Sep 19, 2024
9df5b82
Merge branch 'rolling' into dev/1.0.0
YuanYuYuan Sep 20, 2024
1f135c2
fix: store and destroy the subscriber properly
YuanYuYuan Sep 20, 2024
5177594
chore: improve the null pointer check: NULL => nullptr
YuanYuYuan Sep 20, 2024
6a48919
Change liveliness tokens logs from warn to debug level (#22)
JEnoch Sep 23, 2024
6fd7e1c
fix: properly clone the pointer of query and reply to resolve the seg…
YuanYuYuan Sep 27, 2024
8d3fce9
chore: update to zenoh-c 1.0.0.9 (#23)
imstevenpmwork Sep 27, 2024
73d68af
Sleep for 100ms between router checks (#284)
Yadunund Sep 25, 2024
16916cb
Fix how total_count and total_count_change are calculated for matched…
Yadunund Sep 27, 2024
f089982
Thread-safe access to graph cache (#258)
Yadunund Sep 27, 2024
63530b7
fix: adapt the latest changes in rolling
YuanYuYuan Sep 30, 2024
afd7f63
Merge remote-tracking branch 'origin/rolling' into dev/1.0.0
YuanYuYuan Sep 30, 2024
a67b194
Merge branch 'rolling' into wip/merge-rolling
YuanYuYuan Oct 1, 2024
c8724d2
fix: addres the conflict
YuanYuYuan Oct 2, 2024
979896a
Merge branch 'rolling' into wip/merge-rolling
YuanYuYuan Oct 2, 2024
d022967
chore: adapt the latest change
YuanYuYuan Oct 2, 2024
1cfc9f6
refactor(api): align with latest serialization changes
YuanYuYuan Oct 2, 2024
bb64fde
chore(deps): bump up zenoh-c to 1.0.0.10
YuanYuYuan Oct 2, 2024
4aef9e7
chore(api): align with latest serialization changes
imstevenpmwork Oct 2, 2024
c386a3d
fix: correct the sub_ke and selector_ke in the querying_subscriber
YuanYuYuan Oct 3, 2024
37134bb
Merge branch 'rolling' into wip/merge-rolling
YuanYuYuan Oct 7, 2024
93e733f
fix: thread-safe publisher
YuanYuYuan Oct 7, 2024
eeb9985
Enable history option for liveliness subscriber. (#27)
evshary Oct 8, 2024
bec4a52
refactor!: adopt the TLS config renaming
YuanYuYuan Oct 8, 2024
f32daa9
refactor: allow Zenoh session to close without dropping
YuanYuYuan Oct 8, 2024
14d17b0
fix: address the failure in rclcpp/test_wait_for_message of delcaring…
YuanYuYuan Oct 8, 2024
60a2e8d
Merge branch 'wip/merge-rolling' into dev/1.0.0
YuanYuYuan Oct 8, 2024
589971e
test: close but not drop the session
YuanYuYuan Oct 8, 2024
9b65df5
Merge branch 'rolling' into wip/merge-rolling
YuanYuYuan Oct 9, 2024
c7d3a5b
fix: correct the merge
YuanYuYuan Oct 9, 2024
6ba342b
chore: Explicit false in adminspace config
imstevenpmwork Oct 9, 2024
143fa88
fix: enable admin space in rmw router and ros nodes
gabrik Oct 10, 2024
52070b2
Merge pull request #29 from ZettaScaleLabs/fix/enable-admin-space
imstevenpmwork Oct 10, 2024
5ae0e3a
Bump zenoh-c version. (#30)
evshary Oct 11, 2024
257de16
Use the latest zenoh-c which fix some nav2 issues. (#31)
evshary Oct 14, 2024
736c34e
Update config files according to Zenoh 1.0.0 DEFAULT_CONFIG.json5 (#33)
JEnoch Oct 15, 2024
030959f
Merge branch 'rolling' into wip/merge-rolling
YuanYuYuan Oct 24, 2024
ec8aa99
chore(zenoh_c_vendor): bumb up zenoh-c version
YuanYuYuan Oct 24, 2024
ab5e0be
fix: adjust the merge
YuanYuYuan Oct 24, 2024
24f479b
refactor: remove the free_attachment
YuanYuYuan Oct 24, 2024
e6b7ecb
Fix unset request header writer GUID (#36)
fuzzypixelz Oct 24, 2024
bc6f6d6
Merge branch 'dev/1.0.0' into wip/merge-rolling
YuanYuYuan Oct 24, 2024
8024b7a
fix: keyexpr is missing in the service
YuanYuYuan Oct 24, 2024
3a5cc80
style: ament_uncrustify
YuanYuYuan Oct 24, 2024
5c3d385
style: apply iron ament_uncrustify
YuanYuYuan Oct 24, 2024
bb8e0ec
Avoid touching Zenoh Session while exiting. (#37)
evshary Oct 31, 2024
787376c
chore(deps): bump up zenoh-c to 1.0.1
YuanYuYuan Nov 4, 2024
ec7776e
Merge branch 'rolling' into wip/merge-rolling
YuanYuYuan Nov 7, 2024
2cfa97c
fix: adjust the merge
YuanYuYuan Nov 7, 2024
28d917e
style: ament_cpplint
YuanYuYuan Nov 7, 2024
f400ab5
SHM support (#39)
yellowhatter Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: uncrustify
run: /ros_entrypoint.sh ament_uncrustify --exclude rmw_zenoh_cpp/src/detail/ordered_hash.hpp rmw_zenoh_cpp/src/detail/ordered_map.hpp rmw_zenoh_cpp/
run: /ros_entrypoint.sh ament_uncrustify rmw_zenoh_cpp/ --exclude rmw_zenoh_cpp/src/detail/ordered_hash.hpp rmw_zenoh_cpp/src/detail/ordered_map.hpp
- name: cpplint
run: /ros_entrypoint.sh ament_cpplint --exclude rmw_zenoh_cpp/src/detail/ordered_hash.hpp rmw_zenoh_cpp/src/detail/ordered_map.hpp rmw_zenoh_cpp/
run: /ros_entrypoint.sh ament_cpplint rmw_zenoh_cpp/ --exclude rmw_zenoh_cpp/src/detail/ordered_hash.hpp rmw_zenoh_cpp/src/detail/ordered_map.hpp
4 changes: 0 additions & 4 deletions rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ find_package(rosidl_typesupport_fastrtps_c REQUIRED)
find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
find_package(rmw REQUIRED)
find_package(zenoh_c_vendor REQUIRED)
find_package(zenohc_debug QUIET)
Yadunund marked this conversation as resolved.
Show resolved Hide resolved
if(NOT zenohc_debug_FOUND)
find_package(zenohc REQUIRED)
endif()

add_library(rmw_zenoh_cpp SHARED
src/detail/attachment_helpers.cpp
Expand Down
23 changes: 15 additions & 8 deletions rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_ROUTER_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
},
/// Configure the scouting mechanisms and their behaviours
scouting: {
/// In client mode, the period dedicated to scouting for a router before failing
/// In client mode, the period in milliseconds dedicated to scouting for a router before failing.
timeout: 3000,
/// In peer mode, the period dedicated to scouting remote peers before attempting other operations
delay: 1,
/// In peer mode, the maximum period in milliseconds dedicated to scouting remote peers before attempting other operations.
delay: 500,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the rationale for increasing this delay?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the default value in Zenoh config. We aligned it with the current one.
In fact, this is the maximum delay, which means it doesn't always take 500 ms everytime. zenoh::open() can return quicker than this delay if some preconditions are met (configured peers are connected and scouted peers are connected when enabled).

/// The multicast scouting configuration.
multicast: {
/// Whether multicast scouting is enabled or not
Expand All @@ -44,7 +44,7 @@
/// Which type of Zenoh instances to automatically establish sessions with upon discovery on UDP multicast.
/// Accepts a single value or different values for router, peer and client.
/// Each value is bit-or-like combinations of "peer", "router" and "client".
autoconnect: { router: "", peer: "router|peer" },
autoconnect: { router: [], peer: ["router", "peer"] },
/// Whether or not to listen for scout messages on UDP multicast and reply to them.
listen: true,
},
Expand All @@ -61,7 +61,7 @@
/// Which type of Zenoh instances to automatically establish sessions with upon discovery on gossip.
/// Accepts a single value or different values for router, peer and client.
/// Each value is bit-or-like combinations of "peer", "router" and "client".
autoconnect: { router: "", peer: "router|peer" },
autoconnect: { router: [], peer: ["router", "peer"] },
},
},

Expand Down Expand Up @@ -183,9 +183,16 @@
data_low: 4,
background: 4,
},
/// The initial exponential backoff time in nanoseconds to allow the batching to eventually progress.
/// Higher values lead to a more aggressive batching but it will introduce additional latency.
backoff: 100,
/// Perform batching of messages if they are smaller of the batch_size
batching: {
/// Perform adaptive batching of messages if they are smaller of the batch_size.
/// When the network is detected to not be fast enough to transmit every message individually, many small messages may be
/// batched together and sent all at once on the wire reducing the overall network overhead. This is typically of a high-throughput
/// scenario mainly composed of small messages. In other words, batching is activated by the network back-pressure.
enabled: true,
/// The maximum time limit (in ms) a message should be retained for batching when back-pressure happens.
time_limit: 1,
}
},
// Number of threads dedicated to transmission
// By default, the number of threads is calculated as follows: 1 + ((#cores - 1) / 4)
Expand Down
23 changes: 15 additions & 8 deletions rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
},
/// Configure the scouting mechanisms and their behaviours
scouting: {
/// In client mode, the period dedicated to scouting for a router before failing
/// In client mode, the period in milliseconds dedicated to scouting for a router before failing.
timeout: 3000,
/// In peer mode, the period dedicated to scouting remote peers before attempting other operations
delay: 1,
/// In peer mode, the maximum period in milliseconds dedicated to scouting remote peers before attempting other operations.
delay: 500,
/// The multicast scouting configuration.
multicast: {
/// Whether multicast scouting is enabled or not
Expand All @@ -47,7 +47,7 @@
/// Which type of Zenoh instances to automatically establish sessions with upon discovery on UDP multicast.
/// Accepts a single value or different values for router, peer and client.
/// Each value is bit-or-like combinations of "peer", "router" and "client".
autoconnect: { router: "", peer: "router|peer" },
autoconnect: { router: [], peer: ["router", "peer"] },
/// Whether or not to listen for scout messages on UDP multicast and reply to them.
listen: true,
},
Expand All @@ -64,7 +64,7 @@
/// Which type of Zenoh instances to automatically establish sessions with upon discovery on gossip.
/// Accepts a single value or different values for router, peer and client.
/// Each value is bit-or-like combinations of "peer", "router" and "client".
autoconnect: { router: "", peer: "router|peer" },
autoconnect: { router: [], peer: ["router", "peer"] },
},
},

Expand Down Expand Up @@ -186,9 +186,16 @@
data_low: 4,
background: 4,
},
/// The initial exponential backoff time in nanoseconds to allow the batching to eventually progress.
/// Higher values lead to a more aggressive batching but it will introduce additional latency.
backoff: 100,
/// Perform batching of messages if they are smaller of the batch_size
batching: {
/// Perform adaptive batching of messages if they are smaller of the batch_size.
/// When the network is detected to not be fast enough to transmit every message individually, many small messages may be
/// batched together and sent all at once on the wire reducing the overall network overhead. This is typically of a high-throughput
/// scenario mainly composed of small messages. In other words, batching is activated by the network back-pressure.
enabled: true,
/// The maximum time limit (in ms) a message should be retained for batching when back-pressure happens.
time_limit: 1,
}
},
// Number of threads dedicated to transmission
// By default, the number of threads is calculated as follows: 1 + ((#cores - 1) / 4)
Expand Down
142 changes: 106 additions & 36 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,77 +20,147 @@

#include "rmw/types.h"

#include "logging_macros.hpp"

#include "attachment_helpers.hpp"

namespace rmw_zenoh_cpp
{
bool get_gid_from_attachment(
const z_attachment_t * const attachment, uint8_t gid[RMW_GID_STORAGE_SIZE])

bool create_attachment_iter(z_owned_bytes_t * kv_pair, void * context)
{
if (!z_check(*attachment)) {
attachement_context_t * ctx = reinterpret_cast<attachement_context_t *>(context);
z_owned_bytes_t k, v;

if (ctx->idx == 0) {
z_bytes_serialize_from_str(&k, "sequence_number");
z_bytes_serialize_from_int64(&v, ctx->data->sequence_number);
} else if (ctx->idx == 1) {
z_bytes_serialize_from_str(&k, "source_timestamp");
z_bytes_serialize_from_int64(&v, ctx->data->source_timestamp);
} else if (ctx->idx == 2) {
z_bytes_serialize_from_str(&k, "source_gid");
z_bytes_serialize_from_buf(
&v, ctx->data->source_gid,
RMW_GID_STORAGE_SIZE);
} else {
return false;
}

z_bytes_t index = z_attachment_get(*attachment, z_bytes_new("source_gid"));
if (!z_check(index)) {
z_bytes_from_pair(kv_pair, z_move(k), z_move(v));
ctx->idx += 1;
return true;
}

z_result_t attachement_data_t::serialize_to_zbytes(z_owned_bytes_t * attachment)
{
attachement_context_t context = attachement_context_t(this);
return z_bytes_from_iter(
attachment, create_attachment_iter,
reinterpret_cast<void *>(&context));
}

bool get_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & key, z_owned_bytes_t * val)
{
if (attachment == NULL || z_bytes_is_empty(attachment)) {
return false;
}

if (index.len != RMW_GID_STORAGE_SIZE) {
z_bytes_iterator_t iter = z_bytes_get_iterator(attachment);
z_owned_bytes_t pair, key_;
bool found = false;

while (z_bytes_iterator_next(&iter, &pair)) {
z_bytes_deserialize_into_pair(z_loan(pair), &key_, val);
z_owned_string_t key_string;
z_bytes_deserialize_into_string(z_loan(key_), &key_string);

const char * key_string_ptr = z_string_data(z_loan(key_string));
size_t key_string_len = z_string_len(z_loan(key_string));
if (key_string_len == key.length() && strncmp(key_string_ptr, key.c_str(), key.length()) == 0) {
found = true;
}

z_drop(z_move(pair));
z_drop(z_move(key_));
z_drop(z_move(key_string));

if (found) {
break;
} else {
z_drop(z_move(*val));
}
}

if (!found) {
return false;
}

memcpy(gid, index.start, index.len);
if (z_bytes_is_empty(z_loan(*val))) {
return false;
}

return true;
}

int64_t get_int64_from_attachment(
const z_attachment_t * const attachment, const std::string & name)
bool get_gid_from_attachment(
const z_loaned_bytes_t * const attachment,
uint8_t gid[RMW_GID_STORAGE_SIZE])
{
if (!z_check(*attachment)) {
// A valid request must have had an attachment
return -1;
if (attachment == NULL || z_bytes_is_empty(attachment)) {
return false;
}

z_bytes_t index = z_attachment_get(*attachment, z_bytes_new(name.c_str()));
if (!z_check(index)) {
return -1;
z_owned_bytes_t val;
if (!get_attachment(attachment, "source_gid", &val)) {
return false;
}

if (index.len < 1) {
return -1;
z_owned_slice_t slice;
z_bytes_deserialize_into_slice(z_loan(val), &slice);
if (z_slice_len(z_loan(slice)) != RMW_GID_STORAGE_SIZE) {
RMW_ZENOH_LOG_ERROR_NAMED("rmw_zenoh_cpp", "GID length mismatched.")
return false;
}
memcpy(gid, z_slice_data(z_loan(slice)), z_slice_len(z_loan(slice)));

z_drop(z_move(val));
z_drop(z_move(slice));

if (index.len > 19) {
// The number was larger than we expected
return true;
}

int64_t get_int64_from_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & name)
{
// A valid request must have had an attachment
if (attachment == NULL || z_bytes_is_empty(attachment)) {
return -1;
}

// The largest possible int64_t number is INT64_MAX, i.e. 9223372036854775807.
// That is 19 characters long, plus one for the trailing \0, means we need 20 bytes.
char int64_str[20];
// TODO(yuyuan): This key should be specific
z_owned_bytes_t val;
if (!get_attachment(attachment, name, &val)) {
RMW_ZENOH_LOG_ERROR_NAMED(
"rmw_zenoh_cpp", "Failed to deserialize int64 from the attachment.")
return false;
}

memcpy(int64_str, index.start, index.len);
int64_str[index.len] = '\0';
int64_t num;
if (z_bytes_deserialize_into_int64(z_loan(val), &num) != Z_OK) {
return -1;
}

errno = 0;
char * endptr;
int64_t num = strtol(int64_str, &endptr, 10);
if (num == 0) {
// This is an error regardless; the client should never send this
return -1;
} else if (endptr == int64_str) {
// No values were converted, this is an error
return -1;
} else if (*endptr != '\0') {
// There was junk after the number
return -1;
} else if (errno != 0) {
// Some other error occurred, which may include overflow or underflow
return -1;
}

z_drop(z_move(val));

return num;
}
} // namespace rmw_zenoh_cpp
40 changes: 38 additions & 2 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,47 @@

namespace rmw_zenoh_cpp
{

class attachement_data_t final
{
public:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move data members into private scope and provide accessor functions if needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would introduce lots of complexity since we need to do some serializations in attachment_helpers.cpp which need to access the values. To make them private, we need to provide either public serialization functions or public get functions (including returning an array pointer of a known sized array source_gid[RMW_GID_STORAGE_SIZE])

int64_t sequence_number;
int64_t source_timestamp;
uint8_t source_gid[RMW_GID_STORAGE_SIZE];
attachement_data_t(
YuanYuYuan marked this conversation as resolved.
Show resolved Hide resolved
const int64_t _sequence_number,
const int64_t _source_timestamp,
const uint8_t _source_gid[RMW_GID_STORAGE_SIZE])
{
sequence_number = _sequence_number;
source_timestamp = _source_timestamp;
memcpy(source_gid, _source_gid, RMW_GID_STORAGE_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <cstring>

}
z_result_t serialize_to_zbytes(z_owned_bytes_t *);
};

class attachement_context_t final
{
public:
const attachement_data_t * data;
int length = 3;
int idx = 0;

attachement_context_t(const attachement_data_t * _data)
YuanYuYuan marked this conversation as resolved.
Show resolved Hide resolved
: data(_data) {}
};

bool get_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & key, z_owned_bytes_t * val);

bool get_gid_from_attachment(
const z_attachment_t * const attachment, uint8_t gid[RMW_GID_STORAGE_SIZE]);
const z_loaned_bytes_t * const attachment,
YuanYuYuan marked this conversation as resolved.
Show resolved Hide resolved
uint8_t gid[RMW_GID_STORAGE_SIZE]);

int64_t get_int64_from_attachment(
const z_attachment_t * const attachment, const std::string & name);
const z_loaned_bytes_t * const attachment,
const std::string & name);
} // namespace rmw_zenoh_cpp

#endif // DETAIL__ATTACHMENT_HELPERS_HPP_
1 change: 0 additions & 1 deletion rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <memory>
#include <mutex>
#include <optional>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
Expand Down
4 changes: 1 addition & 3 deletions rmw_zenoh_cpp/src/detail/graph_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
#include "ordered_map.hpp"

#include "rcutils/allocator.h"
#include "rcutils/types.h"

#include "rmw/rmw.h"
#include "rmw/get_topic_endpoint_info.h"
#include "rmw/topic_endpoint_info_array.h"
#include "rmw/names_and_types.h"


Expand Down
Loading