Skip to content

Commit

Permalink
[#500] Use iox::vector instead of std::array
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Nov 13, 2024
1 parent bb80099 commit d6541f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
#define IOX2_UNIQUE_PORT_ID_HPP

#include "iox/optional.hpp"
#include "iox/vector.hpp"
#include "iox2/internal/iceoryx2.hpp"

#include <array>

namespace iox2 {

constexpr uint64_t UNIQUE_PORT_ID_LENGTH = 128;
using RawIdType = std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>;
using RawIdType = iox::vector<uint8_t, UNIQUE_PORT_ID_LENGTH>;

/// The system-wide unique id of a [`Publisher`].
class UniquePublisherId {
Expand Down
8 changes: 4 additions & 4 deletions iceoryx2-ffi/cxx/src/unique_port_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ UniquePublisherId::UniquePublisherId(iox2_unique_publisher_id_h handle)

auto UniquePublisherId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 };
iox2_unique_publisher_id_value(m_handle, bytes.data());
m_raw_id.emplace(std::move(bytes));
}
Expand Down Expand Up @@ -92,7 +92,7 @@ UniqueSubscriberId::UniqueSubscriberId(iox2_unique_subscriber_id_h handle)

auto UniqueSubscriberId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 };
iox2_unique_subscriber_id_value(m_handle, bytes.data());
m_raw_id.emplace(std::move(bytes));
}
Expand Down Expand Up @@ -138,7 +138,7 @@ UniqueNotifierId::UniqueNotifierId(iox2_unique_notifier_id_h handle)

auto UniqueNotifierId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 };
iox2_unique_notifier_id_value(m_handle, bytes.data());
m_raw_id.emplace(std::move(bytes));
}
Expand Down Expand Up @@ -184,7 +184,7 @@ UniqueListenerId::UniqueListenerId(iox2_unique_listener_id_h handle)

auto UniqueListenerId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 };
iox2_unique_listener_id_value(m_handle, bytes.data());
m_raw_id.emplace(std::move(bytes));
}
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-ffi/cxx/tests/src/unique_port_id_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ struct UniquePortIdTest : public ::testing::Test {
TYPED_TEST_SUITE(UniquePortIdTest, iox2_testing::ServiceTypes);

TYPED_TEST(UniquePortIdTest, unique_port_id_value) {
auto null_id = std::array<uint8_t, iox2::UNIQUE_PORT_ID_LENGTH> {};
auto null_id = iox::vector<uint8_t, iox2::UNIQUE_PORT_ID_LENGTH> { iox2::UNIQUE_PORT_ID_LENGTH, 0 };

auto unique_publisher_id = this->publisher_1.id();
ASSERT_TRUE(unique_publisher_id.bytes().has_value());
ASSERT_NE(unique_publisher_id.bytes().value(), null_id);

auto unique_subscriber_id = this->publisher_1.id();
auto unique_subscriber_id = this->subscriber_1.id();
ASSERT_TRUE(unique_subscriber_id.bytes().has_value());
ASSERT_NE(unique_subscriber_id.bytes().value(), null_id);

Expand Down

0 comments on commit d6541f1

Please sign in to comment.