1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <folly/Utility.h>
20 #include <thrift/lib/cpp2/Thrift.h>
21 #include <thrift/lib/cpp2/protocol/Cpp2Ops.h>
22 
23 namespace apache {
24 namespace thrift {
25 namespace detail {
26 
27 template <typename Protocol, typename Args>
deserializeRequestBody(Protocol * prot,Args * args)28 uint32_t deserializeRequestBody(Protocol* prot, Args* args) {
29   auto xferStart = prot->getCursorPosition();
30   ::apache::thrift::Cpp2Ops<Args>::read(prot, args);
31   return folly::to_narrow(prot->getCursorPosition() - xferStart);
32 }
33 
34 template <typename Protocol, typename Args>
serializeResponseBody(Protocol * prot,const Args * args)35 uint32_t serializeResponseBody(Protocol* prot, const Args* args) {
36   return ::apache::thrift::Cpp2Ops<Args>::write(prot, args);
37 }
38 
39 template <typename Protocol, typename Args>
serializedResponseBodySizeZC(Protocol * prot,const Args * args)40 uint32_t serializedResponseBodySizeZC(Protocol* prot, const Args* args) {
41   return ::apache::thrift::Cpp2Ops<Args>::serializedSizeZC(prot, args);
42 }
43 
44 template <typename Protocol, typename Args>
deserializeExceptionBody(Protocol * prot,Args * args)45 uint32_t deserializeExceptionBody(Protocol* prot, Args* args) {
46   return args->read(prot);
47 }
48 
49 template <typename Protocol, typename Args>
serializeExceptionBody(Protocol * prot,const Args * args)50 uint32_t serializeExceptionBody(Protocol* prot, const Args* args) {
51   return args->write(prot);
52 }
53 
54 template <typename Protocol, typename Args>
serializedExceptionBodySizeZC(Protocol * prot,const Args * args)55 uint32_t serializedExceptionBodySizeZC(Protocol* prot, const Args* args) {
56   return args->serializedSizeZC(prot);
57 }
58 } // namespace detail
59 } // namespace thrift
60 } // namespace apache
61