proxygen
ByteToMessageDecoder.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 <wangle/channel/Handler.h>
20 
21 namespace wangle {
22 
43 template <typename M>
44 class ByteToMessageDecoder : public InboundHandler<folly::IOBufQueue&, M> {
45  public:
47 
54  virtual bool decode(Context* ctx, folly::IOBufQueue& buf, M& result, size_t&) = 0;
55 
56  void transportActive(Context* ctx) override {
57  transportActive_ = true;
58  ctx->fireTransportActive();
59  }
60 
61  void transportInactive(Context* ctx) override {
62  transportActive_ = false;
63  ctx->fireTransportInactive();
64  }
65 
66  void read(Context* ctx, folly::IOBufQueue& q) override {
67  bool success = true;
68  while (success && transportActive_) {
69  M result;
70  size_t needed = 0;
71  success = decode(ctx, q, result, needed);
72  if (success) {
73  ctx->fireRead(std::move(result));
74  }
75  }
76  }
77 
78  private:
79  bool transportActive_ = true;
80 };
81 
83 
84 } // namespace wangle
void read(Context *ctx, folly::IOBufQueue &q) override
virtual void fireTransportActive()=0
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ByteToMessageDecoder< std::unique_ptr< folly::IOBuf > > ByteToByteDecoder
InboundHandler< folly::IOBufQueue &, M >::Context Context
virtual bool decode(Context *ctx, folly::IOBufQueue &buf, M &result, size_t &)=0
virtual void fireTransportInactive()=0
void transportActive(Context *ctx) override
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
void transportInactive(Context *ctx) override
virtual void fireRead(In msg)=0