25#include "pw_containers/filtered_view.h"
26#include "pw_containers/vector.h"
27#include "pw_containers/wrapped_iterator.h"
28#include "pw_rpc/channel.h"
29#include "pw_rpc/internal/method_info.h"
30#include "pw_rpc/internal/packet.h"
31#include "pw_rpc/method_type.h"
34namespace internal::test {
36class FakeChannelOutput;
42 constexpr PacketFilter(internal::pwpb::PacketType packet_type_1,
43 internal::pwpb::PacketType packet_type_2,
47 : packet_type_1_(packet_type_1),
48 packet_type_2_(packet_type_2),
49 channel_id_(channel_id),
50 service_id_(service_id),
51 method_id_(method_id) {}
53 constexpr bool operator()(
const Packet& packet)
const {
54 return (packet.type() == packet_type_1_ ||
55 packet.type() == packet_type_2_) &&
56 (channel_id_ == Channel::kUnassignedChannelId ||
57 packet.channel_id() == channel_id_) &&
58 packet.service_id() == service_id_ &&
59 packet.method_id() == method_id_;
65 internal::pwpb::PacketType packet_type_1_;
66 internal::pwpb::PacketType packet_type_2_;
85 internal::test::PacketsView::iterator,
91 const ConstByteSpan& operator*()
const {
return value().payload(); }
92 const ConstByteSpan* operator->()
const {
return &value().payload(); }
97 constexpr iterator(
const internal::test::PacketsView::iterator& it)
99 internal::test::PacketsView::iterator,
107 std::advance(it, index);
112 size_t size()
const {
return view_.size(); }
114 bool empty()
const {
return begin() == end(); }
117 const ConstByteSpan& front()
const {
return *begin(); }
118 const ConstByteSpan& back()
const {
return *std::prev(end()); }
120 iterator begin()
const {
return iterator(view_.begin()); }
121 iterator end()
const {
return iterator(view_.end()); }
124 friend class internal::test::FakeChannelOutput;
127 friend class NanopbPayloadsView;
130 friend class PwpbPayloadsView;
132 template <auto kMethod>
133 using MethodInfo = internal::MethodInfo<kMethod>;
135 using PacketType = internal::pwpb::PacketType;
137 template <auto kMethod>
138 static constexpr PayloadsView For(
const Vector<internal::Packet>& packets,
139 uint32_t channel_id) {
140 constexpr auto kTypes = PacketTypesWithPayload(MethodInfo<kMethod>::kType);
141 return PayloadsView(packets,
145 MethodInfo<kMethod>::kServiceId,
146 MethodInfo<kMethod>::kMethodId);
149 constexpr PayloadsView(
const Vector<internal::Packet>& packets,
150 MethodType method_type,
154 : PayloadsView(packets,
155 std::get<0>(PacketTypesWithPayload(method_type)),
156 std::get<1>(PacketTypesWithPayload(method_type)),
161 constexpr PayloadsView(
const Vector<internal::Packet>& packets,
162 PacketType packet_type_1,
163 PacketType packet_type_2,
168 internal::test::PacketFilter(packet_type_1,
174 static constexpr std::tuple<PacketType, PacketType> PacketTypesWithPayload(
175 MethodType method_type) {
176 switch (method_type) {
177 case MethodType::kUnary:
178 return {PacketType::REQUEST, PacketType::RESPONSE};
179 case MethodType::kServerStreaming:
180 return {PacketType::REQUEST, PacketType::SERVER_STREAM};
181 case MethodType::kClientStreaming:
182 return {PacketType::CLIENT_STREAM, PacketType::RESPONSE};
183 case MethodType::kBidirectionalStreaming:
184 return {PacketType::CLIENT_STREAM, PacketType::SERVER_STREAM};
188#if defined(__GNUC__) && __GNUC__ < 9
195 internal::test::PacketsView view_;
205 internal::test::PacketsView::iterator,
211 const Status& operator*()
const {
return value().status(); }
212 const Status* operator->()
const {
return &value().status(); }
217 constexpr iterator(
const internal::test::PacketsView::iterator& it)
219 internal::test::PacketsView::iterator,
225 const Status& operator[](
size_t index)
const {
227 std::advance(it, index);
232 size_t size()
const {
return view_.size(); }
233 bool empty()
const {
return begin() == end(); }
236 const Status& front()
const {
return *begin(); }
237 const Status& back()
const {
return *std::prev(end()); }
239 iterator begin()
const {
return iterator(view_.begin()); }
240 iterator end()
const {
return iterator(view_.end()); }
243 friend class internal::test::FakeChannelOutput;
245 template <auto kMethod>
246 using MethodInfo = internal::MethodInfo<kMethod>;
248 using PacketType = internal::pwpb::PacketType;
250 constexpr StatusView(
const Vector<internal::Packet>& packets,
251 PacketType packet_type_1,
252 PacketType packet_type_2,
257 internal::test::PacketFilter(packet_type_1,
263 internal::test::PacketsView view_;
Definition: wrapped_iterator.h:34
Definition: payloads_view.h:86
Definition: payloads_view.h:81
Definition: payloads_view.h:206
Definition: payloads_view.h:201
Definition: payloads_view.h:39