2 * Copyright 2015 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <folly/wangle/codec/ByteToMessageCodec.h>
19 #include <folly/io/Cursor.h>
21 namespace folly { namespace wangle {
24 * A decoder that splits the received IOBufQueue on line endings.
26 * Both "\n" and "\r\n" are handled, or optionally reqire only
29 class LineBasedFrameDecoder : public ByteToMessageCodec {
31 enum class TerminatorType {
37 LineBasedFrameDecoder(uint32_t maxLength = UINT_MAX,
38 bool stripDelimiter = true,
39 TerminatorType terminatorType =
40 TerminatorType::BOTH);
42 std::unique_ptr<IOBuf> decode(Context* ctx, IOBufQueue& buf, size_t&);
46 int64_t findEndOfLine(IOBufQueue& buf);
48 void fail(Context* ctx, std::string len);
53 bool discarding_{false};
54 uint32_t discardedBytes_{0};
56 TerminatorType terminatorType_;