proxygen
MessageToByteEncoder.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 
27 template <typename M>
28 class MessageToByteEncoder : public OutboundHandler<M, std::unique_ptr<folly::IOBuf>> {
29  public:
31 
32  virtual std::unique_ptr<folly::IOBuf> encode(M& msg) = 0;
33 
34  folly::Future<folly::Unit> write(Context* ctx, M msg) override {
35  auto buf = encode(msg);
36  return buf ? ctx->fireWrite(std::move(buf)) : folly::makeFuture();
37  }
38 };
39 
40 } // namespace wangle
OutboundHandler< M, std::unique_ptr< folly::IOBuf > >::Context Context
virtual folly::Future< folly::Unit > fireWrite(Out msg)=0
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Future< folly::Unit > write(Context *ctx, M msg) override
virtual std::unique_ptr< folly::IOBuf > encode(M &msg)=0
**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
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310