1 /**
2 * Autogenerated by Thrift for src/module.thrift
3 *
4 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 * @generated @nocommit
6 */
7
8 #include "thrift/compiler/test/fixtures/sink/gen-cpp2/SinkServiceAsyncClient.h"
9
10 #include <thrift/lib/cpp2/gen/client_cpp.h>
11
12 namespace cpp2 {
13 typedef apache::thrift::ThriftPresult<false> SinkService_method_pargs;
14 typedef apache::thrift::ThriftPResultSink<
15 apache::thrift::ThriftPresult<true>,
16 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>>,
17 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>>
18 > SinkService_method_presult;
19 typedef apache::thrift::ThriftPresult<false> SinkService_methodAndReponse_pargs;
20 typedef apache::thrift::ThriftPResultSink<
21 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::InitialResponse*>>,
22 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>>,
23 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>>
24 > SinkService_methodAndReponse_presult;
25 typedef apache::thrift::ThriftPresult<false> SinkService_methodThrow_pargs;
26 typedef apache::thrift::ThriftPResultSink<
27 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<1, ::apache::thrift::type_class::structure, ::cpp2::InitialException>>,
28 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>>,
29 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>>
30 > SinkService_methodThrow_presult;
31 typedef apache::thrift::ThriftPresult<false> SinkService_methodSinkThrow_pargs;
32 typedef apache::thrift::ThriftPResultSink<
33 apache::thrift::ThriftPresult<true>,
34 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>, apache::thrift::FieldData<1, ::apache::thrift::type_class::structure, ::cpp2::SinkException1>>,
35 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>>
36 > SinkService_methodSinkThrow_presult;
37 typedef apache::thrift::ThriftPresult<false> SinkService_methodFinalThrow_pargs;
38 typedef apache::thrift::ThriftPResultSink<
39 apache::thrift::ThriftPresult<true>,
40 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>>,
41 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>, apache::thrift::FieldData<1, ::apache::thrift::type_class::structure, ::cpp2::SinkException2>>
42 > SinkService_methodFinalThrow_presult;
43 typedef apache::thrift::ThriftPresult<false> SinkService_methodBothThrow_pargs;
44 typedef apache::thrift::ThriftPResultSink<
45 apache::thrift::ThriftPresult<true>,
46 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>, apache::thrift::FieldData<1, ::apache::thrift::type_class::structure, ::cpp2::SinkException1>>,
47 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>, apache::thrift::FieldData<1, ::apache::thrift::type_class::structure, ::cpp2::SinkException2>>
48 > SinkService_methodBothThrow_presult;
49 typedef apache::thrift::ThriftPresult<false> SinkService_methodFast_pargs;
50 typedef apache::thrift::ThriftPResultSink<
51 apache::thrift::ThriftPresult<true>,
52 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::SinkPayload*>>,
53 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::FinalResponse*>>
54 > SinkService_methodFast_presult;
55
56 template <typename Protocol_, typename RpcOptions>
methodT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)57 void SinkServiceAsyncClient::methodT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
58
59 SinkService_method_pargs args;
60 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
61 auto writer = [&](Protocol_* p) { args.write(p); };
62
63 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
64 new ::apache::thrift::MethodMetadata::Data(
65 "method",
66 ::apache::thrift::FunctionQualifier::Unspecified);
67 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
68 }
69
70 template <typename Protocol_, typename RpcOptions>
methodAndReponseT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)71 void SinkServiceAsyncClient::methodAndReponseT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
72
73 SinkService_methodAndReponse_pargs args;
74 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
75 auto writer = [&](Protocol_* p) { args.write(p); };
76
77 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
78 new ::apache::thrift::MethodMetadata::Data(
79 "methodAndReponse",
80 ::apache::thrift::FunctionQualifier::Unspecified);
81 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
82 }
83
84 template <typename Protocol_, typename RpcOptions>
methodThrowT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)85 void SinkServiceAsyncClient::methodThrowT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
86
87 SinkService_methodThrow_pargs args;
88 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
89 auto writer = [&](Protocol_* p) { args.write(p); };
90
91 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
92 new ::apache::thrift::MethodMetadata::Data(
93 "methodThrow",
94 ::apache::thrift::FunctionQualifier::Unspecified);
95 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
96 }
97
98 template <typename Protocol_, typename RpcOptions>
methodSinkThrowT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)99 void SinkServiceAsyncClient::methodSinkThrowT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
100
101 SinkService_methodSinkThrow_pargs args;
102 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
103 auto writer = [&](Protocol_* p) { args.write(p); };
104
105 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
106 new ::apache::thrift::MethodMetadata::Data(
107 "methodSinkThrow",
108 ::apache::thrift::FunctionQualifier::Unspecified);
109 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
110 }
111
112 template <typename Protocol_, typename RpcOptions>
methodFinalThrowT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)113 void SinkServiceAsyncClient::methodFinalThrowT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
114
115 SinkService_methodFinalThrow_pargs args;
116 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
117 auto writer = [&](Protocol_* p) { args.write(p); };
118
119 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
120 new ::apache::thrift::MethodMetadata::Data(
121 "methodFinalThrow",
122 ::apache::thrift::FunctionQualifier::Unspecified);
123 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
124 }
125
126 template <typename Protocol_, typename RpcOptions>
methodBothThrowT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)127 void SinkServiceAsyncClient::methodBothThrowT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
128
129 SinkService_methodBothThrow_pargs args;
130 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
131 auto writer = [&](Protocol_* p) { args.write(p); };
132
133 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
134 new ::apache::thrift::MethodMetadata::Data(
135 "methodBothThrow",
136 ::apache::thrift::FunctionQualifier::Unspecified);
137 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
138 }
139
140 template <typename Protocol_, typename RpcOptions>
methodFastT(Protocol_ * prot,RpcOptions && rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback)141 void SinkServiceAsyncClient::methodFastT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
142
143 SinkService_methodFast_pargs args;
144 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
145 auto writer = [&](Protocol_* p) { args.write(p); };
146
147 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
148 new ::apache::thrift::MethodMetadata::Data(
149 "methodFast",
150 ::apache::thrift::FunctionQualifier::Unspecified);
151 apache::thrift::clientSendT<apache::thrift::RpcKind::SINK, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
152 }
153
154
155
methodImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)156 void SinkServiceAsyncClient::methodImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
157 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
158 case apache::thrift::protocol::T_BINARY_PROTOCOL:
159 {
160 apache::thrift::BinaryProtocolWriter writer;
161 if (stealRpcOptions) {
162 methodT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
163 } else {
164 methodT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
165 }
166 break;
167 }
168 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
169 {
170 apache::thrift::CompactProtocolWriter writer;
171 if (stealRpcOptions) {
172 methodT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
173 } else {
174 methodT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
175 }
176 break;
177 }
178 default:
179 {
180 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
181 }
182 }
183 }
184
methodCtx(apache::thrift::RpcOptions * rpcOptions)185 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodCtx(apache::thrift::RpcOptions* rpcOptions) {
186 auto header = std::make_shared<apache::thrift::transport::THeader>(
187 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
188 header->setProtocolId(channel_->getProtocolId());
189 if (rpcOptions) {
190 header->setHeaders(rpcOptions->releaseWriteHeaders());
191 }
192
193 auto ctx = apache::thrift::ContextStack::createWithClientContext(
194 handlers_,
195 getServiceName(),
196 "SinkService.method",
197 *header);
198
199 return {std::move(ctx), std::move(header)};
200 }
201
202
203 #if FOLLY_HAS_COROUTINES
co_method()204 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_method() {
205 ::apache::thrift::RpcOptions rpcOptions;
206 co_return co_await co_method(rpcOptions);
207 }
co_method(apache::thrift::RpcOptions & rpcOptions)208 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_method(apache::thrift::RpcOptions& rpcOptions) {
209 const folly::CancellationToken& cancelToken =
210 co_await folly::coro::co_current_cancellation_token;
211 const bool cancellable = cancelToken.canBeCancelled();
212 apache::thrift::ClientReceiveState returnState;
213 apache::thrift::ClientSyncCallback<false> callback(&returnState);
214 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
215 auto [ctx, header] = methodCtx(&rpcOptions);
216 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
217 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
218 auto wrappedCallback = apache::thrift::createSinkClientCallback(
219 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
220
221 methodImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
222
223 if (cancellable) {
224 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
225 co_await callback.co_waitUntilDone();
226 } else {
227 co_await callback.co_waitUntilDone();
228 }
229 if (returnState.isException()) {
230 co_yield folly::coro::co_error(std::move(returnState.exception()));
231 }
232 returnState.resetProtocolId(protocolId);
233 returnState.resetCtx(std::move(ctx));
234 co_return recv_method(returnState);
235 }
236 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_method(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)237 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_method(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
238 if (state.isException()) {
239 return std::move(state.exception());
240 }
241 if (!state.hasResponseBuffer()) {
242 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
243 }
244
245 using result = SinkService_method_presult;
246 using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
247 switch (state.protocolId()) {
248 case apache::thrift::protocol::T_BINARY_PROTOCOL:
249 {
250 apache::thrift::BinaryProtocolReader reader;
251 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
252 &reader, state, state.extractSink(), _return);
253 }
254 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
255 {
256 apache::thrift::CompactProtocolReader reader;
257 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
258 &reader, state, state.extractSink(), _return);
259 }
260 default:
261 {
262 }
263 }
264 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
265 }
266
recv_method(::apache::thrift::ClientReceiveState & state)267 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_method(::apache::thrift::ClientReceiveState& state) {
268 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
269 auto ew = recv_wrapped_method(_return, state);
270 if (ew) {
271 ew.throw_exception();
272 }
273 return _return;
274 }
275
recv_instance_method(::apache::thrift::ClientReceiveState & state)276 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_method(::apache::thrift::ClientReceiveState& state) {
277 return recv_method(state);
278 }
279
recv_instance_wrapped_method(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)280 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_method(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
281 return recv_wrapped_method(_return, state);
282 }
283
methodAndReponseImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)284 void SinkServiceAsyncClient::methodAndReponseImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
285 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
286 case apache::thrift::protocol::T_BINARY_PROTOCOL:
287 {
288 apache::thrift::BinaryProtocolWriter writer;
289 if (stealRpcOptions) {
290 methodAndReponseT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
291 } else {
292 methodAndReponseT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
293 }
294 break;
295 }
296 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
297 {
298 apache::thrift::CompactProtocolWriter writer;
299 if (stealRpcOptions) {
300 methodAndReponseT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
301 } else {
302 methodAndReponseT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
303 }
304 break;
305 }
306 default:
307 {
308 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
309 }
310 }
311 }
312
methodAndReponseCtx(apache::thrift::RpcOptions * rpcOptions)313 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodAndReponseCtx(apache::thrift::RpcOptions* rpcOptions) {
314 auto header = std::make_shared<apache::thrift::transport::THeader>(
315 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
316 header->setProtocolId(channel_->getProtocolId());
317 if (rpcOptions) {
318 header->setHeaders(rpcOptions->releaseWriteHeaders());
319 }
320
321 auto ctx = apache::thrift::ContextStack::createWithClientContext(
322 handlers_,
323 getServiceName(),
324 "SinkService.methodAndReponse",
325 *header);
326
327 return {std::move(ctx), std::move(header)};
328 }
329
330
331 #if FOLLY_HAS_COROUTINES
co_methodAndReponse()332 folly::coro::Task<apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodAndReponse() {
333 ::apache::thrift::RpcOptions rpcOptions;
334 co_return co_await co_methodAndReponse(rpcOptions);
335 }
co_methodAndReponse(apache::thrift::RpcOptions & rpcOptions)336 folly::coro::Task<apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodAndReponse(apache::thrift::RpcOptions& rpcOptions) {
337 const folly::CancellationToken& cancelToken =
338 co_await folly::coro::co_current_cancellation_token;
339 const bool cancellable = cancelToken.canBeCancelled();
340 apache::thrift::ClientReceiveState returnState;
341 apache::thrift::ClientSyncCallback<false> callback(&returnState);
342 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
343 auto [ctx, header] = methodAndReponseCtx(&rpcOptions);
344 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
345 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
346 auto wrappedCallback = apache::thrift::createSinkClientCallback(
347 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
348
349 methodAndReponseImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
350
351 if (cancellable) {
352 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
353 co_await callback.co_waitUntilDone();
354 } else {
355 co_await callback.co_waitUntilDone();
356 }
357 if (returnState.isException()) {
358 co_yield folly::coro::co_error(std::move(returnState.exception()));
359 }
360 returnState.resetProtocolId(protocolId);
361 returnState.resetCtx(std::move(ctx));
362 co_return recv_methodAndReponse(returnState);
363 }
364 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_methodAndReponse(apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse,::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)365 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_methodAndReponse(apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
366 if (state.isException()) {
367 return std::move(state.exception());
368 }
369 if (!state.hasResponseBuffer()) {
370 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
371 }
372
373 using result = SinkService_methodAndReponse_presult;
374 using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
375 switch (state.protocolId()) {
376 case apache::thrift::protocol::T_BINARY_PROTOCOL:
377 {
378 apache::thrift::BinaryProtocolReader reader;
379 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
380 &reader, state, state.extractSink(), _return);
381 }
382 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
383 {
384 apache::thrift::CompactProtocolReader reader;
385 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
386 &reader, state, state.extractSink(), _return);
387 }
388 default:
389 {
390 }
391 }
392 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
393 }
394
recv_methodAndReponse(::apache::thrift::ClientReceiveState & state)395 apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_methodAndReponse(::apache::thrift::ClientReceiveState& state) {
396 apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
397 auto ew = recv_wrapped_methodAndReponse(_return, state);
398 if (ew) {
399 ew.throw_exception();
400 }
401 return _return;
402 }
403
recv_instance_methodAndReponse(::apache::thrift::ClientReceiveState & state)404 apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_methodAndReponse(::apache::thrift::ClientReceiveState& state) {
405 return recv_methodAndReponse(state);
406 }
407
recv_instance_wrapped_methodAndReponse(apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse,::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)408 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_methodAndReponse(apache::thrift::ResponseAndClientSink<::cpp2::InitialResponse, ::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
409 return recv_wrapped_methodAndReponse(_return, state);
410 }
411
methodThrowImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)412 void SinkServiceAsyncClient::methodThrowImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
413 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
414 case apache::thrift::protocol::T_BINARY_PROTOCOL:
415 {
416 apache::thrift::BinaryProtocolWriter writer;
417 if (stealRpcOptions) {
418 methodThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
419 } else {
420 methodThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
421 }
422 break;
423 }
424 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
425 {
426 apache::thrift::CompactProtocolWriter writer;
427 if (stealRpcOptions) {
428 methodThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
429 } else {
430 methodThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
431 }
432 break;
433 }
434 default:
435 {
436 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
437 }
438 }
439 }
440
methodThrowCtx(apache::thrift::RpcOptions * rpcOptions)441 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodThrowCtx(apache::thrift::RpcOptions* rpcOptions) {
442 auto header = std::make_shared<apache::thrift::transport::THeader>(
443 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
444 header->setProtocolId(channel_->getProtocolId());
445 if (rpcOptions) {
446 header->setHeaders(rpcOptions->releaseWriteHeaders());
447 }
448
449 auto ctx = apache::thrift::ContextStack::createWithClientContext(
450 handlers_,
451 getServiceName(),
452 "SinkService.methodThrow",
453 *header);
454
455 return {std::move(ctx), std::move(header)};
456 }
457
458
459 #if FOLLY_HAS_COROUTINES
co_methodThrow()460 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodThrow() {
461 ::apache::thrift::RpcOptions rpcOptions;
462 co_return co_await co_methodThrow(rpcOptions);
463 }
co_methodThrow(apache::thrift::RpcOptions & rpcOptions)464 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodThrow(apache::thrift::RpcOptions& rpcOptions) {
465 const folly::CancellationToken& cancelToken =
466 co_await folly::coro::co_current_cancellation_token;
467 const bool cancellable = cancelToken.canBeCancelled();
468 apache::thrift::ClientReceiveState returnState;
469 apache::thrift::ClientSyncCallback<false> callback(&returnState);
470 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
471 auto [ctx, header] = methodThrowCtx(&rpcOptions);
472 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
473 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
474 auto wrappedCallback = apache::thrift::createSinkClientCallback(
475 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
476
477 methodThrowImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
478
479 if (cancellable) {
480 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
481 co_await callback.co_waitUntilDone();
482 } else {
483 co_await callback.co_waitUntilDone();
484 }
485 if (returnState.isException()) {
486 co_yield folly::coro::co_error(std::move(returnState.exception()));
487 }
488 returnState.resetProtocolId(protocolId);
489 returnState.resetCtx(std::move(ctx));
490 co_return recv_methodThrow(returnState);
491 }
492 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_methodThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)493 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_methodThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
494 if (state.isException()) {
495 return std::move(state.exception());
496 }
497 if (!state.hasResponseBuffer()) {
498 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
499 }
500
501 using result = SinkService_methodThrow_presult;
502 using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
503 switch (state.protocolId()) {
504 case apache::thrift::protocol::T_BINARY_PROTOCOL:
505 {
506 apache::thrift::BinaryProtocolReader reader;
507 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
508 &reader, state, state.extractSink(), _return);
509 }
510 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
511 {
512 apache::thrift::CompactProtocolReader reader;
513 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
514 &reader, state, state.extractSink(), _return);
515 }
516 default:
517 {
518 }
519 }
520 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
521 }
522
recv_methodThrow(::apache::thrift::ClientReceiveState & state)523 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_methodThrow(::apache::thrift::ClientReceiveState& state) {
524 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
525 auto ew = recv_wrapped_methodThrow(_return, state);
526 if (ew) {
527 ew.throw_exception();
528 }
529 return _return;
530 }
531
recv_instance_methodThrow(::apache::thrift::ClientReceiveState & state)532 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_methodThrow(::apache::thrift::ClientReceiveState& state) {
533 return recv_methodThrow(state);
534 }
535
recv_instance_wrapped_methodThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)536 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_methodThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
537 return recv_wrapped_methodThrow(_return, state);
538 }
539
methodSinkThrowImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)540 void SinkServiceAsyncClient::methodSinkThrowImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
541 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
542 case apache::thrift::protocol::T_BINARY_PROTOCOL:
543 {
544 apache::thrift::BinaryProtocolWriter writer;
545 if (stealRpcOptions) {
546 methodSinkThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
547 } else {
548 methodSinkThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
549 }
550 break;
551 }
552 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
553 {
554 apache::thrift::CompactProtocolWriter writer;
555 if (stealRpcOptions) {
556 methodSinkThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
557 } else {
558 methodSinkThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
559 }
560 break;
561 }
562 default:
563 {
564 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
565 }
566 }
567 }
568
methodSinkThrowCtx(apache::thrift::RpcOptions * rpcOptions)569 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodSinkThrowCtx(apache::thrift::RpcOptions* rpcOptions) {
570 auto header = std::make_shared<apache::thrift::transport::THeader>(
571 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
572 header->setProtocolId(channel_->getProtocolId());
573 if (rpcOptions) {
574 header->setHeaders(rpcOptions->releaseWriteHeaders());
575 }
576
577 auto ctx = apache::thrift::ContextStack::createWithClientContext(
578 handlers_,
579 getServiceName(),
580 "SinkService.methodSinkThrow",
581 *header);
582
583 return {std::move(ctx), std::move(header)};
584 }
585
586
587 #if FOLLY_HAS_COROUTINES
co_methodSinkThrow()588 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodSinkThrow() {
589 ::apache::thrift::RpcOptions rpcOptions;
590 co_return co_await co_methodSinkThrow(rpcOptions);
591 }
co_methodSinkThrow(apache::thrift::RpcOptions & rpcOptions)592 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodSinkThrow(apache::thrift::RpcOptions& rpcOptions) {
593 const folly::CancellationToken& cancelToken =
594 co_await folly::coro::co_current_cancellation_token;
595 const bool cancellable = cancelToken.canBeCancelled();
596 apache::thrift::ClientReceiveState returnState;
597 apache::thrift::ClientSyncCallback<false> callback(&returnState);
598 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
599 auto [ctx, header] = methodSinkThrowCtx(&rpcOptions);
600 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
601 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
602 auto wrappedCallback = apache::thrift::createSinkClientCallback(
603 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
604
605 methodSinkThrowImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
606
607 if (cancellable) {
608 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
609 co_await callback.co_waitUntilDone();
610 } else {
611 co_await callback.co_waitUntilDone();
612 }
613 if (returnState.isException()) {
614 co_yield folly::coro::co_error(std::move(returnState.exception()));
615 }
616 returnState.resetProtocolId(protocolId);
617 returnState.resetCtx(std::move(ctx));
618 co_return recv_methodSinkThrow(returnState);
619 }
620 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_methodSinkThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)621 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_methodSinkThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
622 if (state.isException()) {
623 return std::move(state.exception());
624 }
625 if (!state.hasResponseBuffer()) {
626 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
627 }
628
629 using result = SinkService_methodSinkThrow_presult;
630 struct ExMapType {
631 bool operator()(typename result::SinkPResultType& res, folly::exception_wrapper ew) {
632 if (ew.with_exception([&]( ::cpp2::SinkException1& e) {
633 res.get<1>().ref() = e;
634 res.setIsSet(1, true);
635 })) {
636 return true;
637 }
638 return false;
639 }
640 };
641 switch (state.protocolId()) {
642 case apache::thrift::protocol::T_BINARY_PROTOCOL:
643 {
644 apache::thrift::BinaryProtocolReader reader;
645 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
646 &reader, state, state.extractSink(), _return);
647 }
648 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
649 {
650 apache::thrift::CompactProtocolReader reader;
651 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
652 &reader, state, state.extractSink(), _return);
653 }
654 default:
655 {
656 }
657 }
658 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
659 }
660
recv_methodSinkThrow(::apache::thrift::ClientReceiveState & state)661 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_methodSinkThrow(::apache::thrift::ClientReceiveState& state) {
662 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
663 auto ew = recv_wrapped_methodSinkThrow(_return, state);
664 if (ew) {
665 ew.throw_exception();
666 }
667 return _return;
668 }
669
recv_instance_methodSinkThrow(::apache::thrift::ClientReceiveState & state)670 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_methodSinkThrow(::apache::thrift::ClientReceiveState& state) {
671 return recv_methodSinkThrow(state);
672 }
673
recv_instance_wrapped_methodSinkThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)674 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_methodSinkThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
675 return recv_wrapped_methodSinkThrow(_return, state);
676 }
677
methodFinalThrowImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)678 void SinkServiceAsyncClient::methodFinalThrowImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
679 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
680 case apache::thrift::protocol::T_BINARY_PROTOCOL:
681 {
682 apache::thrift::BinaryProtocolWriter writer;
683 if (stealRpcOptions) {
684 methodFinalThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
685 } else {
686 methodFinalThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
687 }
688 break;
689 }
690 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
691 {
692 apache::thrift::CompactProtocolWriter writer;
693 if (stealRpcOptions) {
694 methodFinalThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
695 } else {
696 methodFinalThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
697 }
698 break;
699 }
700 default:
701 {
702 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
703 }
704 }
705 }
706
methodFinalThrowCtx(apache::thrift::RpcOptions * rpcOptions)707 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodFinalThrowCtx(apache::thrift::RpcOptions* rpcOptions) {
708 auto header = std::make_shared<apache::thrift::transport::THeader>(
709 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
710 header->setProtocolId(channel_->getProtocolId());
711 if (rpcOptions) {
712 header->setHeaders(rpcOptions->releaseWriteHeaders());
713 }
714
715 auto ctx = apache::thrift::ContextStack::createWithClientContext(
716 handlers_,
717 getServiceName(),
718 "SinkService.methodFinalThrow",
719 *header);
720
721 return {std::move(ctx), std::move(header)};
722 }
723
724
725 #if FOLLY_HAS_COROUTINES
co_methodFinalThrow()726 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodFinalThrow() {
727 ::apache::thrift::RpcOptions rpcOptions;
728 co_return co_await co_methodFinalThrow(rpcOptions);
729 }
co_methodFinalThrow(apache::thrift::RpcOptions & rpcOptions)730 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodFinalThrow(apache::thrift::RpcOptions& rpcOptions) {
731 const folly::CancellationToken& cancelToken =
732 co_await folly::coro::co_current_cancellation_token;
733 const bool cancellable = cancelToken.canBeCancelled();
734 apache::thrift::ClientReceiveState returnState;
735 apache::thrift::ClientSyncCallback<false> callback(&returnState);
736 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
737 auto [ctx, header] = methodFinalThrowCtx(&rpcOptions);
738 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
739 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
740 auto wrappedCallback = apache::thrift::createSinkClientCallback(
741 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
742
743 methodFinalThrowImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
744
745 if (cancellable) {
746 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
747 co_await callback.co_waitUntilDone();
748 } else {
749 co_await callback.co_waitUntilDone();
750 }
751 if (returnState.isException()) {
752 co_yield folly::coro::co_error(std::move(returnState.exception()));
753 }
754 returnState.resetProtocolId(protocolId);
755 returnState.resetCtx(std::move(ctx));
756 co_return recv_methodFinalThrow(returnState);
757 }
758 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_methodFinalThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)759 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_methodFinalThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
760 if (state.isException()) {
761 return std::move(state.exception());
762 }
763 if (!state.hasResponseBuffer()) {
764 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
765 }
766
767 using result = SinkService_methodFinalThrow_presult;
768 using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
769 switch (state.protocolId()) {
770 case apache::thrift::protocol::T_BINARY_PROTOCOL:
771 {
772 apache::thrift::BinaryProtocolReader reader;
773 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
774 &reader, state, state.extractSink(), _return);
775 }
776 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
777 {
778 apache::thrift::CompactProtocolReader reader;
779 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
780 &reader, state, state.extractSink(), _return);
781 }
782 default:
783 {
784 }
785 }
786 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
787 }
788
recv_methodFinalThrow(::apache::thrift::ClientReceiveState & state)789 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_methodFinalThrow(::apache::thrift::ClientReceiveState& state) {
790 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
791 auto ew = recv_wrapped_methodFinalThrow(_return, state);
792 if (ew) {
793 ew.throw_exception();
794 }
795 return _return;
796 }
797
recv_instance_methodFinalThrow(::apache::thrift::ClientReceiveState & state)798 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_methodFinalThrow(::apache::thrift::ClientReceiveState& state) {
799 return recv_methodFinalThrow(state);
800 }
801
recv_instance_wrapped_methodFinalThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)802 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_methodFinalThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
803 return recv_wrapped_methodFinalThrow(_return, state);
804 }
805
methodBothThrowImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)806 void SinkServiceAsyncClient::methodBothThrowImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
807 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
808 case apache::thrift::protocol::T_BINARY_PROTOCOL:
809 {
810 apache::thrift::BinaryProtocolWriter writer;
811 if (stealRpcOptions) {
812 methodBothThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
813 } else {
814 methodBothThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
815 }
816 break;
817 }
818 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
819 {
820 apache::thrift::CompactProtocolWriter writer;
821 if (stealRpcOptions) {
822 methodBothThrowT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
823 } else {
824 methodBothThrowT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
825 }
826 break;
827 }
828 default:
829 {
830 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
831 }
832 }
833 }
834
methodBothThrowCtx(apache::thrift::RpcOptions * rpcOptions)835 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodBothThrowCtx(apache::thrift::RpcOptions* rpcOptions) {
836 auto header = std::make_shared<apache::thrift::transport::THeader>(
837 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
838 header->setProtocolId(channel_->getProtocolId());
839 if (rpcOptions) {
840 header->setHeaders(rpcOptions->releaseWriteHeaders());
841 }
842
843 auto ctx = apache::thrift::ContextStack::createWithClientContext(
844 handlers_,
845 getServiceName(),
846 "SinkService.methodBothThrow",
847 *header);
848
849 return {std::move(ctx), std::move(header)};
850 }
851
852
853 #if FOLLY_HAS_COROUTINES
co_methodBothThrow()854 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodBothThrow() {
855 ::apache::thrift::RpcOptions rpcOptions;
856 co_return co_await co_methodBothThrow(rpcOptions);
857 }
co_methodBothThrow(apache::thrift::RpcOptions & rpcOptions)858 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodBothThrow(apache::thrift::RpcOptions& rpcOptions) {
859 const folly::CancellationToken& cancelToken =
860 co_await folly::coro::co_current_cancellation_token;
861 const bool cancellable = cancelToken.canBeCancelled();
862 apache::thrift::ClientReceiveState returnState;
863 apache::thrift::ClientSyncCallback<false> callback(&returnState);
864 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
865 auto [ctx, header] = methodBothThrowCtx(&rpcOptions);
866 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
867 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
868 auto wrappedCallback = apache::thrift::createSinkClientCallback(
869 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
870
871 methodBothThrowImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
872
873 if (cancellable) {
874 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
875 co_await callback.co_waitUntilDone();
876 } else {
877 co_await callback.co_waitUntilDone();
878 }
879 if (returnState.isException()) {
880 co_yield folly::coro::co_error(std::move(returnState.exception()));
881 }
882 returnState.resetProtocolId(protocolId);
883 returnState.resetCtx(std::move(ctx));
884 co_return recv_methodBothThrow(returnState);
885 }
886 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_methodBothThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)887 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_methodBothThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
888 if (state.isException()) {
889 return std::move(state.exception());
890 }
891 if (!state.hasResponseBuffer()) {
892 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
893 }
894
895 using result = SinkService_methodBothThrow_presult;
896 struct ExMapType {
897 bool operator()(typename result::SinkPResultType& res, folly::exception_wrapper ew) {
898 if (ew.with_exception([&]( ::cpp2::SinkException1& e) {
899 res.get<1>().ref() = e;
900 res.setIsSet(1, true);
901 })) {
902 return true;
903 }
904 return false;
905 }
906 };
907 switch (state.protocolId()) {
908 case apache::thrift::protocol::T_BINARY_PROTOCOL:
909 {
910 apache::thrift::BinaryProtocolReader reader;
911 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
912 &reader, state, state.extractSink(), _return);
913 }
914 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
915 {
916 apache::thrift::CompactProtocolReader reader;
917 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
918 &reader, state, state.extractSink(), _return);
919 }
920 default:
921 {
922 }
923 }
924 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
925 }
926
recv_methodBothThrow(::apache::thrift::ClientReceiveState & state)927 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_methodBothThrow(::apache::thrift::ClientReceiveState& state) {
928 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
929 auto ew = recv_wrapped_methodBothThrow(_return, state);
930 if (ew) {
931 ew.throw_exception();
932 }
933 return _return;
934 }
935
recv_instance_methodBothThrow(::apache::thrift::ClientReceiveState & state)936 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_methodBothThrow(::apache::thrift::ClientReceiveState& state) {
937 return recv_methodBothThrow(state);
938 }
939
recv_instance_wrapped_methodBothThrow(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)940 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_methodBothThrow(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
941 return recv_wrapped_methodBothThrow(_return, state);
942 }
943
methodFastImpl(apache::thrift::RpcOptions & rpcOptions,std::shared_ptr<apache::thrift::transport::THeader> header,apache::thrift::ContextStack * contextStack,apache::thrift::SinkClientCallback * callback,bool stealRpcOptions)944 void SinkServiceAsyncClient::methodFastImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
945 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
946 case apache::thrift::protocol::T_BINARY_PROTOCOL:
947 {
948 apache::thrift::BinaryProtocolWriter writer;
949 if (stealRpcOptions) {
950 methodFastT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
951 } else {
952 methodFastT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
953 }
954 break;
955 }
956 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
957 {
958 apache::thrift::CompactProtocolWriter writer;
959 if (stealRpcOptions) {
960 methodFastT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
961 } else {
962 methodFastT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
963 }
964 break;
965 }
966 default:
967 {
968 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
969 }
970 }
971 }
972
methodFastCtx(apache::thrift::RpcOptions * rpcOptions)973 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> SinkServiceAsyncClient::methodFastCtx(apache::thrift::RpcOptions* rpcOptions) {
974 auto header = std::make_shared<apache::thrift::transport::THeader>(
975 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
976 header->setProtocolId(channel_->getProtocolId());
977 if (rpcOptions) {
978 header->setHeaders(rpcOptions->releaseWriteHeaders());
979 }
980
981 auto ctx = apache::thrift::ContextStack::createWithClientContext(
982 handlers_,
983 getServiceName(),
984 "SinkService.methodFast",
985 *header);
986
987 return {std::move(ctx), std::move(header)};
988 }
989
990
991 #if FOLLY_HAS_COROUTINES
co_methodFast()992 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodFast() {
993 ::apache::thrift::RpcOptions rpcOptions;
994 co_return co_await co_methodFast(rpcOptions);
995 }
co_methodFast(apache::thrift::RpcOptions & rpcOptions)996 folly::coro::Task<apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>> SinkServiceAsyncClient::co_methodFast(apache::thrift::RpcOptions& rpcOptions) {
997 const folly::CancellationToken& cancelToken =
998 co_await folly::coro::co_current_cancellation_token;
999 const bool cancellable = cancelToken.canBeCancelled();
1000 apache::thrift::ClientReceiveState returnState;
1001 apache::thrift::ClientSyncCallback<false> callback(&returnState);
1002 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
1003 auto [ctx, header] = methodFastCtx(&rpcOptions);
1004 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
1005 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
1006 auto wrappedCallback = apache::thrift::createSinkClientCallback(
1007 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
1008
1009 methodFastImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
1010
1011 if (cancellable) {
1012 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
1013 co_await callback.co_waitUntilDone();
1014 } else {
1015 co_await callback.co_waitUntilDone();
1016 }
1017 if (returnState.isException()) {
1018 co_yield folly::coro::co_error(std::move(returnState.exception()));
1019 }
1020 returnState.resetProtocolId(protocolId);
1021 returnState.resetCtx(std::move(ctx));
1022 co_return recv_methodFast(returnState);
1023 }
1024 #endif // FOLLY_HAS_COROUTINES
recv_wrapped_methodFast(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)1025 folly::exception_wrapper SinkServiceAsyncClient::recv_wrapped_methodFast(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
1026 if (state.isException()) {
1027 return std::move(state.exception());
1028 }
1029 if (!state.hasResponseBuffer()) {
1030 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
1031 }
1032
1033 using result = SinkService_methodFast_presult;
1034 using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
1035 switch (state.protocolId()) {
1036 case apache::thrift::protocol::T_BINARY_PROTOCOL:
1037 {
1038 apache::thrift::BinaryProtocolReader reader;
1039 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
1040 &reader, state, state.extractSink(), _return);
1041 }
1042 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
1043 {
1044 apache::thrift::CompactProtocolReader reader;
1045 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
1046 &reader, state, state.extractSink(), _return);
1047 }
1048 default:
1049 {
1050 }
1051 }
1052 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
1053 }
1054
recv_methodFast(::apache::thrift::ClientReceiveState & state)1055 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_methodFast(::apache::thrift::ClientReceiveState& state) {
1056 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> _return;
1057 auto ew = recv_wrapped_methodFast(_return, state);
1058 if (ew) {
1059 ew.throw_exception();
1060 }
1061 return _return;
1062 }
1063
recv_instance_methodFast(::apache::thrift::ClientReceiveState & state)1064 apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse> SinkServiceAsyncClient::recv_instance_methodFast(::apache::thrift::ClientReceiveState& state) {
1065 return recv_methodFast(state);
1066 }
1067
recv_instance_wrapped_methodFast(apache::thrift::ClientSink<::cpp2::SinkPayload,::cpp2::FinalResponse> & _return,::apache::thrift::ClientReceiveState & state)1068 folly::exception_wrapper SinkServiceAsyncClient::recv_instance_wrapped_methodFast(apache::thrift::ClientSink<::cpp2::SinkPayload, ::cpp2::FinalResponse>& _return, ::apache::thrift::ClientReceiveState& state) {
1069 return recv_wrapped_methodFast(_return, state);
1070 }
1071
1072
1073 } // cpp2
1074