mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-24 04:38:04 +00:00
Resolves #663 Convert the default limits from 1000 to 8192 octets, as per RFC 7162.
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import NIO
|
|
import NIOIMAPCore
|
|
|
|
public struct FrameDecoder: ByteToMessageDecoder {
|
|
public typealias InboundOut = FramingResult
|
|
|
|
private var framingParser: FramingParser
|
|
|
|
public init(frameSizeLimit: Int = IMAPDefaults.lineLengthLimit) {
|
|
self.framingParser = FramingParser(bufferSizeLimit: frameSizeLimit)
|
|
}
|
|
|
|
public mutating func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
|
|
let frames = try self.framingParser.appendAndFrameBuffer(&buffer)
|
|
guard frames.count > 0 else {
|
|
return .needMoreData
|
|
}
|
|
|
|
for frame in frames {
|
|
context.fireChannelRead(self.wrapInboundOut(frame))
|
|
}
|
|
return .continue
|
|
}
|
|
}
|