Files
swift-nio-imap/Examples/PerformanceTester/Sources/NIOIMAPPerformanceTester/CommandTester.swift
T
Daniel Eggert dd881edcce Add Command.Tag for command and response tags
`TaggedCommand(tag: "A1 NOOP\r\nA2 DELETE INBOX\r\nA3", command: .noop)`
was written verbatim, injecting a command; likewise `APPEND` start.
`TaggedResponse(tag: "* BYE x\r\nA1", …)` injected a response.

RFC 3501: `tag = 1*<any ASTRING-CHAR except "+">`. New `Command.Tag`
replaces the `String` in `TaggedCommand`, `TaggedResponse`, `Response`,
`CommandStreamPart`, `AppendCommand`, `BadCommand` and NIOIMAP's state
machine errors; `init?(_:)` validates, literals trap. The parser already
enforces the production. IMAPCommands converts its numeric tags.
2026-11-03 14:59:37 +01:00

53 lines
1.6 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 NIOIMAP
@_spi(NIOIMAPInternal) import NIOIMAPCore
class CommandTester: Benchmark {
var command: Command
var iterations: Int
init(command: Command, iterations: Int) {
self.command = command
self.iterations = iterations
}
func setUp() throws {}
func tearDown() {}
@discardableResult func run() throws -> Int {
for i in 1...self.iterations {
var commandBuffer = CommandEncodeBuffer(buffer: ByteBuffer(), options: .init(), loggingMode: false)
commandBuffer.writeCommand(.init(tag: Command.Tag("\(i)")!, command: self.command))
var buffer = ByteBuffer()
var chunk = commandBuffer.buffer.nextChunk()
var chunkBuffer = chunk.bytes
buffer.writeBuffer(&chunkBuffer)
while chunk.waitForContinuation {
chunk = commandBuffer.buffer.nextChunk()
var chunkBuffer = chunk.bytes
buffer.writeBuffer(&chunkBuffer)
}
var parser = CommandParser(bufferLimit: 1000)
_ = try! parser.parseCommandStream(buffer: &buffer)
}
return self.iterations
}
}