proxygen
ClientSerializeHandler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
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 #pragma once
17 
18 #include <wangle/channel/Handler.h>
19 
20 #include <thrift/test/gen-cpp2/ThriftTest.h>
21 #include <thrift/lib/cpp2/protocol/Serializer.h>
22 
23 // Do some serialization / deserialization using thrift.
24 // A real rpc server would probably use generated client/server stubs
26  std::unique_ptr<folly::IOBuf>, thrift::test::Xtruct,
27  thrift::test::Bonk, std::unique_ptr<folly::IOBuf>> {
28  public:
29  void read(Context* ctx, std::unique_ptr<folly::IOBuf> msg) override {
30  thrift::test::Xtruct received =
31  apache::thrift::CompactSerializer::deserialize<thrift::test::Xtruct>(
32  msg.get());
33  ctx->fireRead(received);
34  }
35 
36  folly::Future<folly::Unit> write(Context* ctx, thrift::test::Bonk b)
37  override {
38  std::string out;
40  return ctx->fireWrite(folly::IOBuf::copyBuffer(out));
41  }
42 };
char b
virtual folly::Future< folly::Unit > fireWrite(Out msg)=0
void read(Context *ctx, std::unique_ptr< folly::IOBuf > msg) override
folly::Future< folly::Unit > write(Context *ctx, thrift::test::Bonk b) override
virtual void fireRead(In msg)=0
const char * string
Definition: Conv.cpp:212
std::string serialize(dynamic const &dyn, serialization_opts const &opts)
Definition: json.cpp:621
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587