13#ifndef IOX2_SAMPLE_HPP
14#define IOX2_SAMPLE_HPP
39template <ServiceType,
typename Payload,
typename UserHeader>
53 template <typename T = Payload, typename = std::enable_if_t<!bb::IsSlice<T>::VALUE,
void>>
54 auto payload() const -> const ValueType&;
57 template <typename T = Payload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE,
void>>
58 auto
payload() const -> bb::ImmutableSlice<ValueType>;
61 template <typename T = UserHeader, typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value, T>>
75 explicit
Sample() = default;
78 iox2_sample_t m_sample;
79 iox2_sample_h m_handle =
nullptr;
82template <
ServiceType S, typename Payload, typename UserHeader>
83inline
void Sample<S, Payload, UserHeader>::drop() {
84 if (m_handle !=
nullptr) {
85 iox2_sample_drop(m_handle);
91template <ServiceType S,
typename Payload,
typename UserHeader>
93 *
this = std::move(rhs);
98void iox2_sample_move(iox2_sample_t*, iox2_sample_t*, iox2_sample_h*);
102template <ServiceType S,
typename Payload,
typename UserHeader>
107 internal::iox2_sample_move(&rhs.m_sample, &m_sample, &m_handle);
108 rhs.m_handle =
nullptr;
114template <ServiceType S,
typename Payload,
typename UserHeader>
119template <ServiceType S,
typename Payload,
typename UserHeader>
120template <
typename T,
typename>
122 const void* ptr =
nullptr;
124 iox2_sample_payload(&m_handle, &ptr,
nullptr);
126 return *
static_cast<const ValueType*
>(ptr);
129template <ServiceType S,
typename Payload,
typename UserHeader>
130template <
typename T,
typename>
132 const void* ptr =
nullptr;
133 size_t number_of_elements = 0;
135 iox2_sample_payload(&m_handle, &ptr, &number_of_elements);
139 auto length = number_of_elements;
140 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
141 length = iox2_sample_payload_number_of_bytes(&m_handle);
144 return bb::ImmutableSlice<ValueType>(
static_cast<const ValueType*
>(ptr), length);
147template <ServiceType S,
typename Payload,
typename UserHeader>
148template <
typename T,
typename>
150 const void* header_ptr =
nullptr;
152 iox2_sample_user_header(&m_handle, &header_ptr);
154 return *
static_cast<const T*
>(header_ptr);
157template <ServiceType S,
typename Payload,
typename UserHeader>
159 iox2_publish_subscribe_header_h header_handle =
nullptr;
160 iox2_sample_header(&m_handle,
nullptr, &header_handle);
165template <ServiceType S,
typename Payload,
typename UserHeader>
167 return header().publisher_id();
auto header() const -> HeaderPublishSubscribe
Returns a reference to the [Header] of the [Sample].
auto payload() const -> const ValueType &
Returns a reference to the payload of the [Sample].
auto origin() const -> UniquePublisherId
Returns the [UniquePublisherId] of the [Publisher](crate::port::publisher::Publisher)
auto operator=(Sample &&rhs) noexcept -> Sample &
auto user_header() const -> const T &
Returns a reference to the user_header of the [Sample].
Sample(const Sample &)=delete
auto operator=(const Sample &) -> Sample &=delete
The receiving endpoint of a publish-subscribe communication.
The system-wide unique id of a [Publisher].