proxygen
LineBasedFrameDecoder.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 <folly/io/Cursor.h>
21 
22 namespace wangle {
23 
31  public:
32  enum class TerminatorType {
33  BOTH,
34  NEWLINE,
36  };
37 
38  explicit LineBasedFrameDecoder(
39  uint32_t maxLength = UINT_MAX,
40  bool stripDelimiter = true,
41  TerminatorType terminatorType = TerminatorType::BOTH);
42 
43  bool decode(Context* ctx,
44  folly::IOBufQueue& buf,
45  std::unique_ptr<folly::IOBuf>& result,
46  size_t&) override;
47 
48  private:
49 
51 
52  void fail(Context* ctx, std::string len);
53 
56 
57  bool discarding_{false};
59 
61 };
62 
63 } // namespace wangle
LineBasedFrameDecoder(uint32_t maxLength=UINT_MAX, bool stripDelimiter=true, TerminatorType terminatorType=TerminatorType::BOTH)
void fail(Context *ctx, std::string len)
InboundHandler< folly::IOBufQueue &, M >::Context Context
int64_t findEndOfLine(folly::IOBufQueue &buf)
const char * string
Definition: Conv.cpp:212
bool decode(Context *ctx, folly::IOBufQueue &buf, std::unique_ptr< folly::IOBuf > &result, size_t &) override