Files
swift-nio-imap/Sources/NIOIMAP/Coders/ResponseDecoder.swift
T
David Evans a06b3898aa Hide incomplete message errors (#135)
* Hide incomplete message errors

* Fix sanity

* Throw error

* Fix rebase

* Refactor

* Log not throw

* Improve roundtrip handler

* Fix sanity

* Update comments

* Remove error case

* Logging

* PR review

* Simplify loop

* Use NIOSinglestep...

* Fix sanity

* Even more efficiency

* Fix sanity
2020-05-28 13:49:11 +01:00

40 lines
1.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 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 ResponseDecoder: NIOSingleStepByteToMessageDecoder {
public typealias InboundOut = ResponseOrContinueRequest
var parser: ResponseParser
public init(bufferLimit: Int = 1_000, expectGreeting: Bool = true) {
self.parser = ResponseParser(bufferLimit: bufferLimit, expectGreeting: expectGreeting)
}
public mutating func decode(buffer: inout ByteBuffer) throws -> ResponseOrContinueRequest? {
let save = buffer
do {
return try self.parser.parseResponseStream(buffer: &buffer)
} catch {
throw IMAPDecoderError(parserError: error, buffer: save)
}
}
public mutating func decodeLast(buffer: inout ByteBuffer, seenEOF: Bool) throws -> ResponseOrContinueRequest? {
try self.decode(buffer: &buffer)
}
}