removing non-existing file from the build
[folly.git] / folly / wangle / codec / LineBasedFrameDecoder.h
1 /*
2  * Copyright 2015 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 <folly/wangle/codec/ByteToMessageCodec.h>
19 #include <folly/io/Cursor.h>
20
21 namespace folly { namespace wangle {
22
23 /**
24  * A decoder that splits the received IOBufQueue on line endings.
25  *
26  * Both "\n" and "\r\n" are handled, or optionally reqire only
27  * one or the other.
28  */
29 class LineBasedFrameDecoder : public ByteToMessageCodec {
30  public:
31   enum class TerminatorType {
32     BOTH,
33     NEWLINE,
34     CARRIAGENEWLINE
35   };
36
37   LineBasedFrameDecoder(uint32_t maxLength = UINT_MAX,
38                         bool stripDelimiter = true,
39                         TerminatorType terminatorType =
40                         TerminatorType::BOTH);
41
42   std::unique_ptr<IOBuf> decode(Context* ctx, IOBufQueue& buf, size_t&);
43
44  private:
45
46   int64_t findEndOfLine(IOBufQueue& buf);
47
48   void fail(Context* ctx, std::string len);
49
50   uint32_t maxLength_;
51   bool stripDelimiter_;
52
53   bool discarding_{false};
54   uint32_t discardedBytes_{0};
55
56   TerminatorType terminatorType_;
57 };
58
59 }} // namespace