Skip to content

Commit

Permalink
[#490] Rename worst_case_memory_size to maximum_elements in slice exa…
Browse files Browse the repository at this point in the history
…mple
  • Loading branch information
orecham committed Nov 7, 2024
1 parent 5962a0c commit 91f3cf2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions examples/cxx/publish_subscribe_dynamic_data/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ auto main() -> int {
.open_or_create()
.expect("successful service creation/opening");

const uint64_t worst_case_memory_size = 1024; // NOLINT
auto publisher = service.publisher_builder()
.max_slice_len(worst_case_memory_size)
.create()
.expect("successful publisher creation");
// Since the payload type is uint8_t, this number is the same as the number of bytes in the payload.
// For other types, number of bytes used by the payload will be max_slice_len * sizeof(Payload::ValueType)
const uint64_t maximum_elements = 1024; // NOLINT
auto publisher =
service.publisher_builder().max_slice_len(maximum_elements).create().expect("successful publisher creation");

auto counter = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ auto main() -> int {
auto sample = subscriber.receive().expect("receive succeeds");
while (sample.has_value()) {
auto payload = sample->payload();
std::cout << "received " << std::dec << static_cast<int>(payload.size()) << " bytes: ";
std::cout << "received " << std::dec << static_cast<int>(payload.number_of_bytes()) << " bytes: ";
for (auto byte : payload) {
std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(byte) << " ";
}
Expand Down
3 changes: 1 addition & 2 deletions iceoryx2-ffi/cxx/include/iox/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ template <typename T>
Slice<T>::Slice(T* data, uint64_t number_of_elements)
: m_data { data }
, m_number_of_elements { number_of_elements } {
static_assert(!std::is_same_v<T, void>, "Slice<void> is not allowed");
}

template <typename T>
Expand Down Expand Up @@ -124,13 +125,11 @@ auto Slice<T>::begin() const -> Iterator {

template <typename T>
auto Slice<T>::end() -> Iterator {
static_assert(!std::is_same_v<T, void>, "Slice<void> is not allowed");
return m_data + m_number_of_elements;
}

template <typename T>
auto Slice<T>::end() const -> Iterator {
static_assert(!std::is_same_v<T, void>, "Slice<void> is not allowed");
return m_data + m_number_of_elements;
}

Expand Down
5 changes: 3 additions & 2 deletions iceoryx2-ffi/cxx/include/iox2/sample_mut_uninit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ template <ServiceType S, typename Payload, typename UserHeader>
template <typename T, typename>
inline void SampleMutUninit<S, Payload, UserHeader>::write_from_slice(iox::ImmutableSlice<ValueType>& value) {
auto dest = payload_mut();
IOX_ASSERT(dest.size() >= value.size(), "Destination payload size is smaller than source slice size");
std::memcpy(dest.begin(), value.begin(), value.size());
IOX_ASSERT(dest.number_of_bytes() >= value.number_of_bytes(),
"Destination payload size is smaller than source slice size");
std::memcpy(dest.begin(), value.begin(), value.number_of_bytes());
}
} // namespace iox2

Expand Down

0 comments on commit 91f3cf2

Please sign in to comment.