Drop pre-Swift 5 compat in source
Remove if-swift versions, also ties it to NIO2.
This commit is contained in:
parent
7ed9d3bb81
commit
f3f50c7a01
|
@ -69,4 +69,5 @@ fastlane/test_output
|
||||||
*.xcodeproj
|
*.xcodeproj
|
||||||
.build-linux
|
.build-linux
|
||||||
Package.resolved
|
Package.resolved
|
||||||
|
.swiftpm
|
||||||
|
|
||||||
|
|
12
.travis.yml
12
.travis.yml
|
@ -7,16 +7,18 @@ matrix:
|
||||||
include:
|
include:
|
||||||
- os: Linux
|
- os: Linux
|
||||||
dist: trusty
|
dist: trusty
|
||||||
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-4.2.3-release/ubuntu1404/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu14.04.tar.gz"
|
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0.2-release/ubuntu1404/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu14.04.tar.gz"
|
||||||
sudo: required
|
sudo: required
|
||||||
- os: Linux
|
- os: Linux
|
||||||
dist: trusty
|
dist: trusty
|
||||||
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz"
|
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.1.3-release/ubuntu1404/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu14.04.tar.gz"
|
||||||
|
sudo: required
|
||||||
|
- os: Linux
|
||||||
|
dist: xenial
|
||||||
|
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.2-release/ubuntu1604/swift-5.2-RELEASE/swift-5.2-RELEASE-ubuntu16.04.tar.gz"
|
||||||
sudo: required
|
sudo: required
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode10.1
|
osx_image: xcode11
|
||||||
- os: osx
|
|
||||||
osx_image: xcode10.2
|
|
||||||
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// swift-tools-version:4.2
|
// swift-tools-version:5.0
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ let package = Package(
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-nio.git",
|
.package(url: "https://github.com/apple/swift-nio.git",
|
||||||
from: "1.13.2"),
|
from: "2.18.0")
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(name: "NIORedis",
|
.target(name: "NIORedis",
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
// swift-tools-version:5.0
|
|
||||||
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "swift-nio-redis",
|
|
||||||
products: [
|
|
||||||
.library(name: "NIORedis", targets: [ "NIORedis" ]),
|
|
||||||
],
|
|
||||||
dependencies: [
|
|
||||||
.package(url: "https://github.com/apple/swift-nio.git",
|
|
||||||
from: "2.0.0")
|
|
||||||
],
|
|
||||||
targets: [
|
|
||||||
.target(name: "NIORedis",
|
|
||||||
dependencies: [ "NIO", "NIOFoundationCompat" ]),
|
|
||||||
.testTarget(name: "NIORedisTests", dependencies: [ "NIORedis"])
|
|
||||||
]
|
|
||||||
)
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// This source file is part of the swift-nio-redis open source project
|
// This source file is part of the swift-nio-redis open source project
|
||||||
//
|
//
|
||||||
// Copyright (c) 2018-2019 ZeeZide GmbH. and the swift-nio-redis project authors
|
// Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-redis project authors
|
||||||
// Licensed under Apache License v2.0
|
// Licensed under Apache License v2.0
|
||||||
//
|
//
|
||||||
// See LICENSE.txt for license information
|
// See LICENSE.txt for license information
|
||||||
|
@ -16,18 +16,18 @@ import NIO
|
||||||
|
|
||||||
open class RESPChannelHandler : ChannelDuplexHandler {
|
open class RESPChannelHandler : ChannelDuplexHandler {
|
||||||
|
|
||||||
public typealias InboundErr = RESPParserError
|
public typealias InboundErr = RESPParserError
|
||||||
|
|
||||||
public typealias InboundIn = ByteBuffer
|
public typealias InboundIn = ByteBuffer
|
||||||
public typealias InboundOut = RESPValue
|
public typealias InboundOut = RESPValue
|
||||||
|
|
||||||
public typealias OutboundIn = RESPEncodable
|
public typealias OutboundIn = RESPEncodable
|
||||||
public typealias OutboundOut = ByteBuffer
|
public typealias OutboundOut = ByteBuffer
|
||||||
|
|
||||||
private final let nilStringBuffer = ConstantBuffers.nilStringBuffer
|
private final let nilStringBuffer = ConstantBuffers.nilStringBuffer
|
||||||
private final let nilArrayBuffer = ConstantBuffers.nilArrayBuffer
|
private final let nilArrayBuffer = ConstantBuffers.nilArrayBuffer
|
||||||
|
|
||||||
public final var parser = RESPParser()
|
public final var parser = RESPParser()
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
|
@ -133,27 +133,15 @@ open class RESPChannelHandler : ChannelDuplexHandler {
|
||||||
context.write(wrapOutboundOut(out), promise: promise)
|
context.write(wrapOutboundOut(out), promise: promise)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if swift(>=5)
|
@inline(__always)
|
||||||
@inline(__always)
|
final func encode<S: Collection>(simpleString bytes: S,
|
||||||
final func encode<S: Collection>(simpleString bytes: S,
|
out: inout ByteBuffer)
|
||||||
out: inout ByteBuffer)
|
where S.Element == UInt8
|
||||||
where S.Element == UInt8
|
{
|
||||||
{
|
out.writeInteger(UInt8(43)) // +
|
||||||
out.writeInteger(UInt8(43)) // +
|
out.writeBytes(bytes)
|
||||||
out.writeBytes(bytes)
|
out.writeBytes(eol)
|
||||||
out.writeBytes(eol)
|
}
|
||||||
}
|
|
||||||
#else
|
|
||||||
@inline(__always)
|
|
||||||
final func encode<S: ContiguousCollection>(simpleString bytes: S,
|
|
||||||
out: inout ByteBuffer)
|
|
||||||
where S.Element == UInt8
|
|
||||||
{
|
|
||||||
out.writeInteger(UInt8(43)) // +
|
|
||||||
out.writeBytes(bytes)
|
|
||||||
out.writeBytes(eol)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
final func encode(simpleString bytes: ByteBuffer, out: inout ByteBuffer) {
|
final func encode(simpleString bytes: ByteBuffer, out: inout ByteBuffer) {
|
||||||
|
@ -177,41 +165,22 @@ open class RESPChannelHandler : ChannelDuplexHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if swift(>=5)
|
@inline(__always)
|
||||||
@inline(__always)
|
final func encode<S: Collection>(bulkString bytes: S?,
|
||||||
final func encode<S: Collection>(bulkString bytes: S?,
|
out: inout ByteBuffer)
|
||||||
out: inout ByteBuffer)
|
where S.Element == UInt8
|
||||||
where S.Element == UInt8
|
{
|
||||||
{
|
if let s = bytes {
|
||||||
if let s = bytes {
|
out.writeInteger(UInt8(36)) // $
|
||||||
out.writeInteger(UInt8(36)) // $
|
out.write(integerAsString : Int(s.count))
|
||||||
out.write(integerAsString : Int(s.count))
|
out.writeBytes(eol)
|
||||||
out.writeBytes(eol)
|
out.writeBytes(s)
|
||||||
out.writeBytes(s)
|
out.writeBytes(eol)
|
||||||
out.writeBytes(eol)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
out.writeBytes(nilString)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
else {
|
||||||
@inline(__always)
|
out.writeBytes(nilString)
|
||||||
final func encode<S: ContiguousCollection>(bulkString bytes: S?,
|
|
||||||
out: inout ByteBuffer)
|
|
||||||
where S.Element == UInt8
|
|
||||||
{
|
|
||||||
if let s = bytes {
|
|
||||||
out.writeInteger(UInt8(36)) // $
|
|
||||||
out.write(integerAsString : Int(s.count))
|
|
||||||
out.writeBytes(eol)
|
|
||||||
out.writeBytes(s)
|
|
||||||
out.writeBytes(eol)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
out.writeBytes(nilString)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
final func encode(integer i: Int, out: inout ByteBuffer) {
|
final func encode(integer i: Int, out: inout ByteBuffer) {
|
||||||
|
@ -270,36 +239,6 @@ open class RESPChannelHandler : ChannelDuplexHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if swift(>=5) // NIO 2 API - default
|
|
||||||
#else // NIO 1 API Shims
|
|
||||||
open func channelActive(ctx context: ChannelHandlerContext) {
|
|
||||||
channelActive(context: context)
|
|
||||||
}
|
|
||||||
open func channelInactive(ctx context: ChannelHandlerContext) {
|
|
||||||
channelInactive(context: context)
|
|
||||||
}
|
|
||||||
public func channelRead(ctx context: ChannelHandlerContext, data: NIOAny) {
|
|
||||||
channelRead(context: context, data: data)
|
|
||||||
}
|
|
||||||
open func channelRead(ctx context: ChannelHandlerContext, value: RESPValue) {
|
|
||||||
channelRead(context: context, value: value)
|
|
||||||
}
|
|
||||||
open func errorCaught(ctx context: ChannelHandlerContext, error: Error) {
|
|
||||||
errorCaught(context: context, error: error)
|
|
||||||
}
|
|
||||||
public func write(ctx context: ChannelHandlerContext, data: NIOAny,
|
|
||||||
promise: EventLoopPromise<Void>?)
|
|
||||||
{
|
|
||||||
write(context: context, data: data, promise: promise)
|
|
||||||
}
|
|
||||||
public final func write(ctx context: ChannelHandlerContext, value: RESPValue,
|
|
||||||
promise: EventLoopPromise<Void>?)
|
|
||||||
{
|
|
||||||
write(context: context, value: value, promise: promise)
|
|
||||||
}
|
|
||||||
#endif // NIO 1 API Shims
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private let eol : ContiguousArray<UInt8> = [ 13, 10 ] // \r\n
|
private let eol : ContiguousArray<UInt8> = [ 13, 10 ] // \r\n
|
||||||
|
@ -310,49 +249,16 @@ fileprivate enum ConstantBuffers {
|
||||||
|
|
||||||
static let nilStringBuffer : ByteBuffer = {
|
static let nilStringBuffer : ByteBuffer = {
|
||||||
let alloc = ByteBufferAllocator()
|
let alloc = ByteBufferAllocator()
|
||||||
var bb = alloc.buffer(capacity: 6)
|
var bb = alloc.buffer(capacity: 6)
|
||||||
bb.writeBytes(nilString)
|
bb.writeBytes(nilString)
|
||||||
return bb
|
return bb
|
||||||
}()
|
}()
|
||||||
|
|
||||||
static let nilArrayBuffer : ByteBuffer = {
|
static let nilArrayBuffer : ByteBuffer = {
|
||||||
let alloc = ByteBufferAllocator()
|
let alloc = ByteBufferAllocator()
|
||||||
var bb = alloc.buffer(capacity: 6)
|
var bb = alloc.buffer(capacity: 6)
|
||||||
bb.writeBytes(nilArray)
|
bb.writeBytes(nilArray)
|
||||||
return bb
|
return bb
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
#if swift(>=5)
|
|
||||||
// NIO 2
|
|
||||||
#else
|
|
||||||
fileprivate extension ByteBuffer {
|
|
||||||
// NIO 2 API for NIO 1
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeString(_ string: String) -> Int {
|
|
||||||
return self.write(string: string) ?? -1337 // never fails
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeInteger<T: FixedWidthInteger>(_ integer: T) -> Int {
|
|
||||||
return self.write(integer: integer)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBuffer(_ buffer: inout ByteBuffer) -> Int {
|
|
||||||
return self.write(buffer: &buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBytes(_ bytes: UnsafeRawBufferPointer) -> Int {
|
|
||||||
return self.write(bytes: bytes)
|
|
||||||
}
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBytes<Bytes: Sequence>(_ bytes: Bytes) -> Int
|
|
||||||
where Bytes.Element == UInt8
|
|
||||||
{
|
|
||||||
return self.write(bytes: bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // swift(<5)
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// This source file is part of the swift-nio-redis open source project
|
// This source file is part of the swift-nio-redis open source project
|
||||||
//
|
//
|
||||||
// Copyright (c) 2018-2019 ZeeZide GmbH. and the swift-nio-redis project authors
|
// Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-redis project authors
|
||||||
// Licensed under Apache License v2.0
|
// Licensed under Apache License v2.0
|
||||||
//
|
//
|
||||||
// See LICENSE.txt for license information
|
// See LICENSE.txt for license information
|
||||||
|
@ -18,7 +18,7 @@ import struct NIO.ByteBufferAllocator
|
||||||
public enum RESPParserError : Error {
|
public enum RESPParserError : Error {
|
||||||
case UnexpectedStartByte(char: UInt8, buffer: ByteBuffer)
|
case UnexpectedStartByte(char: UInt8, buffer: ByteBuffer)
|
||||||
case UnexpectedEndByte (char: UInt8, buffer: ByteBuffer)
|
case UnexpectedEndByte (char: UInt8, buffer: ByteBuffer)
|
||||||
case TransportError(Swift.Error)
|
case TransportError (Swift.Error)
|
||||||
case ProtocolError
|
case ProtocolError
|
||||||
case UnexpectedNegativeCount
|
case UnexpectedNegativeCount
|
||||||
case InternalInconsistency
|
case InternalInconsistency
|
||||||
|
@ -333,27 +333,3 @@ public struct RESPParser {
|
||||||
private var overflowBuffer : ByteBuffer?
|
private var overflowBuffer : ByteBuffer?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if swift(>=5)
|
|
||||||
// NIO 2
|
|
||||||
#else
|
|
||||||
fileprivate extension ByteBuffer {
|
|
||||||
// NIO 2 API for NIO 1
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeInteger<T: FixedWidthInteger>(_ integer: T) -> Int {
|
|
||||||
return self.write(integer: integer)
|
|
||||||
}
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBytes(_ bytes: UnsafeRawBufferPointer) -> Int {
|
|
||||||
return self.write(bytes: bytes)
|
|
||||||
}
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBytes<Bytes: Sequence>(_ bytes: Bytes) -> Int
|
|
||||||
where Bytes.Element == UInt8
|
|
||||||
{
|
|
||||||
return self.write(bytes: bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // swift(<5)
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// This source file is part of the swift-nio-redis open source project
|
// This source file is part of the swift-nio-redis open source project
|
||||||
//
|
//
|
||||||
// Copyright (c) 2018-2019 ZeeZide GmbH. and the swift-nio-redis project authors
|
// Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-redis project authors
|
||||||
// Licensed under Apache License v2.0
|
// Licensed under Apache License v2.0
|
||||||
//
|
//
|
||||||
// See LICENSE.txt for license information
|
// See LICENSE.txt for license information
|
||||||
|
@ -21,12 +21,7 @@ public extension ChannelPipeline {
|
||||||
name : String = "de.zeezide.nio.RESP")
|
name : String = "de.zeezide.nio.RESP")
|
||||||
-> EventLoopFuture<Void>
|
-> EventLoopFuture<Void>
|
||||||
{
|
{
|
||||||
#if swift(>=5)
|
return self.addHandler(RESPChannelHandler(), name: name,
|
||||||
return self.addHandler(RESPChannelHandler(), name: name,
|
position: first ? .first : .last)
|
||||||
position: first ? .first : .last)
|
|
||||||
#else
|
|
||||||
return self.add(name: name, handler: RESPChannelHandler(), first: first)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// This source file is part of the swift-nio-redis open source project
|
// This source file is part of the swift-nio-redis open source project
|
||||||
//
|
//
|
||||||
// Copyright (c) 2018-2019 ZeeZide GmbH. and the swift-nio-redis project authors
|
// Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-redis project authors
|
||||||
// Licensed under Apache License v2.0
|
// Licensed under Apache License v2.0
|
||||||
//
|
//
|
||||||
// See LICENSE.txt for license information
|
// See LICENSE.txt for license information
|
||||||
|
@ -241,7 +241,6 @@ extension RESPValue : CustomStringConvertible {
|
||||||
case .error(let e): return "<Error: \(e)>"
|
case .error(let e): return "<Error: \(e)>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,24 +275,4 @@ extension String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if swift(>=5)
|
|
||||||
// NIO 2
|
|
||||||
#else
|
|
||||||
fileprivate extension ByteBuffer {
|
|
||||||
// NIO 2 API for NIO 1
|
|
||||||
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBytes(_ bytes: UnsafeRawBufferPointer) -> Int {
|
|
||||||
return self.write(bytes: bytes)
|
|
||||||
}
|
|
||||||
@inline(__always) @discardableResult
|
|
||||||
mutating func writeBytes<Bytes: Sequence>(_ bytes: Bytes) -> Int
|
|
||||||
where Bytes.Element == UInt8
|
|
||||||
{
|
|
||||||
return self.write(bytes: bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // swift(<5)
|
|
||||||
|
|
Loading…
Reference in New Issue