Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
6cc4535fc8 |
|
@ -15,8 +15,8 @@
|
|||
"repositoryURL": "https://github.com/apple/swift-nio.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "4fb0cc68fee45d2ae714484b5979316943ef1f24",
|
||||
"version": "1.0.0"
|
||||
"revision": "ba7970fe396e8198b84c6c1b44b38a1d4e2eb6bd",
|
||||
"version": "1.14.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ public struct Bnftp2SecondRequestComposer {
|
|||
private let localFiletime = 0 as UInt64
|
||||
|
||||
let serverToken: UInt32
|
||||
let clientToken = arc4random()
|
||||
let clientToken = UInt32.random(in: .min ... .max)
|
||||
let filename: String
|
||||
let cdkey: String
|
||||
|
||||
|
|
|
@ -2,6 +2,14 @@ import Foundation
|
|||
|
||||
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] {
|
||||
let count = self.count / MemoryLayout<UInt8>.size
|
||||
var bytesArray = [UInt8](repeating: 0, count: count)
|
||||
|
|
|
@ -17,12 +17,12 @@ public struct BncsMessage: Message, CustomDebugStringConvertible {
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public struct BncsMessage: Message, CustomDebugStringConvertible {
|
|||
// Check entire header is present -- precondition is fine here, guard is used in init
|
||||
precondition(data.count > 2)
|
||||
|
||||
let rawIdentifier: UInt8 = data.withUnsafeBytes { return $0[1] }
|
||||
let rawIdentifier = data.getByte(at: 1)
|
||||
return BncsMessageIdentifier(rawValue: rawIdentifier) ?? .None
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public struct BnlsMessage: Message, CustomDebugStringConvertible {
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public struct BnlsMessage: Message, CustomDebugStringConvertible {
|
|||
// Check entire header is present -- precondition is fine here, guard is used in init
|
||||
precondition(data.count > 3)
|
||||
|
||||
let rawIdentifier: UInt8 = data.withUnsafeBytes { return $0[2] }
|
||||
let rawIdentifier = data.getByte(at: 2)
|
||||
return BnlsMessageIdentifier(rawValue: rawIdentifier) ?? .None
|
||||
}
|
||||
|
||||
|
@ -36,5 +36,5 @@ public struct BnlsMessage: Message, CustomDebugStringConvertible {
|
|||
public var debugDescription: String {
|
||||
return "BnlsMessage (\(identifier)):\n\(data.hexDescription)"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ extension MessageConsumer {
|
|||
}
|
||||
|
||||
public mutating func readUInt8() -> UInt8 {
|
||||
let x: UInt8 = message.data.withUnsafeBytes({ return $0[readIndex] })
|
||||
let x: UInt8 = message.data.getByte(at: readIndex)
|
||||
readIndex += 1
|
||||
return x
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func loadOptionsFromCommandLine() -> [String: String] {
|
|||
|
||||
func createStreamPair(host: String, port: Int) -> (InputStream, OutputStream) {
|
||||
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()
|
||||
inputStream!.open()
|
||||
return (inputStream!, outputStream!)
|
||||
|
|
Loading…
Reference in New Issue