-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for encoding custom commands
This _only_ handles _encoding_ of custom commands. This simply adds a ```swift case custom(name: String, payloads: [CustomCommandPayload]) ``` such that clients of this library do their own encoding of such commands. This is related to the discussion in #92
- Loading branch information
1 parent
82c191e
commit dd093ef
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Sources/NIOIMAPCore/Grammar/Command/CustomCommandPayload.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 struct NIO.ByteBuffer | ||
|
||
extension Command { | ||
public enum CustomCommandPayload: Hashable { | ||
/// This will be encoded using `quoted` or `literal`. | ||
case literal(ByteBuffer) | ||
/// This will be encoded _verbatim_, i.e. directly copied to the output buffer without change. | ||
case verbatim(ByteBuffer) | ||
} | ||
} | ||
|
||
// MARK: - | ||
|
||
extension EncodeBuffer { | ||
/// Writes a `CustomCommandPayload` to the buffer ready to be sent to the network. | ||
/// - parameter stream: The `CustomCommandPayload` to write. | ||
/// - returns: The number of bytes written. | ||
@discardableResult public mutating func writeCustomCommandPayload(_ payload: Command.CustomCommandPayload) -> Int { | ||
switch payload { | ||
case .literal(let literal): | ||
return self.writeIMAPString(literal) | ||
case .verbatim(let verbatim): | ||
return self.writeBytes(verbatim.readableBytesView) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters