Files
swift-nio-imap/Sources/NIOIMAPCore/Grammar/LastCommandSet.swift
T
David Evans 81c8e9158d Underscore EncodeBuffer (#479)
* Underscore

* Underscore everything

* Add soundness self insert
2021-03-18 11:25:05 +00:00

42 lines
1.5 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
//
//===----------------------------------------------------------------------===//
/// Defines an interface for a type to be able to serialize itself to an `EncodeBuffer`.
/// Avoid conforming to this protocol, and use the standard `EncodeBuffer.write` functions.
public protocol _IMAPEncodable: ExpressibleByArrayLiteral, Hashable {
/// Writes the set to an `inout EncodeBuffer`.
func _writeIntoBuffer(_ buffer: inout _EncodeBuffer) -> Int
}
/// Provides support for using either the result of the last command (`.lastCommand`) or
/// a concrete set type.
public enum LastCommandSet<SetType: _IMAPEncodable>: Hashable {
/// A specific set that will be sent to the IMAP server. E.g. `1, 2:5, 10:*`
case set(SetType)
/// Tells the server to use the result of the last command, described in RFC 5182.
case lastCommand
}
extension _EncodeBuffer {
@discardableResult mutating func writeLastCommandSet<T>(_ set: LastCommandSet<T>) -> Int {
switch set {
case .lastCommand:
return self._writeString("$")
case .set(let set):
return set._writeIntoBuffer(&self)
}
}
}