13#ifndef IOX2_SAMPLE_MUT_HPP
14#define IOX2_SAMPLE_MUT_HPP
18#include "iox2/deployment/iceoryx2_cxx_feature_flags.hpp"
20#include "iox2/iceoryx2.h"
28#if IOX2_FEATURE_FLATBUFFERS
29#include <flatbuffers/flatbuffers.h>
52template <ServiceType S,
typename Payload,
typename UserHeader>
69 template <typename T = UserHeader, typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value, T>>
73 template <typename T = UserHeader, typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value, T>>
77 template <typename T = Payload,
79 auto
payload() const -> const ValueType&;
82 template <typename T = Payload,
86#if IOX2_FEATURE_FLATBUFFERS
88 template <typename T = Payload, typename = std::enable_if_t<has_flatbuffer_marker<T>(),
void>>
93 auto
payload_root() const -> const typename T::ValueType*;
97 template <typename T = Payload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE,
void>>
98 auto payload() const ->
bb::ImmutableSlice<ValueType>;
101 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
106 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
107 void truncate(uint64_t number_of_elements);
115 template <
ServiceType ST, typename PayloadT, typename UserHeaderT>
124 iox2_sample_mut_t m_sample;
125 iox2_sample_mut_h m_handle =
nullptr;
128template <
ServiceType S, typename Payload, typename UserHeader>
129inline
void SampleMut<S, Payload, UserHeader>::drop() {
130 if (m_handle !=
nullptr) {
131 iox2_sample_mut_drop(m_handle);
137template <ServiceType S,
typename Payload,
typename UserHeader>
139 *
this = std::move(rhs);
148template <ServiceType S,
typename Payload,
typename UserHeader>
154 rhs.m_handle =
nullptr;
160template <ServiceType S,
typename Payload,
typename UserHeader>
165template <ServiceType S,
typename Payload,
typename UserHeader>
167 iox2_publish_subscribe_header_h header_handle =
nullptr;
168 iox2_sample_mut_header(&m_handle,
nullptr, &header_handle);
173template <ServiceType S,
typename Payload,
typename UserHeader>
174template <
typename T,
typename>
176 const void* ptr =
nullptr;
178 iox2_sample_mut_user_header(&m_handle, &ptr);
180 return *
static_cast<const T*
>(ptr);
183template <ServiceType S,
typename Payload,
typename UserHeader>
184template <
typename T,
typename>
188 iox2_sample_mut_user_header_mut(&m_handle, &ptr);
190 return *
static_cast<T*
>(ptr);
193template <ServiceType S,
typename Payload,
typename UserHeader>
194template <
typename T,
typename>
196 const void* ptr =
nullptr;
198 iox2_sample_mut_payload(&m_handle, &ptr,
nullptr);
200 return *
static_cast<const ValueType*
>(ptr);
203template <ServiceType S,
typename Payload,
typename UserHeader>
204template <
typename T,
typename>
208 iox2_sample_mut_payload_mut(&m_handle, &ptr,
nullptr);
210 return *
static_cast<ValueType*
>(ptr);
213template <ServiceType S,
typename Payload,
typename UserHeader>
214template <
typename T,
typename>
216 const void* ptr =
nullptr;
217 size_t number_of_elements = 0;
219 iox2_sample_mut_payload(&m_handle, &ptr, &number_of_elements);
223 auto length = number_of_elements;
224 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
225 length = iox2_sample_mut_payload_number_of_bytes(&m_handle);
231template <ServiceType S,
typename Payload,
typename UserHeader>
232template <
typename T,
typename>
235 size_t number_of_elements = 0;
237 iox2_sample_mut_payload_mut(&m_handle, &ptr, &number_of_elements);
239 auto length = number_of_elements;
240 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
241 length = iox2_sample_mut_payload_number_of_bytes(&m_handle);
247template <ServiceType S,
typename Payload,
typename UserHeader>
248template <
typename T,
typename>
250 iox2_sample_mut_truncate(&m_handle, number_of_elements);
253#if IOX2_FEATURE_FLATBUFFERS
255template <ServiceType S,
typename Payload,
typename UserHeader>
256template <
typename T,
typename>
258 const void* ptr =
nullptr;
259 size_t number_of_elements = 0;
261 iox2_sample_mut_payload(&m_handle, &ptr, &number_of_elements);
262 auto payload_offset =
header().payload_offset();
263 auto payload_len =
header().number_of_elements();
268template <ServiceType S,
typename Payload,
typename UserHeader>
269template <
typename T,
typename>
271 return flatbuffers::GetRoot<typename T::ValueType>(
payload_bytes().data());
276template <ServiceType S,
typename Payload,
typename UserHeader>
278 size_t number_of_recipients = 0;
279 auto result = iox2_sample_mut_send(sample.m_handle, &number_of_recipients);
280 sample.m_handle =
nullptr;
282 if (result == IOX2_OK) {
283 return number_of_recipients;
friend class SampleMutUninit
auto user_header_mut() -> T &
Returns a mutable reference to the user_header of the [Sample].
auto header() const -> HeaderPublishSubscribe
Returns a reference to the [Header] of the [Sample].
SampleMut(const SampleMut &)=delete
SampleMut(SampleMut &&rhs) noexcept
auto payload_mut() -> ValueType &
Returns a reference to the payload of the sample.
auto payload_root() const -> const typename T::ValueType *
Returns the root of the flatbuffer.
friend auto send(SampleMut< ST, PayloadT, UserHeaderT > &&sample) -> bb::Expected< size_t, SendError >
auto payload_bytes() const -> bb::ImmutableSlice< uint8_t >
Returns the serialized flatbuffer data as bytes.
auto payload() const -> const ValueType &
Returns a reference to the const payload of the sample.
void truncate(uint64_t number_of_elements)
auto user_header() const -> const T &
Returns a reference to the user_header of the [Sample].
auto operator=(const SampleMut &) -> SampleMut &=delete
auto operator=(SampleMut &&rhs) noexcept -> SampleMut &
constexpr auto into(const SourceType value) noexcept -> typename detail::ExtractIntoType< DestinationType >::TargetType
Converts a value of type SourceType to a corresponding value of type DestinationType....
Slice< const T > ImmutableSlice
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Expected< T, E > Expected
void iox2_sample_mut_move(iox2_sample_mut_t *, iox2_sample_mut_t *, iox2_sample_mut_h *)
constexpr auto has_flatbuffer_marker() -> bool
SendError
Failure that can be emitted when data is sent.