13#ifndef IOX2_RESPONSE_MUT_UNINIT_HPP
14#define IOX2_RESPONSE_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>
42template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
55 template <typename T = ResponsePayload, typename = std::enable_if_t<!
has_flatbuffer_marker<T>(),
void>>
59 template <typename T = ResponseUserHeader,
60 typename U = ResponsePayload,
62 std::enable_if_t<!std::is_same<
void, ResponseUserHeader>::value && !
has_flatbuffer_marker<U>(),
void>>
66 template <typename T = ResponseUserHeader,
67 typename U = ResponsePayload,
69 std::enable_if_t<!std::is_same<
void, ResponseUserHeader>::value && !
has_flatbuffer_marker<T>(),
void>>
73 template <typename T = ResponsePayload,
75 auto
payload() const -> const T&;
78 template <typename T = ResponsePayload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
79 auto
payload() const ->
bb::ImmutableSlice<ValueType>;
82 template <typename T = ResponsePayload,
87 template <typename T = ResponsePayload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
92 template <typename T = ResponsePayload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE,
void>>
93 void truncate(uint64_t number_of_elements);
97 template <typename T = ResponsePayload,
103 template <typename T = ResponsePayload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE, T>>
108 template <typename T = ResponsePayload, typename = std::enable_if_t<
bb::IsSlice<T>::VALUE, T>>
109 auto
write_from_fn(const
iox2::
bb::StaticFunction<typename T::ValueType(uint64_t)>& initializer)
112#if IOX2_FEATURE_FLATBUFFERS
115 template <typename T = ResponsePayload, typename = std::enable_if_t<has_flatbuffer_marker<T>(), T>>
120 template <ServiceType,
typename,
typename,
typename,
typename>
123 template <ServiceType S,
typename ResponsePayloadT,
typename ResponseUserHeaderT>
127#if IOX2_FEATURE_FLATBUFFERS
128 template <ServiceType S,
typename ResponsePayloadT,
typename ResponseUserHeaderT>
130 flatbuffers::Offset<ResponsePayloadT>)
136 auto get_handle() -> iox2_response_mut_h;
140#if IOX2_FEATURE_FLATBUFFERS
146template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
147template <
typename T,
typename>
149 return m_response.header();
152template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
153template <
typename T,
typename U,
typename>
158template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
159template <
typename T,
typename U,
typename>
164template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
165template <
typename T,
typename>
167 return m_response.payload();
170template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
171template <
typename T,
typename>
173 ->
bb::ImmutableSlice<ValueType> {
174 return m_response.payload();
177template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
178template <
typename T,
typename>
180 return m_response.payload_mut();
183template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
184template <
typename T,
typename>
187 return m_response.payload_mut();
190template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
191template <
typename T,
typename>
193 m_response.truncate(number_of_elements);
196template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
197template <
typename T,
typename>
201 return std::move(m_response);
204template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
205template <
typename T,
typename>
210 IOX2_ASSERT(dest.number_of_bytes() >= value.number_of_bytes(),
211 "Destination payload size is smaller than source slice size");
212 std::memcpy(dest.begin(), value.begin(), value.number_of_bytes());
213 return std::move(m_response);
216template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
217template <
typename T,
typename>
222 for (uint64_t i = 0; i < slice.number_of_elements(); ++i) {
223 new (&slice[i])
typename T::ValueType(initializer(i));
225 return std::move(m_response);
228template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
229inline auto ResponseMutUninit<Service, ResponsePayload, ResponseUserHeader>::get_handle() -> iox2_response_mut_h {
230 return m_response.m_handle;
233#if IOX2_FEATURE_FLATBUFFERS
234template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
235template <
typename T,
typename>
237 -> flatbuffers::FlatBufferBuilder& {
238 return m_flatbuffer_builder.value();
241template <ServiceType S,
typename ResponsePayload,
typename ResponseUserHeader>
243 flatbuffers::Offset<ResponsePayload> root)
245 self.flatbuffer_builder().Finish(root,
nullptr);
246 const auto* payload_ptr = self.flatbuffer_builder().GetBufferPointer();
247 auto handle = self.get_handle();
248 iox2_response_mut_finish_serialized(&handle, payload_ptr);
253 return std::move(self.m_response);
257template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
260 return std::move(self.m_response);
#define IOX2_ASSERT(condition, message)
only for debug builds: report fatal assert violation if expression evaluates to false
auto payload() const -> const T &
Returns a reference to the payload of the response.
auto payload_mut() -> T &
Returns a mutable reference to the payload of the response.
~ResponseMutUninit() noexcept=default
void truncate(uint64_t number_of_elements)
auto write_from_fn(const iox2::bb::StaticFunction< typename T::ValueType(uint64_t)> &initializer) -> ResponseMut< Service, T, ResponseUserHeader >
auto header() const -> ResponseHeader
Returns a reference to the [ResponseHeader].
auto write_from_slice(bb::ImmutableSlice< ValueType > &value) -> ResponseMut< Service, T, ResponseUserHeader >
auto user_header_mut() -> T &
Returns a mutable reference to the user header of the response.
friend class ActiveRequest
ResponseMutUninit(ResponseMutUninit &&rhs) noexcept=default
auto flatbuffer_builder() -> flatbuffers::FlatBufferBuilder &
auto write_payload(ResponsePayload &&payload) -> ResponseMut< Service, T, ResponseUserHeader >
auto user_header() const -> const T &
Returns a reference to the user header of the response.
friend auto assume_init(ResponseMutUninit< S, Flatbuffer< ResponsePayloadT >, ResponseUserHeaderT > &&self, flatbuffers::Offset< ResponsePayloadT >) -> ResponseMut< S, Flatbuffer< ResponsePayloadT >, ResponseUserHeaderT >
friend auto assume_init(ResponseMutUninit< S, ResponsePayloadT, ResponseUserHeaderT > &&self) -> ResponseMut< S, ResponsePayloadT, ResponseUserHeaderT >
auto operator=(ResponseMutUninit &&rhs) noexcept -> ResponseMutUninit &=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)