Created
March 30, 2018 18:15
-
-
Save iamcrypticcoder/7ded8690ecd7b222f74f56fcccdf65fe to your computer and use it in GitHub Desktop.
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
class ThunderboltAdapter { | |
var connection: Connection | |
init(_ connection: Connection) { | |
self.connection = connection | |
} | |
func sendData(_ data: String) { | |
if connection is EthernetConnection { | |
let sequence = stride(from: 0, to: data.count, by: 10) | |
for i in sequence { | |
let start = data.index(data.startIndex, offsetBy: i) | |
let end = i + 10 >= data.count ? | |
data.index(data.endIndex, offsetBy: 0) : | |
data.index(data.startIndex, offsetBy: i+10) | |
connection.sendPacket(String(data[start..<end])) | |
} | |
return | |
} | |
if connection is MobileDataConnection { | |
let sequence = stride(from: 0, to: data.count, by: 5) | |
for i in sequence { | |
let start = data.index(data.startIndex, offsetBy: i) | |
let end = i + 5 >= data.count ? | |
data.index(data.endIndex, offsetBy: 0) : | |
data.index(data.startIndex, offsetBy: i+5) | |
connection.sendPacket(String(data[start..<end])) | |
} | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment