13#ifndef IOX2_RESPONSE_MUT_HPP
14#define IOX2_RESPONSE_MUT_HPP
36template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
53 template <typename T = ResponseUserHeader,
54 typename = std::enable_if_t<!std::is_same<
void, ResponseUserHeader>::value, T>>
58 template <typename T = ResponseUserHeader,
59 typename = std::enable_if_t<!std::is_same<
void, ResponseUserHeader>::value, T>>
63 template <typename T = ResponsePayload, typename = std::enable_if_t<!bb::IsSlice<T>::VALUE,
void>>
64 auto
payload() const -> const ResponsePayload&;
67 template <typename T = ResponsePayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE,
void>>
68 auto
payload() const -> bb::ImmutableSlice<ValueType>;
71 template <typename T = ResponsePayload, typename = std::enable_if_t<!bb::IsSlice<T>::VALUE,
void>>
75 template <typename T = ResponsePayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE,
void>>
81 template <
ServiceType, typename, typename, typename, typename>
86 template <
ServiceType S, typename ResponsePayloadT, typename ResponseUserHeaderT>
92 iox2_response_mut_t m_response;
93 iox2_response_mut_h m_handle =
nullptr;
99 *
this = std::move(rhs);
104void iox2_response_mut_move(iox2_response_mut_t*, iox2_response_mut_t*, iox2_response_mut_h*);
108template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
114 internal::iox2_response_mut_move(&rhs.m_response, &m_response, &m_handle);
115 rhs.m_handle =
nullptr;
121template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
126template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
128 iox2_response_header_h header_handle =
nullptr;
129 iox2_response_mut_header(&m_handle,
nullptr, &header_handle);
133template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
134template <
typename T,
typename>
136 const void* ptr =
nullptr;
137 iox2_response_mut_user_header(&m_handle, &ptr);
138 return *
static_cast<const T*
>(ptr);
141template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
142template <
typename T,
typename>
145 iox2_response_mut_user_header_mut(&m_handle, &ptr);
146 return *
static_cast<T*
>(ptr);
149template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
150template <
typename T,
typename>
152 const void* ptr =
nullptr;
153 iox2_response_mut_payload(&m_handle, &ptr,
nullptr);
154 return *
static_cast<const T*
>(ptr);
157template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
158template <
typename T,
typename>
160 -> bb::ImmutableSlice<ValueType> {
161 const void* ptr =
nullptr;
162 size_t number_of_elements = 0;
163 iox2_response_mut_payload(&m_handle, &ptr, &number_of_elements);
167 auto length = number_of_elements;
168 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
169 length = iox2_response_mut_payload_number_of_bytes(&m_handle);
172 return bb::ImmutableSlice<ValueType>(
static_cast<const ValueType*
>(ptr), length);
175template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
176template <
typename T,
typename>
179 iox2_response_mut_payload_mut(&m_handle, &ptr,
nullptr);
180 return *
static_cast<ResponsePayload*
>(ptr);
183template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
184template <
typename T,
typename>
187 size_t number_of_elements = 0;
188 iox2_response_mut_payload_mut(&m_handle, &ptr, &number_of_elements);
192 auto length = number_of_elements;
193 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
194 length = iox2_response_mut_payload_number_of_bytes(&m_handle);
197 return bb::MutableSlice<ValueType>(
static_cast<ValueType*
>(ptr), length);
201template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
204 auto result = iox2_response_mut_send(response.m_handle);
205 response.m_handle =
nullptr;
207 if (result == IOX2_OK) {
210 return bb::err(bb::into<SendError>(result));
213template <ServiceType Service,
typename ResponsePayload,
typename ResponseUserHeader>
214inline void ResponseMut<Service, ResponsePayload, ResponseUserHeader>::drop() {
215 if (m_handle !=
nullptr) {
216 iox2_response_mut_drop(m_handle);
friend auto send(ResponseMut< S, ResponsePayloadT, ResponseUserHeaderT > &&response) -> bb::Expected< void, SendError >
auto header() const -> ResponseHeader
Returns a reference to the [ResponseHeader].
auto user_header() const -> const T &
Returns a reference to the user header of the response.
auto user_header_mut() -> T &
Returns a mutable reference to the user header of the response.
auto operator=(ResponseMut &&rhs) noexcept -> ResponseMut &
auto payload_mut() -> ResponsePayload &
Returns a mutable reference to the payload of the response.
ResponseMut(const ResponseMut &)=delete
auto operator=(const ResponseMut &) -> ResponseMut &=delete
auto payload() const -> const ResponsePayload &
Returns a reference to the payload of the response.
A class representing a slice of contiguous elements of type T.
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Expected< T, E > Expected
SendError
Failure that can be emitted when data is sent.