Compare commits

...

1 Commits

Author SHA1 Message Date
William LaFrance 6cc4535fc8 wip on swift 5 update 2019-12-21 22:00:55 -06:00
7 changed files with 19 additions and 11 deletions

View File

@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/apple/swift-nio.git", "repositoryURL": "https://github.com/apple/swift-nio.git",
"state": { "state": {
"branch": null, "branch": null,
"revision": "4fb0cc68fee45d2ae714484b5979316943ef1f24", "revision": "ba7970fe396e8198b84c6c1b44b38a1d4e2eb6bd",
"version": "1.0.0" "version": "1.14.1"
} }
}, },
{ {

View File

@ -81,7 +81,7 @@ public struct Bnftp2SecondRequestComposer {
private let localFiletime = 0 as UInt64 private let localFiletime = 0 as UInt64
let serverToken: UInt32 let serverToken: UInt32
let clientToken = arc4random() let clientToken = UInt32.random(in: .min ... .max)
let filename: String let filename: String
let cdkey: String let cdkey: String

View File

@ -2,6 +2,14 @@ import Foundation
extension Foundation.Data { extension Foundation.Data {
func getByte(at index: Int) -> UInt8 {
let data: UInt8 = self.subdata(in: index ..< (index + 1)).withUnsafeBytes { rawPointer in
rawPointer.bindMemory(to: UInt8.self).baseAddress!.pointee
}
return data
}
public func arrayOfBytes() -> [UInt8] { public func arrayOfBytes() -> [UInt8] {
let count = self.count / MemoryLayout<UInt8>.size let count = self.count / MemoryLayout<UInt8>.size
var bytesArray = [UInt8](repeating: 0, count: count) var bytesArray = [UInt8](repeating: 0, count: count)

View File

@ -17,12 +17,12 @@ public struct BncsMessage: Message, CustomDebugStringConvertible {
} }
// Check sanity bit // Check sanity bit
guard 0xFF as UInt8 == data.withUnsafeBytes({ return $0[0] }) else { guard 0xFF as UInt8 == data.getByte(at: 0) else {
throw BncsMessageError.IllegalSanityByte throw BncsMessageError.IllegalSanityByte
} }
// Check length matches // Check length matches
guard data.count == data.withUnsafeBytes({ IntUtil.from8to16([$0[2], $0[3]]) }) else { guard data.count == IntUtil.from8to16([data.getByte(at: 2), data.getByte(at: 3)]) else {
throw BncsMessageError.IncorrectMessageLength throw BncsMessageError.IncorrectMessageLength
} }
@ -33,7 +33,7 @@ public struct BncsMessage: Message, CustomDebugStringConvertible {
// Check entire header is present -- precondition is fine here, guard is used in init // Check entire header is present -- precondition is fine here, guard is used in init
precondition(data.count > 2) precondition(data.count > 2)
let rawIdentifier: UInt8 = data.withUnsafeBytes { return $0[1] } let rawIdentifier = data.getByte(at: 1)
return BncsMessageIdentifier(rawValue: rawIdentifier) ?? .None return BncsMessageIdentifier(rawValue: rawIdentifier) ?? .None
} }

View File

@ -16,7 +16,7 @@ public struct BnlsMessage: Message, CustomDebugStringConvertible {
} }
// Check length matches // Check length matches
guard data.count == data.withUnsafeBytes({ IntUtil.from8to16([$0[0], $0[1]]) }) else { guard data.count == IntUtil.from8to16([data.getByte(at: 0), data.getByte(at: 1)]) else {
throw BnlsMessageError.IncorrectMessageLength throw BnlsMessageError.IncorrectMessageLength
} }
@ -27,7 +27,7 @@ public struct BnlsMessage: Message, CustomDebugStringConvertible {
// Check entire header is present -- precondition is fine here, guard is used in init // Check entire header is present -- precondition is fine here, guard is used in init
precondition(data.count > 3) precondition(data.count > 3)
let rawIdentifier: UInt8 = data.withUnsafeBytes { return $0[2] } let rawIdentifier = data.getByte(at: 2)
return BnlsMessageIdentifier(rawValue: rawIdentifier) ?? .None return BnlsMessageIdentifier(rawValue: rawIdentifier) ?? .None
} }

View File

@ -27,7 +27,7 @@ extension MessageConsumer {
} }
public mutating func readUInt8() -> UInt8 { public mutating func readUInt8() -> UInt8 {
let x: UInt8 = message.data.withUnsafeBytes({ return $0[readIndex] }) let x: UInt8 = message.data.getByte(at: readIndex)
readIndex += 1 readIndex += 1
return x return x
} }

View File

@ -40,7 +40,7 @@ func loadOptionsFromCommandLine() -> [String: String] {
func createStreamPair(host: String, port: Int) -> (InputStream, OutputStream) { func createStreamPair(host: String, port: Int) -> (InputStream, OutputStream) {
var inputStream: InputStream? = nil, outputStream: OutputStream? = nil var inputStream: InputStream? = nil, outputStream: OutputStream? = nil
Foundation.Stream.getStreamsToHost(withName: host, port: port, inputStream: &inputStream, outputStream: &outputStream) Stream.getStreamsToHost(withName: host, port: port, inputStream: &inputStream, outputStream: &outputStream)
outputStream!.open() outputStream!.open()
inputStream!.open() inputStream!.open()
return (inputStream!, outputStream!) return (inputStream!, outputStream!)