13#ifndef IOX2_SAMPLE_MUT_UNINIT_HPP
14#define IOX2_SAMPLE_MUT_UNINIT_HPP
19#include "iox2/iceoryx2_cxx_deployment.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>>
81 template <typename T = Payload,
86 template <typename T = Payload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, T>>
87 auto
write_from_fn(const
iox2::bb::StaticFunction<typename T::ValueType(uint64_t)>& initializer)
91 template <typename T = Payload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, T>>
94#if IOX2_FEATURE_FLATBUFFERS
97 template <typename T = Payload, typename = std::enable_if_t<has_flatbuffer_marker<T>(), T>>
98 auto flatbuffer_builder() -> flatbuffers::FlatBufferBuilder&;
102 template <ServiceType,
typename,
typename>
105 template <ServiceType ST,
typename PayloadT,
typename UserHeaderT>
108#if IOX2_FEATURE_FLATBUFFERS
109 template <ServiceType ST,
typename PayloadT,
typename UserHeaderT>
118 auto get_handle() -> iox2_sample_mut_h;
122#if IOX2_FEATURE_FLATBUFFERS
123 internal::ResizableMemoryPublishSubscribe<S>* m_memory =
nullptr;
130template <ServiceType S,
typename Payload,
typename UserHeader>
132 return std::move(self.m_sample);
135#if IOX2_FEATURE_FLATBUFFERS
139template <ServiceType S,
typename Payload,
typename UserHeader>
140inline auto assume_init(SampleMutUninit<S, Flatbuffer<Payload>, UserHeader>&& self, flatbuffers::Offset<Payload> root)
141 -> SampleMut<S, Flatbuffer<Payload>, UserHeader> {
142 self.flatbuffer_builder().Finish(root,
nullptr);
143 const auto* payload_ptr = self.flatbuffer_builder().GetBufferPointer();
144 auto handle = self.get_handle();
145 iox2_sample_mut_finish_serialized(&handle, payload_ptr);
150 return std::move(self.m_sample);
153template <ServiceType S,
typename Payload,
typename UserHeader>
154template <
typename T,
typename>
155inline auto SampleMutUninit<S, Payload, UserHeader>::flatbuffer_builder() -> flatbuffers::FlatBufferBuilder& {
156 return m_flatbuffer_builder.value();
161template <ServiceType S,
typename Payload,
typename UserHeader>
162inline auto SampleMutUninit<S, Payload, UserHeader>::get_handle() -> iox2_sample_mut_h {
163 return m_sample.m_handle;
166template <ServiceType S,
typename Payload,
typename UserHeader>
167template <
typename T,
typename>
169 return m_sample.header();
172template <ServiceType S,
typename Payload,
typename UserHeader>
173template <
typename T,
typename U,
typename>
175 return m_sample.template user_header<T>();
178template <ServiceType S,
typename Payload,
typename UserHeader>
179template <
typename T,
typename U,
typename>
181 return m_sample.template user_header_mut<T>();
184template <ServiceType S,
typename Payload,
typename UserHeader>
185template <
typename T,
typename>
187 return m_sample.payload();
190template <ServiceType S,
typename Payload,
typename UserHeader>
191template <
typename T,
typename>
193 return m_sample.payload_mut();
196template <ServiceType S,
typename Payload,
typename UserHeader>
197template <
typename T,
typename>
199 return m_sample.payload();
202template <ServiceType S,
typename Payload,
typename UserHeader>
203template <
typename T,
typename>
205 return m_sample.payload_mut();
208template <ServiceType S,
typename Payload,
typename UserHeader>
209template <
typename T,
typename>
211 new (&payload_mut()) Payload(std::forward<T>(value));
212 return std::move(m_sample);
215template <ServiceType S,
typename Payload,
typename UserHeader>
216template <
typename T,
typename>
219 auto slice = payload_mut();
220 for (uint64_t i = 0; i < slice.number_of_elements(); ++i) {
221 new (&slice[i])
typename T::ValueType(initializer(i));
223 return std::move(m_sample);
226template <ServiceType S,
typename Payload,
typename UserHeader>
227template <
typename T,
typename>
230 auto dest = payload_mut();
231 IOX2_ASSERT(dest.number_of_bytes() >= value.number_of_bytes(),
232 "Destination payload size is smaller than source slice size");
233 std::memcpy(dest.begin(), value.begin(), value.number_of_bytes());
234 return std::move(m_sample);
#define IOX2_ASSERT(condition, message)
only for debug builds: report fatal assert violation if expression evaluates to false
Sending endpoint of a publish-subscriber based communication.
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, PayloadT, UserHeaderT > &&self) -> SampleMut< ST, PayloadT, UserHeaderT >
~SampleMutUninit() noexcept=default
auto header() const -> HeaderPublishSubscribe
Returns a reference to the [Header] of the [Sample].
auto payload() const -> const ValueType &
Returns a reference to the const payload of the sample.
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
A class representing a slice of contiguous elements of type T.
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)