proxygen
CodecTestUtils.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 
17 #pragma once
18 
19 #include <memory>
20 
21 #include <folly/Function.h>
22 #include <folly/io/IOBuf.h>
23 #include <wangle/channel/Handler.h>
24 
25 namespace wangle {
26 namespace test {
27 
29  : public wangle::InboundHandler<std::unique_ptr<folly::IOBuf>> {
30  public:
31  explicit FrameTester(
32  folly::Function<void(std::unique_ptr<folly::IOBuf>)> test)
33  : test_(std::move(test)) {}
34 
35  void read(Context*, std::unique_ptr<folly::IOBuf> buf) override {
36  test_(std::move(buf));
37  }
38 
40  test_(nullptr);
41  }
42 
43  private:
45 };
46 
48  public:
50  Context* ctx,
51  std::unique_ptr<folly::IOBuf> buf) override {
53  q_.append(std::move(buf));
54  ctx->fireRead(q_);
55 
56  return folly::makeFuture();
57  }
58 };
59 }
60 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
folly::Function< void(std::unique_ptr< folly::IOBuf >)> test_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
static Options cacheChainLength()
Definition: IOBufQueue.h:83
folly::Future< folly::Unit > write(Context *ctx, std::unique_ptr< folly::IOBuf > buf) override
void readException(Context *, folly::exception_wrapper) override
FrameTester(folly::Function< void(std::unique_ptr< folly::IOBuf >)> test)
void read(Context *, std::unique_ptr< folly::IOBuf > buf) override
Handler< R, R, W, W >::Context Context
Definition: Handler.h:161
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310