Re-sync with internal repository
[hiphop-php.git] / third-party / thrift / src / thrift / compiler / test / fixtures / single_file_service / gen-cpp2 / module_clients.cpp
blob2d026ae16588faf0b51e2caead59dfa0c99ce32b
1 /**
2 * Autogenerated by Thrift for
4 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 * @generated @nocommit
6 */
8 #include "thrift/compiler/test/fixtures/single_file_service/gen-cpp2/module_clients.h"
10 #include <thrift/lib/cpp2/gen/client_cpp.h>
12 namespace cpp2 {
13 typedef apache::thrift::ThriftPresult<false> A_foo_pargs;
14 typedef apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::structure, ::cpp2::Foo*>> A_foo_presult;
15 } // cpp2
16 template <typename Protocol_, typename RpcOptions>
17 void apache::thrift::Client<::cpp2::A>::fooT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback) {
19 ::cpp2::A_foo_pargs args;
20 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
21 auto writer = [&](Protocol_* p) { args.write(p); };
23 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
24 new ::apache::thrift::MethodMetadata::Data(
25 "foo",
26 ::apache::thrift::FunctionQualifier::Unspecified);
27 apache::thrift::clientSendT<apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
32 apache::thrift::Client<::cpp2::A>::I apache::thrift::Client<::cpp2::A>::createI() {
33 return I(channel_, "I");
35 void apache::thrift::Client<::cpp2::A>::foo(std::unique_ptr<apache::thrift::RequestCallback> callback) {
36 ::apache::thrift::RpcOptions rpcOptions;
37 foo(rpcOptions, std::move(callback));
40 void apache::thrift::Client<::cpp2::A>::foo(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback) {
41 auto [ctx, header] = fooCtx(&rpcOptions);
42 apache::thrift::RequestCallback::Context callbackContext;
43 callbackContext.protocolId =
44 apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
45 auto* contextStack = ctx.get();
46 if (callback) {
47 callbackContext.ctx = std::move(ctx);
49 auto wrappedCallback = apache::thrift::toRequestClientCallbackPtr(std::move(callback), std::move(callbackContext));
50 fooImpl(rpcOptions, std::move(header), contextStack, std::move(wrappedCallback));
53 void apache::thrift::Client<::cpp2::A>::fooImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, bool stealRpcOptions) {
54 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
55 case apache::thrift::protocol::T_BINARY_PROTOCOL:
57 apache::thrift::BinaryProtocolWriter writer;
58 if (stealRpcOptions) {
59 fooT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
60 } else {
61 fooT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
63 break;
65 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
67 apache::thrift::CompactProtocolWriter writer;
68 if (stealRpcOptions) {
69 fooT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
70 } else {
71 fooT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
73 break;
75 default:
77 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
82 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> apache::thrift::Client<::cpp2::A>::fooCtx(apache::thrift::RpcOptions* rpcOptions) {
83 auto header = std::make_shared<apache::thrift::transport::THeader>(
84 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
85 header->setProtocolId(channel_->getProtocolId());
86 if (rpcOptions) {
87 header->setHeaders(rpcOptions->releaseWriteHeaders());
90 auto ctx = apache::thrift::ContextStack::createWithClientContext(
91 handlers_,
92 getServiceName(),
93 "A.foo",
94 *header);
96 return {std::move(ctx), std::move(header)};
99 void apache::thrift::Client<::cpp2::A>::sync_foo(::cpp2::Foo& _return) {
100 ::apache::thrift::RpcOptions rpcOptions;
101 sync_foo(rpcOptions, _return);
104 void apache::thrift::Client<::cpp2::A>::sync_foo(apache::thrift::RpcOptions& rpcOptions, ::cpp2::Foo& _return) {
105 apache::thrift::ClientReceiveState returnState;
106 apache::thrift::ClientSyncCallback<false> callback(&returnState);
107 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
108 auto evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
109 auto ctxAndHeader = fooCtx(&rpcOptions);
110 auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
111 callback.waitUntilDone(
112 evb,
113 [&] {
114 fooImpl(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
117 if (returnState.isException()) {
118 returnState.exception().throw_exception();
120 returnState.resetProtocolId(protocolId);
121 returnState.resetCtx(std::move(ctxAndHeader.first));
122 SCOPE_EXIT {
123 if (returnState.header() && !returnState.header()->getHeaders().empty()) {
124 rpcOptions.setReadHeaders(returnState.header()->releaseHeaders());
127 return folly::fibers::runInMainContext([&] {
128 recv_foo(_return, returnState);
133 folly::Future<::cpp2::Foo> apache::thrift::Client<::cpp2::A>::future_foo() {
134 ::apache::thrift::RpcOptions rpcOptions;
135 return future_foo(rpcOptions);
138 folly::SemiFuture<::cpp2::Foo> apache::thrift::Client<::cpp2::A>::semifuture_foo() {
139 ::apache::thrift::RpcOptions rpcOptions;
140 return semifuture_foo(rpcOptions);
143 folly::Future<::cpp2::Foo> apache::thrift::Client<::cpp2::A>::future_foo(apache::thrift::RpcOptions& rpcOptions) {
144 folly::Promise<::cpp2::Foo> promise;
145 auto future = promise.getFuture();
146 auto callback = std::make_unique<apache::thrift::FutureCallback<::cpp2::Foo>>(std::move(promise), recv_wrapped_foo, channel_);
147 foo(rpcOptions, std::move(callback));
148 return future;
151 folly::SemiFuture<::cpp2::Foo> apache::thrift::Client<::cpp2::A>::semifuture_foo(apache::thrift::RpcOptions& rpcOptions) {
152 auto callbackAndFuture = makeSemiFutureCallback(recv_wrapped_foo, channel_);
153 auto callback = std::move(callbackAndFuture.first);
154 foo(rpcOptions, std::move(callback));
155 return std::move(callbackAndFuture.second);
158 folly::Future<std::pair<::cpp2::Foo, std::unique_ptr<apache::thrift::transport::THeader>>> apache::thrift::Client<::cpp2::A>::header_future_foo(apache::thrift::RpcOptions& rpcOptions) {
159 folly::Promise<std::pair<::cpp2::Foo, std::unique_ptr<apache::thrift::transport::THeader>>> promise;
160 auto future = promise.getFuture();
161 auto callback = std::make_unique<apache::thrift::HeaderFutureCallback<::cpp2::Foo>>(std::move(promise), recv_wrapped_foo, channel_);
162 foo(rpcOptions, std::move(callback));
163 return future;
166 folly::SemiFuture<std::pair<::cpp2::Foo, std::unique_ptr<apache::thrift::transport::THeader>>> apache::thrift::Client<::cpp2::A>::header_semifuture_foo(apache::thrift::RpcOptions& rpcOptions) {
167 auto callbackAndFuture = makeHeaderSemiFutureCallback(recv_wrapped_foo, channel_);
168 auto callback = std::move(callbackAndFuture.first);
169 foo(rpcOptions, std::move(callback));
170 return std::move(callbackAndFuture.second);
173 void apache::thrift::Client<::cpp2::A>::foo(folly::Function<void (::apache::thrift::ClientReceiveState&&)> callback) {
174 foo(std::make_unique<apache::thrift::FunctionReplyCallback>(std::move(callback)));
177 #if FOLLY_HAS_COROUTINES
178 #endif // FOLLY_HAS_COROUTINES
179 folly::exception_wrapper apache::thrift::Client<::cpp2::A>::recv_wrapped_foo(::cpp2::Foo& _return, ::apache::thrift::ClientReceiveState& state) {
180 if (state.isException()) {
181 return std::move(state.exception());
183 if (!state.hasResponseBuffer()) {
184 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
187 using result = ::cpp2::A_foo_presult;
188 switch (state.protocolId()) {
189 case apache::thrift::protocol::T_BINARY_PROTOCOL:
191 apache::thrift::BinaryProtocolReader reader;
192 return apache::thrift::detail::ac::recv_wrapped<result>(
193 &reader, state, _return);
195 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
197 apache::thrift::CompactProtocolReader reader;
198 return apache::thrift::detail::ac::recv_wrapped<result>(
199 &reader, state, _return);
201 default:
205 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
208 void apache::thrift::Client<::cpp2::A>::recv_foo(::cpp2::Foo& _return, ::apache::thrift::ClientReceiveState& state) {
209 auto ew = recv_wrapped_foo(_return, state);
210 if (ew) {
211 ew.throw_exception();
215 void apache::thrift::Client<::cpp2::A>::recv_instance_foo(::cpp2::Foo& _return, ::apache::thrift::ClientReceiveState& state) {
216 return recv_foo(_return, state);
219 folly::exception_wrapper apache::thrift::Client<::cpp2::A>::recv_instance_wrapped_foo(::cpp2::Foo& _return, ::apache::thrift::ClientReceiveState& state) {
220 return recv_wrapped_foo(_return, state);
225 namespace cpp2 {
226 typedef apache::thrift::ThriftPresult<false> A_I_interact_pargs;
227 typedef apache::thrift::ThriftPresult<true> A_I_interact_presult;
228 } // cpp2
229 template <typename Protocol_, typename RpcOptions>
230 void apache::thrift::Client<::cpp2::A>::I::interactT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback) {
231 apache::thrift::RpcOptions rpcOpts(std::forward<RpcOptions>(rpcOptions));
232 setInteraction(rpcOpts);
234 ::cpp2::A_I_interact_pargs args;
235 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
236 auto writer = [&](Protocol_* p) { args.write(p); };
238 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
239 new ::apache::thrift::MethodMetadata::Data(
240 "I.interact",
241 ::apache::thrift::FunctionQualifier::Unspecified,
242 ::apache::thrift::InteractionMethodPosition::Member,
243 "I");
244 apache::thrift::clientSendT<apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE, Protocol_>(prot, std::move(rpcOpts), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
249 void apache::thrift::Client<::cpp2::A>::I::interact(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback) {
250 auto [ctx, header] = interactCtx(&rpcOptions);
251 apache::thrift::RequestCallback::Context callbackContext;
252 callbackContext.protocolId =
253 apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
254 auto* contextStack = ctx.get();
255 if (callback) {
256 callbackContext.ctx = std::move(ctx);
258 auto wrappedCallback = apache::thrift::toRequestClientCallbackPtr(std::move(callback), std::move(callbackContext));
259 interactImpl(rpcOptions, std::move(header), contextStack, std::move(wrappedCallback));
262 void apache::thrift::Client<::cpp2::A>::I::interactImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, bool stealRpcOptions) {
263 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
264 case apache::thrift::protocol::T_BINARY_PROTOCOL:
266 apache::thrift::BinaryProtocolWriter writer;
267 if (stealRpcOptions) {
268 interactT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
269 } else {
270 interactT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
272 break;
274 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
276 apache::thrift::CompactProtocolWriter writer;
277 if (stealRpcOptions) {
278 interactT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
279 } else {
280 interactT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
282 break;
284 default:
286 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
291 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> apache::thrift::Client<::cpp2::A>::I::interactCtx(apache::thrift::RpcOptions* rpcOptions) {
292 auto header = std::make_shared<apache::thrift::transport::THeader>(
293 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
294 header->setProtocolId(channel_->getProtocolId());
295 if (rpcOptions) {
296 header->setHeaders(rpcOptions->releaseWriteHeaders());
299 auto ctx = apache::thrift::ContextStack::createWithClientContext(
300 handlers_,
301 getServiceName(),
302 "A.I.interact",
303 *header);
305 return {std::move(ctx), std::move(header)};
307 void apache::thrift::Client<::cpp2::A>::I::sync_interact() {
308 ::apache::thrift::RpcOptions rpcOptions;
309 sync_interact(rpcOptions);
312 void apache::thrift::Client<::cpp2::A>::I::sync_interact(apache::thrift::RpcOptions& rpcOptions) {
313 apache::thrift::ClientReceiveState returnState;
314 apache::thrift::ClientSyncCallback<false> callback(&returnState);
315 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
316 auto evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
317 auto ctxAndHeader = interactCtx(&rpcOptions);
318 auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
319 callback.waitUntilDone(
320 evb,
321 [&] {
322 interactImpl(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
325 if (returnState.isException()) {
326 returnState.exception().throw_exception();
328 returnState.resetProtocolId(protocolId);
329 returnState.resetCtx(std::move(ctxAndHeader.first));
330 SCOPE_EXIT {
331 if (returnState.header() && !returnState.header()->getHeaders().empty()) {
332 rpcOptions.setReadHeaders(returnState.header()->releaseHeaders());
335 return folly::fibers::runInMainContext([&] {
336 recv_interact(returnState);
341 folly::SemiFuture<folly::Unit> apache::thrift::Client<::cpp2::A>::I::semifuture_interact() {
342 ::apache::thrift::RpcOptions rpcOptions;
343 return semifuture_interact(rpcOptions);
346 folly::SemiFuture<folly::Unit> apache::thrift::Client<::cpp2::A>::I::semifuture_interact(apache::thrift::RpcOptions& rpcOptions) {
347 auto callbackAndFuture = makeSemiFutureCallback(recv_wrapped_interact, channel_);
348 auto callback = std::move(callbackAndFuture.first);
349 interact(rpcOptions, std::move(callback));
350 return std::move(callbackAndFuture.second);
354 #if FOLLY_HAS_COROUTINES
355 #endif // FOLLY_HAS_COROUTINES
356 folly::exception_wrapper apache::thrift::Client<::cpp2::A>::I::recv_wrapped_interact(::apache::thrift::ClientReceiveState& state) {
357 if (state.isException()) {
358 return std::move(state.exception());
360 if (!state.hasResponseBuffer()) {
361 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
364 using result = ::cpp2::A_I_interact_presult;
365 switch (state.protocolId()) {
366 case apache::thrift::protocol::T_BINARY_PROTOCOL:
368 apache::thrift::BinaryProtocolReader reader;
369 return apache::thrift::detail::ac::recv_wrapped<result>(
370 &reader, state);
372 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
374 apache::thrift::CompactProtocolReader reader;
375 return apache::thrift::detail::ac::recv_wrapped<result>(
376 &reader, state);
378 default:
382 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
384 void apache::thrift::Client<::cpp2::A>::I::recv_interact(::apache::thrift::ClientReceiveState& state) {
385 auto ew = recv_wrapped_interact(state);
386 if (ew) {
387 ew.throw_exception();
393 namespace cpp2 {
394 typedef apache::thrift::ThriftPresult<false, apache::thrift::FieldData<1, ::apache::thrift::type_class::structure, ::cpp2::Foo*>> B_bar_pargs;
395 typedef apache::thrift::ThriftPresult<true> B_bar_presult;
396 typedef apache::thrift::ThriftPresult<false> B_stream_stuff_pargs;
397 typedef apache::thrift::ThriftPResultStream<
398 apache::thrift::ThriftPresult<true>,
399 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::integral, ::std::int32_t*>>
400 > B_stream_stuff_presult;
401 typedef apache::thrift::ThriftPresult<false> B_sink_stuff_pargs;
402 typedef apache::thrift::ThriftPResultSink<
403 apache::thrift::ThriftPresult<true>,
404 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::integral, ::std::int32_t*>>,
405 apache::thrift::ThriftPresult<true, apache::thrift::FieldData<0, ::apache::thrift::type_class::integral, ::std::int32_t*>>
406 > B_sink_stuff_presult;
407 } // cpp2
408 template <typename Protocol_, typename RpcOptions>
409 void apache::thrift::Client<::cpp2::B>::barT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, const ::cpp2::Foo& p_foo) {
411 ::cpp2::B_bar_pargs args;
412 args.get<0>().value = const_cast<::cpp2::Foo*>(&p_foo);
413 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
414 auto writer = [&](Protocol_* p) { args.write(p); };
416 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
417 new ::apache::thrift::MethodMetadata::Data(
418 "bar",
419 ::apache::thrift::FunctionQualifier::Unspecified);
420 apache::thrift::clientSendT<apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
423 template <typename Protocol_, typename RpcOptions>
424 void apache::thrift::Client<::cpp2::B>::stream_stuffT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::StreamClientCallback* callback) {
426 ::cpp2::B_stream_stuff_pargs args;
427 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
428 auto writer = [&](Protocol_* p) { args.write(p); };
430 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
431 new ::apache::thrift::MethodMetadata::Data(
432 "stream_stuff",
433 ::apache::thrift::FunctionQualifier::Unspecified);
434 apache::thrift::clientSendT<apache::thrift::RpcKind::SINGLE_REQUEST_STREAMING_RESPONSE, Protocol_>(prot, std::forward<RpcOptions>(rpcOptions), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
437 template <typename Protocol_, typename RpcOptions>
438 void apache::thrift::Client<::cpp2::B>::sink_stuffT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback) {
440 ::cpp2::B_sink_stuff_pargs args;
441 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
442 auto writer = [&](Protocol_* p) { args.write(p); };
444 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
445 new ::apache::thrift::MethodMetadata::Data(
446 "sink_stuff",
447 ::apache::thrift::FunctionQualifier::Unspecified);
448 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);
453 void apache::thrift::Client<::cpp2::B>::bar(std::unique_ptr<apache::thrift::RequestCallback> callback, const ::cpp2::Foo& p_foo) {
454 ::apache::thrift::RpcOptions rpcOptions;
455 bar(rpcOptions, std::move(callback), p_foo);
458 void apache::thrift::Client<::cpp2::B>::bar(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback, const ::cpp2::Foo& p_foo) {
459 auto [ctx, header] = barCtx(&rpcOptions);
460 apache::thrift::RequestCallback::Context callbackContext;
461 callbackContext.protocolId =
462 apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
463 auto* contextStack = ctx.get();
464 if (callback) {
465 callbackContext.ctx = std::move(ctx);
467 auto wrappedCallback = apache::thrift::toRequestClientCallbackPtr(std::move(callback), std::move(callbackContext));
468 barImpl(rpcOptions, std::move(header), contextStack, std::move(wrappedCallback), p_foo);
471 void apache::thrift::Client<::cpp2::B>::barImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, const ::cpp2::Foo& p_foo, bool stealRpcOptions) {
472 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
473 case apache::thrift::protocol::T_BINARY_PROTOCOL:
475 apache::thrift::BinaryProtocolWriter writer;
476 if (stealRpcOptions) {
477 barT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback), p_foo);
478 } else {
479 barT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback), p_foo);
481 break;
483 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
485 apache::thrift::CompactProtocolWriter writer;
486 if (stealRpcOptions) {
487 barT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback), p_foo);
488 } else {
489 barT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback), p_foo);
491 break;
493 default:
495 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
500 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> apache::thrift::Client<::cpp2::B>::barCtx(apache::thrift::RpcOptions* rpcOptions) {
501 auto header = std::make_shared<apache::thrift::transport::THeader>(
502 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
503 header->setProtocolId(channel_->getProtocolId());
504 if (rpcOptions) {
505 header->setHeaders(rpcOptions->releaseWriteHeaders());
508 auto ctx = apache::thrift::ContextStack::createWithClientContext(
509 handlers_,
510 getServiceName(),
511 "B.bar",
512 *header);
514 return {std::move(ctx), std::move(header)};
517 void apache::thrift::Client<::cpp2::B>::sync_bar(const ::cpp2::Foo& p_foo) {
518 ::apache::thrift::RpcOptions rpcOptions;
519 sync_bar(rpcOptions, p_foo);
522 void apache::thrift::Client<::cpp2::B>::sync_bar(apache::thrift::RpcOptions& rpcOptions, const ::cpp2::Foo& p_foo) {
523 apache::thrift::ClientReceiveState returnState;
524 apache::thrift::ClientSyncCallback<false> callback(&returnState);
525 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
526 auto evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
527 auto ctxAndHeader = barCtx(&rpcOptions);
528 auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
529 callback.waitUntilDone(
530 evb,
531 [&] {
532 barImpl(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback), p_foo);
535 if (returnState.isException()) {
536 returnState.exception().throw_exception();
538 returnState.resetProtocolId(protocolId);
539 returnState.resetCtx(std::move(ctxAndHeader.first));
540 SCOPE_EXIT {
541 if (returnState.header() && !returnState.header()->getHeaders().empty()) {
542 rpcOptions.setReadHeaders(returnState.header()->releaseHeaders());
545 return folly::fibers::runInMainContext([&] {
546 recv_bar(returnState);
551 folly::Future<folly::Unit> apache::thrift::Client<::cpp2::B>::future_bar(const ::cpp2::Foo& p_foo) {
552 ::apache::thrift::RpcOptions rpcOptions;
553 return future_bar(rpcOptions, p_foo);
556 folly::SemiFuture<folly::Unit> apache::thrift::Client<::cpp2::B>::semifuture_bar(const ::cpp2::Foo& p_foo) {
557 ::apache::thrift::RpcOptions rpcOptions;
558 return semifuture_bar(rpcOptions, p_foo);
561 folly::Future<folly::Unit> apache::thrift::Client<::cpp2::B>::future_bar(apache::thrift::RpcOptions& rpcOptions, const ::cpp2::Foo& p_foo) {
562 folly::Promise<folly::Unit> promise;
563 auto future = promise.getFuture();
564 auto callback = std::make_unique<apache::thrift::FutureCallback<folly::Unit>>(std::move(promise), recv_wrapped_bar, channel_);
565 bar(rpcOptions, std::move(callback), p_foo);
566 return future;
569 folly::SemiFuture<folly::Unit> apache::thrift::Client<::cpp2::B>::semifuture_bar(apache::thrift::RpcOptions& rpcOptions, const ::cpp2::Foo& p_foo) {
570 auto callbackAndFuture = makeSemiFutureCallback(recv_wrapped_bar, channel_);
571 auto callback = std::move(callbackAndFuture.first);
572 bar(rpcOptions, std::move(callback), p_foo);
573 return std::move(callbackAndFuture.second);
576 folly::Future<std::pair<folly::Unit, std::unique_ptr<apache::thrift::transport::THeader>>> apache::thrift::Client<::cpp2::B>::header_future_bar(apache::thrift::RpcOptions& rpcOptions, const ::cpp2::Foo& p_foo) {
577 folly::Promise<std::pair<folly::Unit, std::unique_ptr<apache::thrift::transport::THeader>>> promise;
578 auto future = promise.getFuture();
579 auto callback = std::make_unique<apache::thrift::HeaderFutureCallback<folly::Unit>>(std::move(promise), recv_wrapped_bar, channel_);
580 bar(rpcOptions, std::move(callback), p_foo);
581 return future;
584 folly::SemiFuture<std::pair<folly::Unit, std::unique_ptr<apache::thrift::transport::THeader>>> apache::thrift::Client<::cpp2::B>::header_semifuture_bar(apache::thrift::RpcOptions& rpcOptions, const ::cpp2::Foo& p_foo) {
585 auto callbackAndFuture = makeHeaderSemiFutureCallback(recv_wrapped_bar, channel_);
586 auto callback = std::move(callbackAndFuture.first);
587 bar(rpcOptions, std::move(callback), p_foo);
588 return std::move(callbackAndFuture.second);
591 void apache::thrift::Client<::cpp2::B>::bar(folly::Function<void (::apache::thrift::ClientReceiveState&&)> callback, const ::cpp2::Foo& p_foo) {
592 bar(std::make_unique<apache::thrift::FunctionReplyCallback>(std::move(callback)), p_foo);
595 #if FOLLY_HAS_COROUTINES
596 #endif // FOLLY_HAS_COROUTINES
597 folly::exception_wrapper apache::thrift::Client<::cpp2::B>::recv_wrapped_bar(::apache::thrift::ClientReceiveState& state) {
598 if (state.isException()) {
599 return std::move(state.exception());
601 if (!state.hasResponseBuffer()) {
602 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
605 using result = ::cpp2::B_bar_presult;
606 switch (state.protocolId()) {
607 case apache::thrift::protocol::T_BINARY_PROTOCOL:
609 apache::thrift::BinaryProtocolReader reader;
610 return apache::thrift::detail::ac::recv_wrapped<result>(
611 &reader, state);
613 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
615 apache::thrift::CompactProtocolReader reader;
616 return apache::thrift::detail::ac::recv_wrapped<result>(
617 &reader, state);
619 default:
623 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
626 void apache::thrift::Client<::cpp2::B>::recv_bar(::apache::thrift::ClientReceiveState& state) {
627 auto ew = recv_wrapped_bar(state);
628 if (ew) {
629 ew.throw_exception();
633 void apache::thrift::Client<::cpp2::B>::recv_instance_bar(::apache::thrift::ClientReceiveState& state) {
634 recv_bar(state);
637 folly::exception_wrapper apache::thrift::Client<::cpp2::B>::recv_instance_wrapped_bar(::apache::thrift::ClientReceiveState& state) {
638 return recv_wrapped_bar(state);
641 void apache::thrift::Client<::cpp2::B>::stream_stuff(std::unique_ptr<apache::thrift::RequestCallback> callback) {
642 ::apache::thrift::RpcOptions rpcOptions;
643 stream_stuff(rpcOptions, std::move(callback));
646 void apache::thrift::Client<::cpp2::B>::stream_stuff(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback) {
647 auto [ctx, header] = stream_stuffCtx(&rpcOptions);
648 apache::thrift::RequestCallback::Context callbackContext;
649 callbackContext.protocolId =
650 apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
651 auto* contextStack = ctx.get();
652 if (callback) {
653 callbackContext.ctx = std::move(ctx);
655 auto wrappedCallback = apache::thrift::createStreamClientCallback(
656 apache::thrift::toRequestClientCallbackPtr(std::move(callback), std::move(callbackContext)),
657 rpcOptions.getBufferOptions());
658 stream_stuffImpl(rpcOptions, std::move(header), contextStack, std::move(wrappedCallback));
661 void apache::thrift::Client<::cpp2::B>::stream_stuffImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::StreamClientCallback* callback, bool stealRpcOptions) {
662 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
663 case apache::thrift::protocol::T_BINARY_PROTOCOL:
665 apache::thrift::BinaryProtocolWriter writer;
666 if (stealRpcOptions) {
667 stream_stuffT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
668 } else {
669 stream_stuffT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
671 break;
673 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
675 apache::thrift::CompactProtocolWriter writer;
676 if (stealRpcOptions) {
677 stream_stuffT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
678 } else {
679 stream_stuffT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
681 break;
683 default:
685 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
690 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> apache::thrift::Client<::cpp2::B>::stream_stuffCtx(apache::thrift::RpcOptions* rpcOptions) {
691 auto header = std::make_shared<apache::thrift::transport::THeader>(
692 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
693 header->setProtocolId(channel_->getProtocolId());
694 if (rpcOptions) {
695 header->setHeaders(rpcOptions->releaseWriteHeaders());
698 auto ctx = apache::thrift::ContextStack::createWithClientContext(
699 handlers_,
700 getServiceName(),
701 "B.stream_stuff",
702 *header);
704 return {std::move(ctx), std::move(header)};
707 apache::thrift::ClientBufferedStream<::std::int32_t> apache::thrift::Client<::cpp2::B>::sync_stream_stuff() {
708 ::apache::thrift::RpcOptions rpcOptions;
709 return sync_stream_stuff(rpcOptions);
712 apache::thrift::ClientBufferedStream<::std::int32_t> apache::thrift::Client<::cpp2::B>::sync_stream_stuff(apache::thrift::RpcOptions& rpcOptions) {
713 apache::thrift::ClientReceiveState returnState;
714 apache::thrift::ClientSyncCallback<false> callback(&returnState);
715 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
716 auto evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
717 auto ctxAndHeader = stream_stuffCtx(&rpcOptions);
718 auto wrappedCallback = apache::thrift::createStreamClientCallback(
719 apache::thrift::RequestClientCallback::Ptr(&callback),
720 rpcOptions.getBufferOptions());
721 callback.waitUntilDone(
722 evb,
723 [&] {
724 stream_stuffImpl(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
727 if (returnState.isException()) {
728 returnState.exception().throw_exception();
730 returnState.resetProtocolId(protocolId);
731 returnState.resetCtx(std::move(ctxAndHeader.first));
732 SCOPE_EXIT {
733 if (returnState.header() && !returnState.header()->getHeaders().empty()) {
734 rpcOptions.setReadHeaders(returnState.header()->releaseHeaders());
737 return folly::fibers::runInMainContext([&] {
738 return recv_stream_stuff(returnState);
744 folly::SemiFuture<apache::thrift::ClientBufferedStream<::std::int32_t>> apache::thrift::Client<::cpp2::B>::semifuture_stream_stuff() {
745 ::apache::thrift::RpcOptions rpcOptions;
746 return semifuture_stream_stuff(rpcOptions);
750 folly::SemiFuture<apache::thrift::ClientBufferedStream<::std::int32_t>> apache::thrift::Client<::cpp2::B>::semifuture_stream_stuff(apache::thrift::RpcOptions& rpcOptions) {
751 auto callbackAndFuture = makeSemiFutureCallback(recv_wrapped_stream_stuff, channel_);
752 auto callback = std::move(callbackAndFuture.first);
753 stream_stuff(rpcOptions, std::move(callback));
754 return std::move(callbackAndFuture.second);
758 folly::SemiFuture<std::pair<apache::thrift::ClientBufferedStream<::std::int32_t>, std::unique_ptr<apache::thrift::transport::THeader>>> apache::thrift::Client<::cpp2::B>::header_semifuture_stream_stuff(apache::thrift::RpcOptions& rpcOptions) {
759 auto callbackAndFuture = makeHeaderSemiFutureCallback(recv_wrapped_stream_stuff, channel_);
760 auto callback = std::move(callbackAndFuture.first);
761 stream_stuff(rpcOptions, std::move(callback));
762 return std::move(callbackAndFuture.second);
766 #if FOLLY_HAS_COROUTINES
767 #endif // FOLLY_HAS_COROUTINES
768 folly::exception_wrapper apache::thrift::Client<::cpp2::B>::recv_wrapped_stream_stuff(apache::thrift::ClientBufferedStream<::std::int32_t>& _return, ::apache::thrift::ClientReceiveState& state) {
769 if (state.isException()) {
770 return std::move(state.exception());
772 if (!state.hasResponseBuffer()) {
773 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
776 using result = ::cpp2::B_stream_stuff_presult;
777 switch (state.protocolId()) {
778 case apache::thrift::protocol::T_BINARY_PROTOCOL:
780 apache::thrift::BinaryProtocolReader reader;
781 return apache::thrift::detail::ac::recv_wrapped<result>(
782 &reader, state, _return);
784 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
786 apache::thrift::CompactProtocolReader reader;
787 return apache::thrift::detail::ac::recv_wrapped<result>(
788 &reader, state, _return);
790 default:
794 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
797 apache::thrift::ClientBufferedStream<::std::int32_t> apache::thrift::Client<::cpp2::B>::recv_stream_stuff(::apache::thrift::ClientReceiveState& state) {
798 apache::thrift::ClientBufferedStream<::std::int32_t> _return;
799 auto ew = recv_wrapped_stream_stuff(_return, state);
800 if (ew) {
801 ew.throw_exception();
803 return _return;
806 apache::thrift::ClientBufferedStream<::std::int32_t> apache::thrift::Client<::cpp2::B>::recv_instance_stream_stuff(::apache::thrift::ClientReceiveState& state) {
807 return recv_stream_stuff(state);
810 folly::exception_wrapper apache::thrift::Client<::cpp2::B>::recv_instance_wrapped_stream_stuff(apache::thrift::ClientBufferedStream<::std::int32_t>& _return, ::apache::thrift::ClientReceiveState& state) {
811 return recv_wrapped_stream_stuff(_return, state);
814 void apache::thrift::Client<::cpp2::B>::sink_stuffImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::SinkClientCallback* callback, bool stealRpcOptions) {
815 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
816 case apache::thrift::protocol::T_BINARY_PROTOCOL:
818 apache::thrift::BinaryProtocolWriter writer;
819 if (stealRpcOptions) {
820 sink_stuffT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
821 } else {
822 sink_stuffT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
824 break;
826 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
828 apache::thrift::CompactProtocolWriter writer;
829 if (stealRpcOptions) {
830 sink_stuffT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
831 } else {
832 sink_stuffT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
834 break;
836 default:
838 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
843 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> apache::thrift::Client<::cpp2::B>::sink_stuffCtx(apache::thrift::RpcOptions* rpcOptions) {
844 auto header = std::make_shared<apache::thrift::transport::THeader>(
845 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
846 header->setProtocolId(channel_->getProtocolId());
847 if (rpcOptions) {
848 header->setHeaders(rpcOptions->releaseWriteHeaders());
851 auto ctx = apache::thrift::ContextStack::createWithClientContext(
852 handlers_,
853 getServiceName(),
854 "B.sink_stuff",
855 *header);
857 return {std::move(ctx), std::move(header)};
861 #if FOLLY_HAS_COROUTINES
862 folly::coro::Task<apache::thrift::ClientSink<::std::int32_t, ::std::int32_t>> apache::thrift::Client<::cpp2::B>::co_sink_stuff() {
863 ::apache::thrift::RpcOptions rpcOptions;
864 co_return co_await co_sink_stuff(rpcOptions);
866 folly::coro::Task<apache::thrift::ClientSink<::std::int32_t, ::std::int32_t>> apache::thrift::Client<::cpp2::B>::co_sink_stuff(apache::thrift::RpcOptions& rpcOptions) {
867 const folly::CancellationToken& cancelToken =
868 co_await folly::coro::co_current_cancellation_token;
869 const bool cancellable = cancelToken.canBeCancelled();
870 apache::thrift::ClientReceiveState returnState;
871 apache::thrift::ClientCoroCallback<false> callback(&returnState, co_await folly::coro::co_current_executor);
872 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
873 auto [ctx, header] = sink_stuffCtx(&rpcOptions);
874 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>;
875 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr;
876 auto wrappedCallback = apache::thrift::createSinkClientCallback(
877 apache::thrift::RequestClientCallback::Ptr(apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback)));
879 sink_stuffImpl(rpcOptions, std::move(header), ctx.get(), wrappedCallback);
881 if (cancellable) {
882 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); });
883 co_await callback.co_waitUntilDone();
884 } else {
885 co_await callback.co_waitUntilDone();
887 if (returnState.isException()) {
888 co_yield folly::coro::co_error(std::move(returnState.exception()));
890 returnState.resetProtocolId(protocolId);
891 returnState.resetCtx(std::move(ctx));
892 co_return recv_sink_stuff(returnState);
894 #endif // FOLLY_HAS_COROUTINES
895 folly::exception_wrapper apache::thrift::Client<::cpp2::B>::recv_wrapped_sink_stuff(apache::thrift::ClientSink<::std::int32_t, ::std::int32_t>& _return, ::apache::thrift::ClientReceiveState& state) {
896 if (state.isException()) {
897 return std::move(state.exception());
899 if (!state.hasResponseBuffer()) {
900 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
903 using result = ::cpp2::B_sink_stuff_presult;
904 using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
905 switch (state.protocolId()) {
906 case apache::thrift::protocol::T_BINARY_PROTOCOL:
908 apache::thrift::BinaryProtocolReader reader;
909 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::BinaryProtocolWriter>(
910 &reader, state, state.extractSink(), _return);
912 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
914 apache::thrift::CompactProtocolReader reader;
915 return apache::thrift::detail::ac::recv_wrapped<result, ExMapType, apache::thrift::CompactProtocolWriter>(
916 &reader, state, state.extractSink(), _return);
918 default:
922 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
925 apache::thrift::ClientSink<::std::int32_t, ::std::int32_t> apache::thrift::Client<::cpp2::B>::recv_sink_stuff(::apache::thrift::ClientReceiveState& state) {
926 apache::thrift::ClientSink<::std::int32_t, ::std::int32_t> _return;
927 auto ew = recv_wrapped_sink_stuff(_return, state);
928 if (ew) {
929 ew.throw_exception();
931 return _return;
934 apache::thrift::ClientSink<::std::int32_t, ::std::int32_t> apache::thrift::Client<::cpp2::B>::recv_instance_sink_stuff(::apache::thrift::ClientReceiveState& state) {
935 return recv_sink_stuff(state);
938 folly::exception_wrapper apache::thrift::Client<::cpp2::B>::recv_instance_wrapped_sink_stuff(apache::thrift::ClientSink<::std::int32_t, ::std::int32_t>& _return, ::apache::thrift::ClientReceiveState& state) {
939 return recv_wrapped_sink_stuff(_return, state);
945 namespace cpp2 {
946 } // cpp2
949 apache::thrift::Client<::cpp2::C>::I apache::thrift::Client<::cpp2::C>::createI() {
950 return I(channel_, "I");
954 namespace cpp2 {
955 typedef apache::thrift::ThriftPresult<false> C_I_interact_pargs;
956 typedef apache::thrift::ThriftPresult<true> C_I_interact_presult;
957 } // cpp2
958 template <typename Protocol_, typename RpcOptions>
959 void apache::thrift::Client<::cpp2::C>::I::interactT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback) {
960 apache::thrift::RpcOptions rpcOpts(std::forward<RpcOptions>(rpcOptions));
961 setInteraction(rpcOpts);
963 ::cpp2::C_I_interact_pargs args;
964 auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); };
965 auto writer = [&](Protocol_* p) { args.write(p); };
967 static ::apache::thrift::MethodMetadata::Data* methodMetadata =
968 new ::apache::thrift::MethodMetadata::Data(
969 "I.interact",
970 ::apache::thrift::FunctionQualifier::Unspecified,
971 ::apache::thrift::InteractionMethodPosition::Member,
972 "I");
973 apache::thrift::clientSendT<apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE, Protocol_>(prot, std::move(rpcOpts), std::move(callback), contextStack, std::move(header), channel_.get(), ::apache::thrift::MethodMetadata::from_static(methodMetadata), writer, sizer);
978 void apache::thrift::Client<::cpp2::C>::I::interact(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback) {
979 auto [ctx, header] = interactCtx(&rpcOptions);
980 apache::thrift::RequestCallback::Context callbackContext;
981 callbackContext.protocolId =
982 apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
983 auto* contextStack = ctx.get();
984 if (callback) {
985 callbackContext.ctx = std::move(ctx);
987 auto wrappedCallback = apache::thrift::toRequestClientCallbackPtr(std::move(callback), std::move(callbackContext));
988 interactImpl(rpcOptions, std::move(header), contextStack, std::move(wrappedCallback));
991 void apache::thrift::Client<::cpp2::C>::I::interactImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, bool stealRpcOptions) {
992 switch (apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId()) {
993 case apache::thrift::protocol::T_BINARY_PROTOCOL:
995 apache::thrift::BinaryProtocolWriter writer;
996 if (stealRpcOptions) {
997 interactT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
998 } else {
999 interactT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
1001 break;
1003 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
1005 apache::thrift::CompactProtocolWriter writer;
1006 if (stealRpcOptions) {
1007 interactT(&writer, std::move(rpcOptions), std::move(header), contextStack, std::move(callback));
1008 } else {
1009 interactT(&writer, rpcOptions, std::move(header), contextStack, std::move(callback));
1011 break;
1013 default:
1015 apache::thrift::detail::ac::throw_app_exn("Could not find Protocol");
1020 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> apache::thrift::Client<::cpp2::C>::I::interactCtx(apache::thrift::RpcOptions* rpcOptions) {
1021 auto header = std::make_shared<apache::thrift::transport::THeader>(
1022 apache::thrift::transport::THeader::ALLOW_BIG_FRAMES);
1023 header->setProtocolId(channel_->getProtocolId());
1024 if (rpcOptions) {
1025 header->setHeaders(rpcOptions->releaseWriteHeaders());
1028 auto ctx = apache::thrift::ContextStack::createWithClientContext(
1029 handlers_,
1030 getServiceName(),
1031 "C.I.interact",
1032 *header);
1034 return {std::move(ctx), std::move(header)};
1036 void apache::thrift::Client<::cpp2::C>::I::sync_interact() {
1037 ::apache::thrift::RpcOptions rpcOptions;
1038 sync_interact(rpcOptions);
1041 void apache::thrift::Client<::cpp2::C>::I::sync_interact(apache::thrift::RpcOptions& rpcOptions) {
1042 apache::thrift::ClientReceiveState returnState;
1043 apache::thrift::ClientSyncCallback<false> callback(&returnState);
1044 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId();
1045 auto evb = apache::thrift::GeneratedAsyncClient::getChannel()->getEventBase();
1046 auto ctxAndHeader = interactCtx(&rpcOptions);
1047 auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(&callback);
1048 callback.waitUntilDone(
1049 evb,
1050 [&] {
1051 interactImpl(rpcOptions, std::move(ctxAndHeader.second), ctxAndHeader.first.get(), std::move(wrappedCallback));
1054 if (returnState.isException()) {
1055 returnState.exception().throw_exception();
1057 returnState.resetProtocolId(protocolId);
1058 returnState.resetCtx(std::move(ctxAndHeader.first));
1059 SCOPE_EXIT {
1060 if (returnState.header() && !returnState.header()->getHeaders().empty()) {
1061 rpcOptions.setReadHeaders(returnState.header()->releaseHeaders());
1064 return folly::fibers::runInMainContext([&] {
1065 recv_interact(returnState);
1070 folly::SemiFuture<folly::Unit> apache::thrift::Client<::cpp2::C>::I::semifuture_interact() {
1071 ::apache::thrift::RpcOptions rpcOptions;
1072 return semifuture_interact(rpcOptions);
1075 folly::SemiFuture<folly::Unit> apache::thrift::Client<::cpp2::C>::I::semifuture_interact(apache::thrift::RpcOptions& rpcOptions) {
1076 auto callbackAndFuture = makeSemiFutureCallback(recv_wrapped_interact, channel_);
1077 auto callback = std::move(callbackAndFuture.first);
1078 interact(rpcOptions, std::move(callback));
1079 return std::move(callbackAndFuture.second);
1083 #if FOLLY_HAS_COROUTINES
1084 #endif // FOLLY_HAS_COROUTINES
1085 folly::exception_wrapper apache::thrift::Client<::cpp2::C>::I::recv_wrapped_interact(::apache::thrift::ClientReceiveState& state) {
1086 if (state.isException()) {
1087 return std::move(state.exception());
1089 if (!state.hasResponseBuffer()) {
1090 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
1093 using result = ::cpp2::C_I_interact_presult;
1094 switch (state.protocolId()) {
1095 case apache::thrift::protocol::T_BINARY_PROTOCOL:
1097 apache::thrift::BinaryProtocolReader reader;
1098 return apache::thrift::detail::ac::recv_wrapped<result>(
1099 &reader, state);
1101 case apache::thrift::protocol::T_COMPACT_PROTOCOL:
1103 apache::thrift::CompactProtocolReader reader;
1104 return apache::thrift::detail::ac::recv_wrapped<result>(
1105 &reader, state);
1107 default:
1111 return folly::make_exception_wrapper<apache::thrift::TApplicationException>("Could not find Protocol");
1113 void apache::thrift::Client<::cpp2::C>::I::recv_interact(::apache::thrift::ClientReceiveState& state) {
1114 auto ew = recv_wrapped_interact(state);
1115 if (ew) {
1116 ew.throw_exception();