13#ifndef IOX2_SAMPLE_MUT_UNINIT_HPP
14#define IOX2_SAMPLE_MUT_UNINIT_HPP
18#include "iox2/deployment/iceoryx2_cxx_feature_flags.hpp"
25#if IOX2_FEATURE_FLATBUFFERS
28#include <flatbuffers/buffer.h>
29#include <flatbuffers/flatbuffer_builder.h>
33template <ServiceType S,
typename Payload,
typename UserHeader>
51 template <typename T = UserHeader,
53 typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value && !
has_flatbuffer_marker<U>(), T>>
57 template <typename T = UserHeader,
59 typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value && !
has_flatbuffer_marker<U>(), T>>
63 template <typename T = Payload,
65 auto
payload() const -> const ValueType&;
68 template <typename T = Payload,
73 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
74 auto
payload() const ->
bb::ImmutableSlice<ValueType>;
77 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
82 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
83 void truncate(uint64_t number_of_elements);
86 template <typename T = Payload,
91 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE, T>>
92 auto
write_from_fn(const
iox2::
bb::StaticFunction<typename T::ValueType(uint64_t)>& initializer)
96 template <typename T = Payload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE, T>>
99#if IOX2_FEATURE_FLATBUFFERS
102 template <typename T = Payload, typename = std::enable_if_t<has_flatbuffer_marker<T>(), T>>
107 template <ServiceType,
typename,
typename>
110 template <ServiceType ST,
typename PayloadT,
typename UserHeaderT>
113#if IOX2_FEATURE_FLATBUFFERS
114 template <ServiceType ST,
typename PayloadT,
typename UserHeaderT>
123 auto get_handle() -> iox2_sample_mut_h;
127#if IOX2_FEATURE_FLATBUFFERS
135template <ServiceType S,
typename Payload,
typename UserHeader>
137 return std::move(self.m_sample);
140#if IOX2_FEATURE_FLATBUFFERS
144template <ServiceType S,
typename Payload,
typename UserHeader>
147 self.flatbuffer_builder().Finish(root,
nullptr);
148 const auto* payload_ptr = self.flatbuffer_builder().GetBufferPointer();
149 auto handle = self.get_handle();
150 iox2_sample_mut_finish_serialized(&handle, payload_ptr);
155 return std::move(self.m_sample);
158template <ServiceType S,
typename Payload,
typename UserHeader>
159template <
typename T,
typename>
161 return m_flatbuffer_builder.value();
166template <ServiceType S,
typename Payload,
typename UserHeader>
167inline auto SampleMutUninit<S, Payload, UserHeader>::get_handle() -> iox2_sample_mut_h {
168 return m_sample.m_handle;
171template <ServiceType S,
typename Payload,
typename UserHeader>
172template <
typename T,
typename>
174 return m_sample.header();
177template <ServiceType S,
typename Payload,
typename UserHeader>
178template <
typename T,
typename U,
typename>
183template <ServiceType S,
typename Payload,
typename UserHeader>
184template <
typename T,
typename U,
typename>
189template <ServiceType S,
typename Payload,
typename UserHeader>
190template <
typename T,
typename>
192 return m_sample.payload();
195template <ServiceType S,
typename Payload,
typename UserHeader>
196template <
typename T,
typename>
198 return m_sample.payload_mut();
201template <ServiceType S,
typename Payload,
typename UserHeader>
202template <
typename T,
typename>
204 return m_sample.payload();
207template <ServiceType S,
typename Payload,
typename UserHeader>
208template <
typename T,
typename>
210 return m_sample.payload_mut();
213template <ServiceType S,
typename Payload,
typename UserHeader>
214template <
typename T,
typename>
216 m_sample.truncate(number_of_elements);
219template <ServiceType S,
typename Payload,
typename UserHeader>
220template <
typename T,
typename>
222 new (&
payload_mut()) Payload(std::forward<T>(value));
223 return std::move(m_sample);
226template <ServiceType S,
typename Payload,
typename UserHeader>
227template <
typename T,
typename>
231 for (uint64_t i = 0; i < slice.number_of_elements(); ++i) {
232 new (&slice[i])
typename T::ValueType(initializer(i));
234 return std::move(m_sample);
237template <ServiceType S,
typename Payload,
typename UserHeader>
238template <
typename T,
typename>
242 IOX2_ASSERT(dest.number_of_bytes() >= value.number_of_bytes(),
243 "Destination payload size is smaller than source slice size");
244 std::memcpy(dest.begin(), value.begin(), value.number_of_bytes());
245 return std::move(m_sample);
#define IOX2_ASSERT(condition, message)
only for debug builds: report fatal assert violation if expression evaluates to false
auto payload_mut() -> ValueType &
Returns a reference to the payload of the sample.
auto user_header() const -> const T &
Returns a reference to the user_header of the [Sample].
auto write_payload(T &&value) -> SampleMut< S, Payload, UserHeader >
Writes the payload to the sample.
auto operator=(SampleMutUninit &&rhs) noexcept -> SampleMutUninit &=default
friend auto assume_init(SampleMutUninit< ST, Flatbuffer< PayloadT >, UserHeaderT > &&self, flatbuffers::Offset< PayloadT >) -> SampleMut< ST, Flatbuffer< PayloadT >, UserHeaderT >
friend auto assume_init(SampleMutUninit< ST, PayloadT, UserHeaderT > &&self) -> SampleMut< ST, PayloadT, UserHeaderT >
~SampleMutUninit() noexcept=default
auto header() const -> HeaderPublishSubscribe
Returns a reference to the [Header] of the [Sample].
void truncate(uint64_t number_of_elements)
auto payload() const -> const ValueType &
Returns a reference to the const payload of the sample.
auto flatbuffer_builder() -> flatbuffers::FlatBufferBuilder &
auto user_header_mut() -> T &
Returns a mutable reference to the user_header of the [Sample].
auto write_from_fn(const iox2::bb::StaticFunction< typename T::ValueType(uint64_t)> &initializer) -> SampleMut< S, Payload, UserHeader >
Writes the payload to the sample.
auto write_from_slice(bb::ImmutableSlice< ValueType > &value) -> SampleMut< S, Payload, UserHeader >
mem copies the value to the sample
SampleMutUninit(SampleMutUninit &&rhs) noexcept=default
Internal helper class to handle dynamic memory allocations used in e.g. flatbuffers.
detail::StaticFunction< Capacity, Signature > StaticFunction
A static memory replacement for std::function.
Slice< const T > ImmutableSlice
iox2::bb::variation::Optional< T > Optional
constexpr auto has_flatbuffer_marker() -> bool
auto assume_init(RequestMutUninit< Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader > &&self) -> RequestMut< Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader >
Identifies payloads that are serialized via flatbuffer.
static void placement_default(S &payload)