Commit 662530c 1 parent 904dcad commit 662530c Copy full SHA for 662530c
File tree 4 files changed +73
-91
lines changed
4 files changed +73
-91
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 35
35
#include " attachment_helpers.hpp"
36
36
#include " type_support_common.hpp"
37
37
#include " zenoh_utils.hpp"
38
- #include " payload.hpp"
39
38
40
39
#include " rcutils/allocator.h"
41
40
Original file line number Diff line number Diff line change @@ -96,4 +96,48 @@ std::chrono::nanoseconds::rep ZenohReply::get_received_timestamp() const
96
96
{
97
97
return received_timestamp_;
98
98
}
99
+
100
+ // /=============================================================================
101
+ Payload::Payload (const zenoh::Bytes & bytes)
102
+ {
103
+ zenoh::Bytes::SliceIterator slices = bytes.slice_iter ();
104
+ std::optional<zenoh::Slice> slice = slices.next ();
105
+ if (!slice.has_value ()) {
106
+ bytes_ = nullptr ;
107
+ } else {
108
+ if (!slices.next ().has_value ()) {
109
+ bytes_ = Contiguous {slice.value (), bytes.clone ()};
110
+ } else {
111
+ bytes_ = bytes.as_vector ();
112
+ }
113
+ }
114
+ }
115
+
116
+ const uint8_t * Payload::data ()
117
+ {
118
+ if (std::holds_alternative<Empty>(bytes_)) {
119
+ return nullptr ;
120
+ } else if (std::holds_alternative<NonContiguous>(bytes_)) {
121
+ return std::get<NonContiguous>(bytes_).data ();
122
+ } else {
123
+ return std::get<Contiguous>(bytes_).slice .data ;
124
+ }
125
+ }
126
+
127
+ size_t Payload::size ()
128
+ {
129
+ if (std::holds_alternative<Empty>(bytes_)) {
130
+ return 0 ;
131
+ } else if (std::holds_alternative<NonContiguous>(bytes_)) {
132
+ return std::get<NonContiguous>(bytes_).size ();
133
+ } else {
134
+ return std::get<Contiguous>(bytes_).slice .len ;
135
+ }
136
+ }
137
+
138
+ bool Payload::empty ()
139
+ {
140
+ return std::holds_alternative<Empty>(bytes_);
141
+ }
142
+
99
143
} // namespace rmw_zenoh_cpp
Original file line number Diff line number Diff line change 21
21
#include < chrono>
22
22
#include < functional>
23
23
#include < optional>
24
+ #include < utility>
25
+ #include < variant>
26
+ #include < vector>
24
27
25
28
#include " rmw/types.h"
26
29
@@ -80,6 +83,32 @@ class ZenohQuery final
80
83
zenoh::Query query_;
81
84
std::chrono::nanoseconds::rep received_timestamp_;
82
85
};
86
+
87
+ class Payload
88
+ {
89
+ public:
90
+ explicit Payload (const zenoh::Bytes & bytes);
91
+
92
+ ~Payload () = default ;
93
+
94
+ const uint8_t * data () const ;
95
+
96
+ size_t size () const ;
97
+
98
+ bool empty () const ;
99
+
100
+ private:
101
+ struct Contiguous
102
+ {
103
+ zenoh::Slice slice;
104
+ zenoh::Bytes bytes;
105
+ };
106
+ using NonContiguous = std::vector<uint8_t >;
107
+ using Empty = std::nullptr_t ;
108
+ // Is `std::vector<uint8_t>` in case of a non-contiguous payload
109
+ // and `zenoh::Slice` plus a `zenoh::Bytes` otherwise.
110
+ std::variant<NonContiguous, Contiguous, Empty> bytes_;
111
+ }
83
112
} // namespace rmw_zenoh_cpp
84
113
85
114
#endif // DETAIL__ZENOH_UTILS_HPP_
You can’t perform that action at this time.
0 commit comments