proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
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
25
class
ClientSerializeHandler
:
public
wangle::Handler
<
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;
39
apache::thrift::CompactSerializer::serialize
(b, &out);
40
return
ctx->
fireWrite
(
folly::IOBuf::copyBuffer
(out));
41
}
42
};
wangle::Handler
Definition:
Handler.h:49
b
char b
Definition:
OptionalTest.cpp:53
wangle::HandlerContext::fireWrite
virtual folly::Future< folly::Unit > fireWrite(Out msg)=0
wangle::HandlerContext< thrift::test::Xtruct, std::unique_ptr< folly::IOBuf > >
ClientSerializeHandler
Definition:
ClientSerializeHandler.h:25
ClientSerializeHandler::read
void read(Context *ctx, std::unique_ptr< folly::IOBuf > msg) override
Definition:
ClientSerializeHandler.h:29
ClientSerializeHandler::write
folly::Future< folly::Unit > write(Context *ctx, thrift::test::Bonk b) override
Definition:
ClientSerializeHandler.h:36
wangle::HandlerContext::fireRead
virtual void fireRead(In msg)=0
folly::Future
Definition:
FiberManagerInternal.h:46
Handler.h
string
const char * string
Definition:
Conv.cpp:212
folly::json::serialize
std::string serialize(dynamic const &dyn, serialization_opts const &opts)
Definition:
json.cpp:621
folly::IOBuf::copyBuffer
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
proxygen
wangle
wangle
example
rpc
ClientSerializeHandler.h
Generated by
1.8.11